Archived topic
Google Global Site Tag (gtag.js)
5 replies · Started by Mario on October 28, 2021
Hi there,
I tried to insert the Google Global Site Tag (gtag.js) from my Goggle Analytics admin panel into the header section of my website using a hook as per the advice in the documentation (I set the hook position to wp_head and to Entire Site). However, when I look at the HTML code of the website, I can see that it's actually located in the body section (after <body>) and the code itself has also changed from what I copied and pasted into the hook text box.
How do I resolve this?
Hi there,
However, when I look at the HTML code of the website, I can see that it’s actually located in the body section (after <body>)
That's not really possible as the wp_head hook is located here:
https://github.com/tomusborne/generatepress/blob/master/header.php#L17
Can you disable all plugins except GP premium to test first?
Hi Leo,
I can't disable all other plugins - it is a live site. The code in line 313:
}</style></head><body class="home page-template-default page page-id-10914 wp-custom-logo wp-embed-responsive post-image-aligned-center slideout-enabled slideout-mobile sticky-menu-no-transition sticky-enabled both-sticky-menu mobile-header mobile-header-logo mobile-header-sticky no-sidebar nav-below-header separate-containers nav-search-enabled header-aligned-left dropdown-hover full-width-content elementor-default elementor-kit-7434" itemtype="https://schema.org/WebPage" itemscope> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXX"></script> <script>window.dataLayer = window.dataLayer || [];
You can see it is in line after the </head>.
Can you start a staging site so we can go through some debugging tests?
Make sure you are actually using the wp_head hook:
https://github.com/tomusborne/generatepress/blob/master/header.php#L17
and not the wp_body_open hook which is right after the opening of the <body>:
https://github.com/tomusborne/generatepress/blob/master/header.php#L27
Hi Leo,
Thanks for the help.
I have made the research on my development site and found that the problem was with a plugin: Asset CleanUp Pro - Move All <SCRIPT> tags From HEAD to BODY - I have disabled.
The analytics code is bak in the head section.
No problem :)