GDPR consent check on Checkout Page

ranjitsingh
Visitor
1 0 0

Trying to make checkout page for store in UK be GDPR compliant. Intending to add tracking scripts on the checkout page via Shopify Admin >> Settings >> Checkout >> Additional scripts, but is there any way we can track the consent choice on that page, because I was trying to access "Shopify" and "Window" object from javascript console logs, but could not find anything that might help us.

 

In a nutshell, I'm trying to include the scripts only if the consent is given but cannot find an out of box functionality to track consent choice on the checkout page, like I can do on the rest of the website (https://shopify.dev/api/consent-tracking).

Replies 2 (2)

NicoRi
Excursionist
14 0 2

I know this is an old thread, but I found it on Google page 1 when searching for a solution to this, so I thought I'd share my solution. I parsed the cookie with JavaScript this way:

 

cookies = Object.fromEntries(document.cookie.split('; ').map(v=>v.split(/=(.*)/s).map(decodeURIComponent)));
consentCookie = JSON.parse(cookies._tracking_consent);
consentStatus = consentCookie.con.GDPR;
if(consentStatus == 1) {
  // call tracking functions here
}

NicoRi
Excursionist
14 0 2

It appears that the cookie has now a different structure/format since version 2.x. I tweaked my code a little, based on deciphering the cookie content and Shopify's trekkie.storefront.abababababa...js:

 

 

 

 

cookies = Object.fromEntries(document.cookie.split('; ').map(v=>v.split(/=(.*)/s).map(decodeURIComponent)));
consentCookie = JSON.parse(cookies._tracking_consent);
if (typeof consentCookie.con.GDPR != "undefined") { //this is 1 or 0 for cookie version < 2
  consentStatus = consentCookie.con.GDPR;
} else {
  consentStatus = consentCookie.con.CMP.m;
  /* with v2, the cookie saves 4 different consent settings in the "CMP" object inside the "con" object, namely "p","m","a" and "s". "m" is Marketing, which appears appropriate for GAds conversions etc. It is definitely set to 1 when your cookie banner has called the Consent API to allow all cookies/tracking. The other entities apparently are "Preferences", "Analytics" and "Sale of data". If your cookie banner calls the consent api with
window.Shopify.customerPrivacy.setTrackingConsent(true, callback);
, "p", "m" and "a" are set to 1; "s" remains empty/false, likely since there's no legal framework in the GDPR to allow a company to sell my data by merely clicking on a cookie banner. */
}
if(consentStatus == 1) {
  // tracking scripts here
}