From f84b9a12ff5fc69f79f485c9489803a32cea8d47 Mon Sep 17 00:00:00 2001
From: Ronnie Miller
Date: Wed, 1 Oct 2025 14:45:58 -0700
Subject: [PATCH 1/4] Implement Segment TrustArc wrapper and add listeners for
consent
---
src/js/04-segment-analytics.js | 80 +++++++++++++++++++++++--
src/js/10-trustarc-consent.js | 23 --------
src/partials/footer.hbs | 7 ++-
src/partials/head-scripts.hbs | 105 ++++++++++++++++++++++++++++++++-
src/partials/intercom.hbs | 38 +++++++++---
5 files changed, 212 insertions(+), 41 deletions(-)
delete mode 100644 src/js/10-trustarc-consent.js
diff --git a/src/js/04-segment-analytics.js b/src/js/04-segment-analytics.js
index fffa0e30..2822bd38 100644
--- a/src/js/04-segment-analytics.js
+++ b/src/js/04-segment-analytics.js
@@ -1,20 +1,83 @@
;(function () {
'use strict'
+ // Get common properties from digitalData
+ const getCommonProperties = () => {
+ return window.digitalData?.page?.pageInfo?.segment?.commonProperties || {}
+ }
+
+ /**
+ * Track events with IBM Segment Common Schema
+ * @param {string} name - Event name (e.g., "CTA Clicked", "UI Interaction")
+ * @param {object} payload - Event properties
+ */
const trackEvent = (name, payload) => {
if (window.analytics) {
- window.analytics.track(name, payload || {})
+ // Merge common properties with event-specific properties
+ const eventProperties = {
+ ...getCommonProperties(),
+ ...(payload || {})
+ }
+ window.analytics.track(name, eventProperties)
}
}
+ /**
+ * Track link clicks with IBM Segment Common Schema
+ * @param {HTMLElement} element - The link element
+ * @param {string} name - Event name
+ * @param {object} payload - Event properties
+ */
const trackLinkEvent = (element, name, payload) => {
if (window.analytics) {
- window.analytics.trackLink(element, name, payload || {})
+ const eventProperties = {
+ ...getCommonProperties(),
+ ...(payload || {})
+ }
+ window.analytics.trackLink(element, name, eventProperties)
}
}
- // Add click event listeners to all elements with a data-track attribute.
- if (window.analytics) {
+ /**
+ * Initialize data-attribute tracking for declarative analytics
+ * Supports both legacy data-track and new IBM schema patterns
+ */
+ const initDataAttributeTracking = () => {
+ // Handle data-event attributes (IBM Schema pattern)
+ const handleClick = (event) => {
+ const target = event.target
+ const trackingElement = target.closest('[data-event]')
+
+ if (!trackingElement) return
+
+ const eventName = trackingElement.dataset.event
+ if (!eventName) return
+
+ const properties = {}
+
+ // Extract all data attributes and map to event properties
+ Object.keys(trackingElement.dataset).forEach((key) => {
+ if (key !== 'event') {
+ // Map to IBM Segment property names (preserve exact casing per schema)
+ let propertyKey = key
+
+ // Handle special IBM property mappings
+ if (key === 'cta') propertyKey = 'CTA'
+ else if (key === 'elementId') propertyKey = 'elementId'
+ else if (key === 'topLevel') propertyKey = 'topLevel'
+ else if (key === 'subLevel') propertyKey = 'subLevel'
+
+ properties[propertyKey] = trackingElement.dataset[key]
+ }
+ })
+
+ trackEvent(eventName, properties)
+ }
+
+ document.removeEventListener('click', handleClick)
+ document.addEventListener('click', handleClick)
+
+ // Legacy data-track support for backwards compatibility
const trackedLinkElements = document.querySelectorAll('a[data-track]')
const trackedElements = document.querySelectorAll('[data-track]:not(a)')
@@ -29,7 +92,14 @@
})
}
- // Expose trackEvent and trackLinkEvent to the global scope.
+ // Initialize tracking when DOM is ready
+ if (document.readyState === 'loading') {
+ document.addEventListener('DOMContentLoaded', initDataAttributeTracking)
+ } else {
+ initDataAttributeTracking()
+ }
+
+ // Expose functions to the global scope
window.trackEvent = trackEvent
window.trackLinkEvent = trackLinkEvent
})()
diff --git a/src/js/10-trustarc-consent.js b/src/js/10-trustarc-consent.js
deleted file mode 100644
index ff996fe9..00000000
--- a/src/js/10-trustarc-consent.js
+++ /dev/null
@@ -1,23 +0,0 @@
-/* eslint-disable */
-window._ibmAnalytics = {
- "settings": {
- "name": "DataStax",
- "tealiumProfileName": "ibm-subsidiary",
- },
- "trustarc": {
- "privacyPolicyLink": "https://www.datastax.com/legal/datastax-website-privacy-policy"
- },
- "digitalData.page.services.google.enabled": true
-};
-window.digitalData = {
- "page": {
- "pageInfo": {
- "ibm": {
- "siteId": "IBM_" + _ibmAnalytics.settings.name,
- }
- },
- "category": {
- "primaryCategory": "PC230"
- }
- }
-};
diff --git a/src/partials/footer.hbs b/src/partials/footer.hbs
index c2e0a2d7..b30a4322 100644
--- a/src/partials/footer.hbs
+++ b/src/partials/footer.hbs
@@ -24,12 +24,13 @@
target="_blank"
data-track="Footer Terms of Use Link Clicked"
>Terms of use
- {{#with site.keys.ketchSmartTagUrl}}
+ {{#with site.keys.ibmAnalyticsEnabled}}
|
Manage Privacy Choices
@@ -93,4 +94,4 @@
>info@datastax.com
-
\ No newline at end of file
+
diff --git a/src/partials/head-scripts.hbs b/src/partials/head-scripts.hbs
index bea0d1b5..948ef98d 100644
--- a/src/partials/head-scripts.hbs
+++ b/src/partials/head-scripts.hbs
@@ -1,12 +1,111 @@
{{#with site.keys.segment}}
+
+
{{/with}}
{{#with site.keys.ibmAnalyticsEnabled}}
+
{{/with}}
diff --git a/src/partials/intercom.hbs b/src/partials/intercom.hbs
index 16bbb428..6368e53d 100644
--- a/src/partials/intercom.hbs
+++ b/src/partials/intercom.hbs
@@ -1,11 +1,35 @@
{{#with site.keys.intercom}}
-
{{/with}}
From 79982bd5ea0fedcb0dd481f853d82c4f6439fe0e Mon Sep 17 00:00:00 2001
From: Ronnie Miller
Date: Wed, 1 Oct 2025 14:51:55 -0700
Subject: [PATCH 2/4] Fix lint error
---
src/js/04-segment-analytics.js | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/js/04-segment-analytics.js b/src/js/04-segment-analytics.js
index 2822bd38..db0bd193 100644
--- a/src/js/04-segment-analytics.js
+++ b/src/js/04-segment-analytics.js
@@ -16,7 +16,7 @@
// Merge common properties with event-specific properties
const eventProperties = {
...getCommonProperties(),
- ...(payload || {})
+ ...(payload || {}),
}
window.analytics.track(name, eventProperties)
}
@@ -32,7 +32,7 @@
if (window.analytics) {
const eventProperties = {
...getCommonProperties(),
- ...(payload || {})
+ ...(payload || {}),
}
window.analytics.trackLink(element, name, eventProperties)
}
From 6aa9c3a1fc7e65a4037d777c381c6e84eaf8b6bd Mon Sep 17 00:00:00 2001
From: Ronnie Miller
Date: Wed, 1 Oct 2025 15:56:26 -0700
Subject: [PATCH 3/4] Fix segment key not loading for IBM script
---
src/partials/head-scripts.hbs | 49 +++++++++++++++++++++--------------
1 file changed, 30 insertions(+), 19 deletions(-)
diff --git a/src/partials/head-scripts.hbs b/src/partials/head-scripts.hbs
index 948ef98d..c828c4b2 100644
--- a/src/partials/head-scripts.hbs
+++ b/src/partials/head-scripts.hbs
@@ -1,22 +1,3 @@
-{{#with site.keys.segment}}
-
-
-
-{{/with}}
-
{{#with site.keys.ibmAnalyticsEnabled}}
+{{#with ../site.keys.segment}}
+
+
+{{/with}}
{{/with}}
From 0d063a8602827415cb7cc42edaf8677512ef1c06 Mon Sep 17 00:00:00 2001
From: Ronnie Miller
Date: Wed, 1 Oct 2025 16:27:13 -0700
Subject: [PATCH 4/4] Try again with Segment script
---
src/partials/head-scripts.hbs | 30 ++++++++++++------------------
1 file changed, 12 insertions(+), 18 deletions(-)
diff --git a/src/partials/head-scripts.hbs b/src/partials/head-scripts.hbs
index c828c4b2..d9935e2b 100644
--- a/src/partials/head-scripts.hbs
+++ b/src/partials/head-scripts.hbs
@@ -1,3 +1,9 @@
+{{#with site.keys.segment}}
+
+{{/with}}
+
{{#with site.keys.ibmAnalyticsEnabled}}
{{/with}}