question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Google is advising to put all of the gTag code inside the <head> .

See original GitHub issue

Google is advising to put all the gtag code inside the <head> element.

Why can’t I find nothing about this advice in any of the docs of Next, when using Next/Script?

Also, now the Google Analytics implementation is not working, it only works when gtag script is inside <head> element.

image

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
balazsorban44commented, Jul 15, 2022

You can read more about how to load analytics scripts in our docs under next/script:

https://nextjs.org/docs/basic-features/script#afterinteractive

Next.js will inject the script into head for you, and add necessary optimizations to defer loading the analytics script after the page has become interactive to ensure performance.

0reactions
github-actions[bot]commented, Aug 16, 2022

This closed issue has been automatically locked because it had no new activity for a month. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Should You Place The GA Tracking Code In The Header or ...
This is the main reason why Google recommends putting your tracking code in the header, but by making the GA tracking code asynchronous,...
Read more >
Should I put the Google Analytics JS in the <head> or at the ...
Putting it at the end of the <head> section helps ensure the your metrics are tracked even when a user doesn't let the...
Read more >
Google Tag Manager Container Code. In head or body?
Where should you place your Google Tag Manager container code? Website head or body? This blog post will explain.
Read more >
Set up and install Tag Manager - Google Support
Google Tag Manager lets you configure and deploy tags from Google products ... Place the <script> code snippet in the <head> of your...
Read more >
Where Should The Google Tag Manager Snippet Be Placed?
Google Tag Manager recently changed their implementation guidelines and now recommends two snippets, one in the Head and one in the Body.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found