From 2652537a5f5649171b754ba27f076161e6d6fdc4 Mon Sep 17 00:00:00 2001 From: Cole Goldsmith Date: Fri, 24 Jan 2025 17:18:24 -0600 Subject: [PATCH] add gtag script and use staging www site footer link --- src/js/10-ketch-consent.js | 21 +++++++++++++++++++++ src/partials/footer.hbs | 3 ++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/js/10-ketch-consent.js b/src/js/10-ketch-consent.js index 2ad3a4f..30078c2 100644 --- a/src/js/10-ketch-consent.js +++ b/src/js/10-ketch-consent.js @@ -3,6 +3,7 @@ window.analytics.ready(() => { window.ketch('once', 'consent', onKetchConsent) + window.ketch('on', 'consent', onKetchConsentGtagTrack) window.ketch('on', 'userConsentUpdated', onKetchConsentUpdated) }) @@ -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 }) => { diff --git a/src/partials/footer.hbs b/src/partials/footer.hbs index 6bff0c0..559b768 100644 --- a/src/partials/footer.hbs +++ b/src/partials/footer.hbs @@ -29,7 +29,8 @@ | Manage Privacy Choices