Search…

X3 Photo Gallery Support Forums

Search…
 
User avatar
ulfklose
Experienced
Topic Author
Posts: 48
Joined: 10 Dec 2019, 09:10

Can I add something directly after body?

03 Feb 2020, 15:14

My SEO buddy asked me to install Google Tag Manager on my website. To do this I have to add a snippet to the head (no problem) and to the body. 

I did this by adding the snippet to the footer section in the custom settings but Google wants me to insert the snippet right after the opening body tag. Is there a way I can do that?

https://support.google.com/tagmanager/a ... 3696?hl=en
 
User avatar
mjau-mjau
X3 Wizard
Posts: 13993
Joined: 30 Sep 2006, 03:37

Re: Can I add something directly after body?

03 Feb 2020, 23:53

ulfklose wrote:My SEO buddy asked me to install Google Tag Manager on my website. To do this I have to add a snippet to the head (no problem) and to the body. 
Although I haven't used "tag manager" myself yet, the script used for this is same uses as for Google Analytics. When you add your tracking ID to Settings > Accounts, X3 will load the gtag.js script from googletagmanager, at the very top of the <head>:
Code
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-12345678-1"></script><script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-59731830-1');
</script>
The only reason Google wants to load this as high up as possible in the document, is so that it can detect bounces (visitors leaving, or navigating away from the page before it's fully loaded), and perhaps to do some load-timing functions.
ulfklose wrote:I did this by adding the snippet to the footer section in the custom settings but Google wants me to insert the snippet right after the opening body tag. Is there a way I can do that?
https://support.google.com/tagmanager/a ... 3696?hl=en
Is there any logic to this? As noted, the only reason for this, is so that the script might trigger a few ms earlier. There is no way to add anything top top of body in X3 ... You could inject via javascript, but that would abandon the purpose in the first place. I would be surprised if there is any practical to this.