Replies: 8 comments
-
You should be getting custom events and page view events after consent is given. However, no events will be queued between when all analytics integration is ready and the consent is given. For example:
|
Beta Was this translation helpful? Give feedback.
-
Hello @wizardlyhel I'll quote your message in the Shopify Partners Slack Community here, just in case anyone reading this is not a member:
Following your advice here, we've changed our code to now call document.addEventListener(
'visitorConsentCollected',
() => {
ready();
console.log('GTM integration ready()');
},
{ once: true },
); Our observations are now as follows: From here, there's 3 scenarios:
So in short;
Hopefully the screen recordings are useful in helping to identify the problem.
|
Beta Was this translation helpful? Give feedback.
-
In this function, can you log the state of
Also, update to |
Beta Was this translation helpful? Give feedback.
-
Hi @wizardlyhel I have updated to the latest version and included those console logs. I have also added an explicit <Analytics.Provider
cart={cart}
shop={shop}
consent={consent}
canTrack={() => {
const canTrack = Boolean(
typeof window !== 'undefined' && window.Shopify?.customerPrivacy.analyticsProcessingAllowed(),
);
console.log('canTrack() called, returns', canTrack);
return canTrack;
}}
> Note: I have also added logs to both standard and custom events I have updated the code above to reflect the changes so far. On first visit
After clicking "Accept": On second visit (hard reload)After previously clicking "Accept": |
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
-
The Now, the value of
and the value of
|
Beta Was this translation helpful? Give feedback.
-
It should exist after you have accepted the consent without hard refresh. Something is wrong with your set up. Check your consent banner set up against what's on https://hydrogen.shop/
|
Beta Was this translation helpful? Give feedback.
-
We are simply using Shopify's built-in cookie banner. I do see some relevant network request to Query {
"query": "query { consentManagement { cookies(visitorConsent:{}) { answersCookie trackingConsentCookie cookieDomain landingPageCookie origReferrerCookie } } }",
"variables": {}
} Response {
"data": {
"consentManagement": {
"cookies": {
"answersCookie": "%7B%22purposes%22%3A%7B%22p%22%3Afalse%2C%22a%22%3Afalse%2C%22m%22%3Afalse%2C%22t%22%3Atrue%7D%2C%22display_banner%22%3Atrue%2C%22sale_of_data_region%22%3Afalse%7D",
"trackingConsentCookie": "%7B%22con%22%3A%7B%22CMP%22%3A%7B%22a%22%3A%22%22%2C%22m%22%3A%22%22%2C%22p%22%3A%22%22%2C%22s%22%3A%22%22%7D%7D%2C%22v%22%3A%222.1%22%2C%22region%22%3A%22BEVLG%22%2C%22reg%22%3A%22%22%2C%22purposes%22%3A%7B%22p%22%3Afalse%2C%22a%22%3Afalse%2C%22m%22%3Afalse%2C%22t%22%3Atrue%7D%2C%22display_banner%22%3Atrue%2C%22sale_of_data_region%22%3Afalse%7D",
"cookieDomain": "cowboy.com",
"landingPageCookie": null,
"origReferrerCookie": null
}
}
}
} and another one related to the cookie banner: Query {
"query": "\n query bannerQuery ($isPreviewMode: Boolean = false) @inContext(language: EN, country: BE) {\n consentManagement {\n banner {\n enabled\n position\n policyLinkText\n policyLinkUrl\n title\n text\n buttonPrefsOpenText\n buttonAcceptText\n buttonDeclineText\n regionVisibility @include(if: $isPreviewMode)\n theme {\n theme\n fontColor\n backgroundColor\n buttonFontColor\n buttonBackgroundColor\n }\n preferences {\n title\n introTitle\n introText\n buttonAcceptText\n buttonDeclineText\n buttonSaveText\n bulletPoints {\n enabled\n title\n firstText\n secondText\n thirdText\n }\n purposes {\n essentialName\n essentialDesc\n performanceName\n performanceDesc\n preferencesName\n preferencesDesc\n marketingName\n marketingDesc\n }\n }\n }\n }\n }",
"variables": {
"isPreviewMode": false
}
} Response {
"data": {
"consentManagement": {
"banner": {
"enabled": true,
"position": "bottom_left",
"policyLinkText": "Privacy Policy.",
"policyLinkUrl": "https://cowboy.com/policies/privacy-policy",
"title": "We value your privacy",
"text": "We use cookies and other technologies to personalize your experience, perform marketing, and collect analytics. Learn more in our ",
"buttonPrefsOpenText": "Manage preferences",
"buttonAcceptText": "Accept",
"buttonDeclineText": "Decline",
"theme": {
"theme": "custom",
"fontColor": "0,0,11,100",
"backgroundColor": "0,0,100,100",
"buttonFontColor": "0,0,11,100",
"buttonBackgroundColor": "0,0,100,100"
},
"preferences": {
"title": "Cookie preferences",
"introTitle": "You control your data",
"introText": "Learn more about the cookies we use, and choose which cookies to allow.",
"buttonAcceptText": "Accept all",
"buttonDeclineText": "Decline all",
"buttonSaveText": "Save my choices",
"bulletPoints": {
"enabled": false,
"title": "If you accept all cookies",
"firstText": "Our site may be improved based on your interests",
"secondText": "Your preferences may be stored for when you return",
"thirdText": "You may see advertising that's tailored to you"
},
"purposes": {
"essentialName": "Required",
"essentialDesc": "These cookies are necessary for the site to function properly, including capabilities like logging in and adding items to the cart.",
"performanceName": "Analytics",
"performanceDesc": "These cookies help us understand how you interact with the site. We use this data to identify areas to improve.",
"preferencesName": "Personalization",
"preferencesDesc": "These cookies store details about your actions to personalize your next visit to the website.",
"marketingName": "Marketing",
"marketingDesc": "These cookies are used to optimize marketing communications and show you ads on other sites."
}
}
}
}
},
"extensions": {
"context": {
"country": "BE",
"language": "EN"
}
}
} After accepting, that first call querying consentManagement is repeated: Query {
"query": "query { consentManagement { cookies(visitorConsent:{marketing:true,analytics:true,preferences:true},origReferrer:\"\",landingPage:\"/pages/delivery\") { answersCookie trackingConsentCookie cookieDomain landingPageCookie origReferrerCookie } } }",
"variables": {}
} Response {
"data": {
"consentManagement": {
"cookies": {
"answersCookie": "%7B%22purposes%22%3A%7B%22p%22%3Atrue%2C%22a%22%3Atrue%2C%22m%22%3Atrue%2C%22t%22%3Atrue%7D%2C%22display_banner%22%3Atrue%2C%22sale_of_data_region%22%3Afalse%7D",
"trackingConsentCookie": "%7B%22con%22%3A%7B%22CMP%22%3A%7B%22a%22%3A%221%22%2C%22m%22%3A%221%22%2C%22p%22%3A%221%22%2C%22s%22%3A%22%22%7D%7D%2C%22v%22%3A%222.1%22%2C%22region%22%3A%22BEVLG%22%2C%22reg%22%3A%22%22%2C%22purposes%22%3A%7B%22p%22%3Atrue%2C%22a%22%3Atrue%2C%22m%22%3Atrue%2C%22t%22%3Atrue%7D%2C%22display_banner%22%3Atrue%2C%22sale_of_data_region%22%3Afalse%7D",
"cookieDomain": "cowboy.com",
"landingPageCookie": "%2Fpages%2Fdelivery",
"origReferrerCookie": ""
}
}
}
} The cookies you mention are never set during first visit. It is only after hard reloading the page that they appear:
{"purposes":{"p":true,"a":true,"m":true,"t":true},"display_banner":true,"sale_of_data_region":false}
{"con":{"CMP":{"a":"1","m":"1","p":"1","s":""}},"v":"2.1","region":"BEVLG","reg":"","purposes":{"p":true,"a":true,"m":true,"t":true},"display_banner":true,"sale_of_data_region":false} |
Beta Was this translation helpful? Give feedback.
-
Context
We are attempting to set up Shopify Analytics with Google Tag Manager as a 3rd party integration (mostly hooked onto custom events). Following the Shopify docs as well as we can. We're using the default Shopify cookie banner to collect consent, using the Customer Privacy API.
Maybe not so relevant, but still worth sharing: we are also doing incremental adoption of Hydrogen.
Issue description
Steps to reproduce
Expected behavior
page_viewed
and any custom events) that are supposed to be fired before consent is collected get queued instead and fired immediately after the user clicks "accept"Actual behavior
page_viewed
and custom ones are being fired normally.Relevant code
Hydrogen version:
v2024.7.8
root.jsx
components/GoogleTagManager.jsx
Has anyone encountered a similar issue? How could we fix this?
Beta Was this translation helpful? Give feedback.
All reactions