Is placing Google analytic tag after the head element correct?

Topic summary

Correct placement of Analytics code in a Shopify theme: the script must be inserted inside the element (between and ), not after the closing . This allows Google to recognize the tag.

A later case involved a “G-XXXXXXX” tag (GA4 Measurement ID) appearing as text at the top-left of the storefront. A screenshot helped identify it as GA4. For GA4, the correct method is to use Shopify’s Google Channel integration rather than pasting code in the theme:

  • Admin > Online store > Preferences > Manage pixel here
  • Connect your Google account
  • Select the GA4 Measurement ID
  • Connect the GA4 property
  • Remove any manually added tag from the theme

If a tag renders on the page, it’s likely placed in the rather than within .

Outcomes:

  • Original question resolved by moving the tag inside .
  • GA4 case resolved by connecting via Google Channel and removing manual code.

Newest update: another user asked for the code and setup. Guidance: use your own unique Google-provided tag and follow Google’s setup documentation before applying the relevant method above.

Status: Key issues resolved; thread open for further questions.

Summarized with AI on January 14. AI used: gpt-5.

Hi, @ecoepc !

Welcome to Shopify Community and thank you for your question.

This is almost right, though you’ve pasted the tag code right after the closing element of the head tag as denoted by .

The opening element, which you will likely find several lines up will look like . The secret is to paste your code in between these two, which would mean it is in the header element. My recommendation is to find the opening , and hit enter to add a line beneath it in which to paste your code.

Google should then be able to recognize it immediately once done correctly.

Let me know if you have further questions!

1 Like