Skip to content

Commit 70f7cb8

Browse files
committed
Replace Ketch with IBM TrustArc consent management
1 parent f8ce864 commit 70f7cb8

File tree

6 files changed

+300
-114
lines changed

6 files changed

+300
-114
lines changed

src/js/04-segment-analytics.js

Lines changed: 146 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,108 @@
11
;(function () {
22
'use strict'
33

4-
const trackEvent = (name, payload) => {
5-
if (window.analytics) {
6-
window.analytics.track(name, payload || {})
4+
/**
5+
* IBM Segment Event Types:
6+
* - 'CTA Clicked': Call-to-action clicks (links, buttons)
7+
* - 'UI Interaction': General UI interactions (excludes userId)
8+
* - 'User Form': Form interactions (handled separately in form-specific files)
9+
*/
10+
11+
// Determine if a data-track event should be CTA Clicked or UI Interaction
12+
const getEventType = (eventName) => {
13+
// Links are typically CTAs
14+
if (eventName.includes('Link Clicked') || eventName.includes('Clicked')) {
15+
return 'CTA Clicked'
16+
}
17+
// Buttons and other interactions
18+
if (eventName.includes('Button') || eventName.includes('Form')) {
19+
return 'UI Interaction'
20+
}
21+
// Default to UI Interaction
22+
return 'UI Interaction'
23+
}
24+
25+
// Extract CTA text from event name or element
26+
const extractCTA = (eventName, element) => {
27+
if (element) {
28+
return element.textContent?.trim() || element.getAttribute('title') || eventName
29+
}
30+
return eventName
31+
}
32+
33+
// Extract namespace from event name
34+
const extractNamespace = (eventName) => {
35+
if (eventName.includes('Footer')) return 'footer'
36+
if (eventName.includes('Tutorial')) return 'tutorial'
37+
if (eventName.includes('Feedback')) return 'feedback'
38+
if (eventName.includes('Edit')) return 'content'
39+
if (eventName.includes('Colab')) return 'tutorial'
40+
return 'docs'
41+
}
42+
43+
// Extract action from event name
44+
const extractAction = (eventName) => {
45+
if (eventName.includes('Clicked')) return 'clicked'
46+
if (eventName.includes('Submitted')) return 'submitted'
47+
if (eventName.includes('Copied')) return 'copied'
48+
return 'interacted'
49+
}
50+
51+
const trackEvent = (name, payload = {}, element = null) => {
52+
if (window.analytics && window.getSegmentCommonProperties) {
53+
const eventType = getEventType(name)
54+
const commonProps = window.getSegmentCommonProperties(eventType)
55+
56+
let eventPayload = { ...commonProps, ...payload }
57+
58+
if (eventType === 'CTA Clicked') {
59+
eventPayload = {
60+
...eventPayload,
61+
CTA: extractCTA(name, element),
62+
location: extractNamespace(name),
63+
}
64+
} else if (eventType === 'UI Interaction') {
65+
eventPayload = {
66+
...eventPayload,
67+
action: extractAction(name),
68+
CTA: extractCTA(name, element),
69+
namespace: extractNamespace(name),
70+
elementId: element?.id || '',
71+
payload: payload,
72+
}
73+
}
74+
75+
// IBM requires identify() call before track events
76+
if (window.SEGMENT_COMMON_PROPERTIES?.userId) {
77+
const identifyTraits = window.getSegmentIdentifyTraits()
78+
window.analytics.identify(window.SEGMENT_COMMON_PROPERTIES.userId, identifyTraits)
79+
}
80+
81+
window.analytics.track(eventType, eventPayload)
782
}
883
}
984

10-
const trackLinkEvent = (element, name, payload) => {
11-
if (window.analytics) {
12-
window.analytics.trackLink(element, name, payload || {})
85+
const trackLinkEvent = (element, name, payload = {}) => {
86+
if (window.analytics && window.getSegmentCommonProperties) {
87+
const eventType = 'CTA Clicked' // Links are always CTAs
88+
const commonProps = window.getSegmentCommonProperties(eventType)
89+
90+
const eventPayload = {
91+
...commonProps,
92+
...payload,
93+
CTA: extractCTA(name, element),
94+
location: extractNamespace(name),
95+
type: 'Link',
96+
text: element.textContent?.trim() || element.getAttribute('title') || '',
97+
}
98+
99+
// IBM requires identify() call before track events
100+
if (window.SEGMENT_COMMON_PROPERTIES?.userId) {
101+
const identifyTraits = window.getSegmentIdentifyTraits()
102+
window.analytics.identify(window.SEGMENT_COMMON_PROPERTIES.userId, identifyTraits)
103+
}
104+
105+
window.analytics.trackLink(element, eventType, eventPayload)
13106
}
14107
}
15108

@@ -24,12 +117,57 @@
24117

25118
trackedElements.forEach((element) => {
26119
element.addEventListener('click', (e) => {
27-
trackEvent(element.dataset.track)
120+
trackEvent(element.dataset.track, {}, element)
28121
})
29122
})
30123
}
31124

32-
// Expose trackEvent and trackLinkEvent to the global scope.
125+
/**
126+
* Track page view with friendly name
127+
* IBM requires page events to have a friendly "page" property
128+
*/
129+
const trackPage = (pageName) => {
130+
if (window.analytics && window.SEGMENT_COMMON_PROPERTIES) {
131+
// IBM requires identify() call before page events
132+
const identifyTraits = window.getSegmentIdentifyTraits()
133+
window.analytics.identify(window.SEGMENT_COMMON_PROPERTIES.userId, identifyTraits)
134+
135+
// Get friendly page name from title or use provided name
136+
const friendlyName = pageName || document.title.split('|')[0].trim()
137+
138+
// Get common properties for page event (excludes userId per IBM requirements)
139+
const pageProperties = window.getSegmentCommonProperties('page')
140+
141+
window.analytics.page(friendlyName, {
142+
...pageProperties,
143+
path: window.location.pathname,
144+
url: window.location.href,
145+
title: document.title,
146+
})
147+
}
148+
}
149+
150+
// Wait for analytics to load, then track page view on initial load
151+
const waitForAnalytics = (callback, maxAttempts = 50, interval = 100) => {
152+
let attempts = 0
153+
const checkAnalytics = () => {
154+
attempts++
155+
if (window.analytics && window.analytics.initialized) {
156+
callback()
157+
} else if (attempts < maxAttempts) {
158+
setTimeout(checkAnalytics, interval)
159+
}
160+
}
161+
checkAnalytics()
162+
}
163+
164+
// Track page view on initial load once analytics is ready
165+
waitForAnalytics(() => {
166+
trackPage()
167+
})
168+
169+
// Expose trackEvent, trackLinkEvent, and trackPage to the global scope.
33170
window.trackEvent = trackEvent
34171
window.trackLinkEvent = trackLinkEvent
172+
window.trackPage = trackPage
35173
})()

src/js/05-feedback-dialog.js

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,25 @@
4040
form.onsubmit = (e) => {
4141
e.preventDefault()
4242
const message = form.elements.message.value
43-
if (message && window.trackEvent) {
44-
window.trackEvent('Feedback Form', {
45-
message,
43+
if (message && window.analytics && window.getSegmentCommonProperties) {
44+
const commonProps = window.getSegmentCommonProperties('User Form')
45+
46+
// IBM requires identify() call before track events
47+
if (window.SEGMENT_COMMON_PROPERTIES?.userId) {
48+
const identifyTraits = window.getSegmentIdentifyTraits()
49+
window.analytics.identify(window.SEGMENT_COMMON_PROPERTIES.userId, identifyTraits)
50+
}
51+
52+
// Map to IBM User Form schema
53+
window.analytics.track('User Form', {
54+
...commonProps,
55+
action: 'submitted',
56+
formId: 'feedback_form',
57+
formType: 'feedback',
58+
field: 'feedback_message',
59+
fieldType: 'text_field',
60+
title: 'Give Feedback',
61+
data: message,
4662
})
4763
}
4864
form.elements.message.value = ''
@@ -52,6 +68,26 @@
5268

5369
const feedbackButtonYes = document.getElementById('feedback_button_yes')
5470
feedbackButtonYes.addEventListener('click', (e) => {
71+
if (window.analytics && window.getSegmentCommonProperties) {
72+
const commonProps = window.getSegmentCommonProperties('User Form')
73+
74+
// IBM requires identify() call before track events
75+
if (window.SEGMENT_COMMON_PROPERTIES?.userId) {
76+
const identifyTraits = window.getSegmentIdentifyTraits()
77+
window.analytics.identify(window.SEGMENT_COMMON_PROPERTIES.userId, identifyTraits)
78+
}
79+
80+
// Track positive feedback button click
81+
window.analytics.track('User Form', {
82+
...commonProps,
83+
action: 'clicked',
84+
formId: 'feedback_buttons',
85+
formType: 'feedback',
86+
field: 'helpful_yes',
87+
fieldType: 'button',
88+
title: 'Was This Helpful?',
89+
})
90+
}
5591
showThankYou()
5692
})
5793

src/js/06-copy-to-clipboard.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,28 @@
9292
}
9393

9494
function trackCopy (language, title, text) {
95-
if (window.trackEvent) {
95+
if (window.analytics && window.getSegmentCommonProperties) {
9696
var sample = text.slice(0, 50).replace(/\s+/g, ' ').trim()
97-
window.trackEvent('Code Snippet Copied', {
98-
snippetLanguage: language,
99-
snippetTitle: title,
100-
snippetSample: sample,
97+
var commonProps = window.getSegmentCommonProperties('UI Interaction')
98+
99+
// IBM requires identify() call before track events
100+
if (window.SEGMENT_COMMON_PROPERTIES?.userId) {
101+
var identifyTraits = window.getSegmentIdentifyTraits()
102+
window.analytics.identify(window.SEGMENT_COMMON_PROPERTIES.userId, identifyTraits)
103+
}
104+
105+
// Map to IBM UI Interaction schema
106+
window.analytics.track('UI Interaction', {
107+
...commonProps,
108+
action: 'copied',
109+
CTA: 'Copy Code',
110+
namespace: 'code-snippet',
111+
elementId: 'copy-button',
112+
payload: {
113+
language: language,
114+
title: title,
115+
sample: sample,
116+
},
101117
})
102118
}
103119
}

src/js/09-ketch-consent.js

Lines changed: 0 additions & 86 deletions
This file was deleted.

src/partials/footer.hbs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,15 @@
2424
target="_blank"
2525
data-track="Footer Terms of Use Link Clicked"
2626
>Terms of use</a>
27-
{{#with site.keys.ketchSmartTagUrl}}
27+
{{#with site.keys.ibmSegment}}
2828
<span id="preferenceCenterContainer">
29-
|
29+
·&nbsp;
3030
<a
3131
id="preferenceCenterLink"
32-
href="https://www.datastax.com/preferences?redirect_to={{{../site.url}}}{{{../page.url}}}"
32+
href="#"
33+
onclick="if(typeof window !== 'undefined' && window.truste && window.truste.eu && window.truste.eu.clickListener) { window.truste.eu.clickListener(); } return false;"
3334
data-track="Footer Consent Preference Link Clicked"
35+
style="cursor: pointer;"
3436
>Manage Privacy Choices</a>
3537
</span>
3638
{{/with}}
@@ -93,4 +95,4 @@
9395
9496
</p>
9597
</div>
96-
</footer>
98+
</footer>

0 commit comments

Comments
 (0)