Here’s my compiled email I’ve sent to Shopify’s Support attempting to deal with this. Currently they’re saying there’s no issue, but we know there is. Hopefully this will help others in describing this issue, if I can’t get Shopify to resolve this myself.
I know why this is happening, and it is an issue Shopify needs to resolve. I will describe it as best I can. If you do not understand CSR headers, please forward this request to someone who does.
Why is Google Analytics GA4 code is not firing on Shopify’s Checkout Pages
As mentioned in my emails and in the community thread: Shopify’s checkout process aka URLs (/checkouts/c/*) do not include the proper CSR HTTP Headers.
CSR HTTP Headers are served via Shopify’s servers (thus this issue needs to be fixed there) and actually has nothing to do with Google’s javascript implementation of GA4.
IF Google’s GA4 javascript URLs are not explicitly added to Shopify’s CSR HTTP Headers on the checkout pages, THEN when Google GA4 javascript is BLOCKED.
Here’s the error of Google’s GA4 Javascript being blocked due to Shopify’s incorrectly configured CSR HTTP Headers:
**Refused to connect to 'https://analytics.google.com**/g/collect?v=2&tid=G-XXXXX>m=XXXXXXX&_p=2105325346&cid=2111485033.1666174160&ul=en-us&sr=2560x1440&uaa=x86&uab=64&uafvl=Chromium%3B111.0.5563.64%7CNot(A%253ABrand%3B8.0.0.0&uamb=0&uam=&uap=Linux&uapv=5.19.0&uaw=0&_eu=AEA&_s=2&sid=1679458096&sct=20&seg=1&dl=https%3A%2F%2Fwww.MYWEBSITE.com%2Fcheckouts%2Fc%xxxxxxxx%2Finformation%3F_ga%3D2.201687447.702385085.1679309372-2111485033.1666174160%26preview_theme_id%3D132554490042&dr=https%3A%2F%2Fwww.MYWEBSITE.com%2F%3F_ab%3D0%26_fd%3D0%26_sc%3D1&dt=Information%20-%20XXXX%20XXX%20-%20Checkout&en=scroll&epn.percent_scrolled=90' because it violates the following Content Security Policy directive: "connect-src 'self' *.shopifycs.com c1-stats.shopifysvc.com/performance c1-stats.shopifysvc.com/custom-metrics monorail-edge.shopifysvc.com monorail-edge-staging.shopifycloud.com ct.pinterest.com analytics.tiktok.com stats.g.doubleclick.net c1-stats.shopifysvc.com www.google-analytics.com www.facebook.com www.instagram.com *.snapchat.com atlas.shopifysvc.com atlas.shopifycloud.com MYWEBSITE.myshopify.com www.MYWEBSITE.com MYWEBSITE.com MYWEBSITE.account.myshopify.com account.MYWEBSITE.com shop.app shopify-chat.shopifycloud.com shopify-chat.shopifyapps.com *.pusher.com *.bugsnag.com experiments.shopify.com hcaptcha.com *.hcaptcha.com www.sandbox.paypal.com www.paypal.com".
The main part of this to look at is:
Refused to connect to 'https://analytics.google.com … because it violates the following Content Security Policy directive: "connect-src
The domains Shopify includes in CSR HTTP Headers are listed below:
Because analytics.google.com is NOT in that list of CSR HTTP Headers, it’s being BLOCKED by the browsers. And thus, these events will not work on browsers which enforce CSR Headers.
You’ll notice in this list that analytics.google.com is NOT in that list.
To resolve this issue Shopify will need to follow the documentation provided by Google and implement the appropriate CSR Headers at Checkout:
https://developers.google.com/tag-platform/tag-manager/web/csp#google_analytics_4_google_analytics
Google Analytics 4 (Google Analytics)
To use the Google Analytics 4 (Google Analytics) tag, the CSP must include the following directives:
script-src: https://*.googletagmanager.com
img-src: https://*.google-analytics.com https://*.googletagmanager.com
connect-src: https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com
For Google Analytics 4 (Google Analytics) deployments using Google Signals, the CSP must include the following directives:
script-src: https://*.googletagmanager.com
img-src: https://*.google-analytics.com https://*.analytics.google.com https://*.googletagmanager.com
https://*.g.doubleclick.net https://*.google.com https://*.google.<TLD>
connect-src: https://*.google-analytics.com https://*.analytics.google.com
https://*.googletagmanager.com https://*.g.doubleclick.net https://*.google.com https://*.google.<TLD>
^ Documentation about what domains are required in CSR Headers on Shopify’s end so that GA4 code can be run on checkout pages in Shopify.
To CONFIRM this is an error on Shopify’s end, ask someone who knows at Shopify for a list of CSR headers included on Checkout Pages.
Then see if *.analytics.google.com is in that list. I bet it’s not.