Where should I insert my Google Analytics 4 tag in my code?

Hey,

I am aware that I need to put my Google tag into my code for my shop, however I have no idea where it should go. What I am missing?

Any help I would be grateful appreciate

Hey, @D_Dog_21 .

Thank you for reaching out and posting this question!

If you’re looking to set up Google Analytics for your Shopify store, then we’ve got a step-by-step guide that can assist you with that here: Setting up Google Analytics 4. Once you’ve created your Google Analytics account and Google Analytics 4 property, you can add it to the preferences of your online store (‘Online store > Preferences > Google Analytics > Manage pixel here’).

![11-58-ia2o1-xqiqw|2854x1663](upload://6ypgflYVhBC8pCbrCqQs9jyagvo.jpeg)

I noticed that you’re a new member of our Shopify Community! Once you’ve added your Google Analytics tag, I’d love to hear more about your business and share some resources to help you get started. What kinds of products are you selling? Do you have a marketing plan prepare for your store?

@Elias is there a way we can get some Shopify Developers to look into the issue of Google Analytics 4 being blocked on /checkout pages due to incorrectly configured Content Security Policy (CSP) Headers.

Shopify hasn’t added appropriate CSP Headers to the checkout pages and it’s blocking Google Analytics 4 tracking. Specifically begin_checkout and add_payment_info events.

Here’s Google’s documentation on appropriate CSP Headers

https://developers.google.com/tag-platform/tag-manager/web/csp#google_analytics_4_google_analytics

Hey, This hasn’t solved my my issue. Google Analytics is now telling me I haven’t put it on right page. I have try for the home page but can’t find it.

Hey, @Barnett4321 .

Thank you for bringing this to our attention.

It looks like there is a known issue that may have affected some merchants migrating from Universal Analytics to Google Analytics 4. Specifically where the purchase events, such as begin_checkout and add_payment, aren’t being reported in their Google analytics account. If you are experiencing this issue, then we will need to access your account and perform some troubleshooting in order to resolve this issue. While we’re unable to provide account-specific support via the Shopify Community, we’d be happy to continue assisting you through live chat or emails. Please visit the Shopify Help Center and login to your account to create a support request.

If you have any other questions on this topic, then don’t hesitate to let me know!

Hey, @D_Dog_21 .

Thank you for following up!

It sounds like you might be following a different method for installing Google Analytics, which may or may not be supported for our platform. However, if you need some account-specific support with installing Google Analytics onto your store, then we’d be happy to further assist you through live chat or emails. Simply visit the Shopify Help Center and login to your account to create a support request.

If you have any other questions, then don’t hesitate to let me know!

This issue finally got resolved around April 11th-13th, 2023. Confirmed fixed from others who were experiencing the same issue (i assume it was everyone on Shopify TBH)

Contacting support on Shopify is useless because they rarely take developers seriously. Shopify does need a github issue queue where devs can get in front of other devs. Also need the ability to vote up issues, so you guys can see whom else is having the same problems to prioritize what’s wrong.

Here’s my email to Shopify regarding the CSP issue, laying it out for em

Here’s Shopify’s reply:


Thank you for reaching back.

The Google Analytics integration is fully supported by Google - if changes need to be made, then it must come from their end.

We highly recommend contacting Google using the Get Support button in the channel and choosing Google Analytics as the topic. If Google determines that there is an issue, they will contact us directly.

Thank you for your patience and understanding of this matter.

All the best,

Sarah A.
Marketplaces Advisor


Since we’re on this topic, there’s still events not integrated in to GA4 as far as I can tell.

And the more difficult ones (for you guys to implement, I understand).

I think the best way to implement this would be to add data attributes to the html that your GA4 implementation could look for on a category page and then collect that data and fire off the events.

<ul data-ga-category-id="tshirts" data-ga-category-name="T-Shirts">
<li><a data-ga-product-id="1234" data-ga-variant-id="56789" href="/product/1234">Product 1234</a></li>
<li><a data-ga-product-id="6666" data-ga-variant-id="8888" href="/product/1234">Product 1234</a></li>
</ul>

if i add csp to theme file, does it work for checkout page too ? checkout is a sperate page, as you known