Skip to content

Commit

Permalink
add gtag script and use staging www site footer link
Browse files Browse the repository at this point in the history
  • Loading branch information
colegoldsmith committed Jan 24, 2025
1 parent 0663bb2 commit 2652537
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
21 changes: 21 additions & 0 deletions src/js/10-ketch-consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

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

Expand Down Expand Up @@ -40,6 +41,26 @@
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 }) => {
Expand Down
3 changes: 2 additions & 1 deletion src/partials/footer.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
|
<a
id="preferenceCenterLink"
href="https://www.datastax.com/preferences"
{{!-- href="https://www.datastax.com/preferences" --}}
href="https://marketing-git-feature-ketch-datastax-marketing.vercel.app/preferences"
data-track="Footer Consent Preference Link Clicked"
>Manage Privacy Choices</a>
</span>
Expand Down

0 comments on commit 2652537

Please sign in to comment.