Skip to content

Commit 84b9b5c

Browse files
authored
Revert "Switch from Ketch to IBM TrustArc for cookie consent (#196)" (#199)
This reverts commit 0fe09ac.
1 parent 0fe09ac commit 84b9b5c

File tree

3 files changed

+88
-25
lines changed

3 files changed

+88
-25
lines changed

src/js/10-ketch-consent.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
;(function () {
2+
'use strict'
3+
4+
window.analytics.ready(() => {
5+
window.ketch('once', 'consent', onKetchConsent)
6+
window.ketch('on', 'consent', onKetchConsentGtagTrack)
7+
window.ketch('on', 'userConsentUpdated', onKetchConsentUpdated)
8+
})
9+
10+
// If the user is in the US-CA region, change the text of the preference center link
11+
// 3/19/25: Disabled this feature due to shifting CA legal requirements. Will re-enable with new textContent if needed
12+
// window.ketch('on', 'regionInfo', (regionInfo) => {
13+
// const customTextRegions = ['US-CA']
14+
// if (customTextRegions.includes(regionInfo)) {
15+
// const preferenceCenterLinkElement = document.getElementById('preferenceCenterLink')
16+
// if (preferenceCenterLinkElement) {
17+
// preferenceCenterLinkElement.textContent = 'Do Not Sell My Personal Information'
18+
// }
19+
// }
20+
// })
21+
22+
// If the user is in the default jurisdiction, remove the preference center link
23+
window.ketch('on', 'jurisdiction', (jurisdiction) => {
24+
if (jurisdiction.includes('default')) {
25+
const preferenceCenterContainerElement = document.getElementById('preferenceCenterContainer')
26+
if (preferenceCenterContainerElement) {
27+
preferenceCenterContainerElement.remove()
28+
}
29+
}
30+
})
31+
32+
// Once - This will be fired only one time, will initialize all the main features.
33+
const onKetchConsent = (consent) => {
34+
window.ketchConsent = consent
35+
addKetchConsentToContextMiddleware()
36+
window.analytics.page()
37+
// loadScripts(); // Load any script if we have scripts to fire after ketch consent is fired.
38+
}
39+
40+
// on - Each time the user changes the preferences, save them to the global variable
41+
const onKetchConsentUpdated = (consent) => {
42+
window.ketchConsent = consent
43+
}
44+
45+
// On - each time the consent is loaded, track it to the gtag event
46+
const onKetchConsentGtagTrack = (consent) => {
47+
if (window.gtag &&
48+
consent.purposes &&
49+
'analytics' in consent.purposes &&
50+
'targeted_advertising' in consent.purposes
51+
) {
52+
const analyticsString = consent.purposes.analytics === true ? 'granted' : 'denied'
53+
const targetedAdsString = consent.purposes.targeted_advertising === true ? 'granted' : 'denied'
54+
55+
const gtagObject = {
56+
analytics_storage: analyticsString,
57+
ad_personalization: targetedAdsString,
58+
ad_storage: targetedAdsString,
59+
ad_user_data: targetedAdsString,
60+
}
61+
window.gtag('consent', 'update', gtagObject)
62+
}
63+
}
64+
65+
// Use the analytics.addSourceMiddleware function to include the consent on all the events
66+
const addKetchConsentToContextMiddleware = () => {
67+
window.analytics.addSourceMiddleware(({ payload, next }) => {
68+
if (window.ketchConsent) {
69+
const analyticsString = window.ketchConsent.purposes.analytics === true ? 'granted' : 'denied'
70+
const targetedAdsString = window.ketchConsent.purposes.targeted_advertising === true ? 'granted' : 'denied'
71+
72+
payload.obj.properties = {
73+
...(payload.obj.properties || {}),
74+
analyticsStorageConsentState: analyticsString,
75+
adsStorageConsentState: targetedAdsString,
76+
adUserDataConsentState: targetedAdsString,
77+
adPersonalizationConsentState: targetedAdsString,
78+
}
79+
payload.obj.context.consent = {
80+
categoryPreferences: window.ketchConsent?.purposes,
81+
}
82+
}
83+
next(payload)
84+
})
85+
}
86+
})()

src/js/10-trustarc-consent.js

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

src/partials/head-scripts.hbs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ analytics.load("{{this}}");
66
</script>
77
{{/with}}
88

9-
{{#with site.keys.ibmAnalyticsEnabled}}
10-
<script src="//1.www.s81c.com/common/stats/ibm-common.js" type="text/javascript" async="async"></script>
9+
{{#with site.keys.ketchSmartTagUrl}}
10+
<script>!function(){window.semaphore=window.semaphore||[],window.ketch=function(){window.semaphore.push(arguments)};var e=document.createElement("script");e.type="text/javascript",e.src="{{this}}",e.defer=e.async=!0,document.getElementsByTagName("head")[0].appendChild(e)}();</script>
1111
{{/with}}
1212

1313
<script>var uiRootPath = '{{{uiRootPath}}}'</script>

0 commit comments

Comments
 (0)