constantsolutions / website-comments

Comments for website
0 stars 0 forks source link

2020/06/delay-loading-of-google-analytics-google-tag-manager-script-for-better-pagespeed-score-and-initial-load/ #1

Open utterances-bot opened 2 years ago

utterances-bot commented 2 years ago

Delay loading of Google Analytics / Google Tag Manager script for better PageSpeed score and initial load | Constant Solutions

This is a custom description for SEO and Open Graph purposes, rather than the default generated excerpt. Simply add a description field to the frontmatter.

http://localhost:8000/2020/06/delay-loading-of-google-analytics-google-tag-manager-script-for-better-pagespeed-score-and-initial-load/

JCDerrick108 commented 2 years ago

Thank you for sharing this. I implemented, via the footer of our site, and it worked great, but I am having trouble getting Pageviews to register, even with your fix in the code. Curious as to if you’ve experienced any issues with Pageviews since posting this? Thanks again for this great resource!

marekka commented 2 years ago

Sorry, but this is not working :( G tracking is not loaded :(

marekka commented 2 years ago

Sorry - seems to be working :)

Tyler1110 commented 1 year ago

I pasted this in my footer and the code is showing on my live site, I'm on webflow I'm not sure if that's the problem.

gerlor50 commented 1 year ago

Thanks a lot. I pasted the code in the header, and it is also showing in the front end.

Salome-sperling commented 1 year ago

Thanks for the solution. I'm working with Webflow too, and it is also showing it in the front end...

CleSitMut commented 1 year ago

Thank you so much, you are an absolute life saver!

oa2000 commented 1 year ago

Where do I add this script ?

Seryel commented 1 year ago

The script works, you just need to follow certain steps:

1- Remove the Tag Manager code and replace it with the script. 2- Modify the script with the Tag Manager ID. 3- Add the script to the header of your website. 4- If GTmetrix still detects Tag Manager, adjust the variable setTimeout(initGTM, 3500);. In my case, my website loaded before 3 seconds, so adjusting the value to setTimeout(initGTM, 2500); worked perfectly. Note: Perform tests, especially with events and conversions, including Facebook Ads, Google Ads, etc.

bradandmoo commented 12 months ago

Hi. Thank you for such a great post! My website is on shopify and we have the google/you tube shopify app to link our GTM tag to our website. My question is: Should we replace the code provided by GTM and instead use your code? OR, should we use both? Thanks.

Hardwaypro commented 6 months ago

A real game changer!

GodinhoB commented 3 months ago

Hello , i'm trying to use your code but on this line :" dataLayer.push({ event: 'gtm.js', 'gtm.start': new Date().getTime(), 'gtm.uniqueEventId': 0 }); "

I don't see where dalaLayer is been defined

simplenotezy commented 3 months ago

@GodinhoB the dataLayer is a global variable introduced by the gtm.js script if I recall correctly. So as soon as the script is loaded, dataLayer should be present. Try to go to any website that you believe have Google Analytics (like matas.dk) and type "dataLayer" in the console. You should see it hold some values image

simplenotezy commented 3 months ago

@bradandmoo sorry for the late response here. My code embeds gtm.js, so you'll need to disable any other way of adding Google Analytics, otherwise it would be added multiple times, which possibly could introduce unwanted results (and not provide the expected effect either)