Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions src/js/10-ketch-consent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
;(function () {
'use strict'

window.analytics.ready(() => {
window.ketch('once', 'consent', onKetchConsent)
window.ketch('on', 'consent', onKetchConsentGtagTrack)
window.ketch('on', 'userConsentUpdated', onKetchConsentUpdated)
})

// If the user is in the US-CA region, change the text of the preference center link
// 3/19/25: Disabled this feature due to shifting CA legal requirements. Will re-enable with new textContent if needed
// window.ketch('on', 'regionInfo', (regionInfo) => {
// const customTextRegions = ['US-CA']
// if (customTextRegions.includes(regionInfo)) {
// const preferenceCenterLinkElement = document.getElementById('preferenceCenterLink')
// if (preferenceCenterLinkElement) {
// preferenceCenterLinkElement.textContent = 'Do Not Sell My Personal Information'
// }
// }
// })

// If the user is in the default jurisdiction, remove the preference center link
window.ketch('on', 'jurisdiction', (jurisdiction) => {
if (jurisdiction.includes('default')) {
const preferenceCenterContainerElement = document.getElementById('preferenceCenterContainer')
if (preferenceCenterContainerElement) {
preferenceCenterContainerElement.remove()
}
}
})

// Once - This will be fired only one time, will initialize all the main features.
const onKetchConsent = (consent) => {
window.ketchConsent = consent
addKetchConsentToContextMiddleware()
window.analytics.page()
// loadScripts(); // Load any script if we have scripts to fire after ketch consent is fired.
}

// on - Each time the user changes the preferences, save them to the global variable
const onKetchConsentUpdated = (consent) => {
window.ketchConsent = consent
}

// On - each time the consent is loaded, track it to the gtag event
const onKetchConsentGtagTrack = (consent) => {
if (window.gtag &&
consent.purposes &&
'analytics' in consent.purposes &&
'targeted_advertising' in consent.purposes
) {
const analyticsString = consent.purposes.analytics === true ? 'granted' : 'denied'
const targetedAdsString = consent.purposes.targeted_advertising === true ? 'granted' : 'denied'

const gtagObject = {
analytics_storage: analyticsString,
ad_personalization: targetedAdsString,
ad_storage: targetedAdsString,
ad_user_data: targetedAdsString,
}
window.gtag('consent', 'update', gtagObject)
}
}

// Use the analytics.addSourceMiddleware function to include the consent on all the events
const addKetchConsentToContextMiddleware = () => {
window.analytics.addSourceMiddleware(({ payload, next }) => {
if (window.ketchConsent) {
const analyticsString = window.ketchConsent.purposes.analytics === true ? 'granted' : 'denied'
const targetedAdsString = window.ketchConsent.purposes.targeted_advertising === true ? 'granted' : 'denied'

payload.obj.properties = {
...(payload.obj.properties || {}),
analyticsStorageConsentState: analyticsString,
adsStorageConsentState: targetedAdsString,
adUserDataConsentState: targetedAdsString,
adPersonalizationConsentState: targetedAdsString,
}
payload.obj.context.consent = {
categoryPreferences: window.ketchConsent?.purposes,
}
}
next(payload)
})
}
})()
23 changes: 0 additions & 23 deletions src/js/10-trustarc-consent.js

This file was deleted.

4 changes: 2 additions & 2 deletions src/partials/head-scripts.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ analytics.load("{{this}}");
</script>
{{/with}}

{{#with site.keys.ibmAnalyticsEnabled}}
<script src="//1.www.s81c.com/common/stats/ibm-common.js" type="text/javascript" async="async"></script>
{{#with site.keys.ketchSmartTagUrl}}
<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>
{{/with}}

<script>var uiRootPath = '{{{uiRootPath}}}'</script>
Expand Down
Loading