Site logo

Archived topic

Why does the google analytics code keep disappearing

12 replies · Started by Clare on November 26, 2021

Viewing posts 1–13 of 13

At least twice now the gooogle analytics code has disappeared from my head theme code. Why is this? I'm not making any updates to the theme or Wordpress versions other than what is happening automatically. Thanks

Hi there,

how has the GA code been added to the site ?

Hi David. This has happened again - it seems to happen every couple of months. I have added it again to the theme header. Any idea why it keeps dropping off?

Thanks David. I'm not editing anything in Theme editor but I am going into customise and tweaking things like heading settings - size, weight etc. Would this cause GA to fall off?

Hi Clare,

Let's settle this for the script so it NEVER happens again.

Can we change how the script is being added?

I suggest using a Hook element for this.

The setup would be something like this - https://share.getcloudapp.com/p9uXZw5x

And on its display rule tab. Set the Display Rule Location to "Entire site".

This way, the GA won't be messed up even if the theme updates.

Hi Elvin and David

Just coming back to this. I've followed your instructions Elvin and also the first part of the instructions on the page David gave above, but I can't find a second lot of code on my GA for the second part on David's page. Am I supposed to add that in also and if so where do I find the code? Thanks

Hi Fernando

So I need to add that Google Tag Manager code just to get Google Analytics to stick on my site? (see all previous comments on this post).

Hi Clare,

Just a follow up. To be sure, I tried adding Google Analytics on my personal site to see if anything has changed.

You’re correct. There’s only one tag for Google Analytics specifically. I followed this specific article and I was able to make it work: https://www.wpbeginner.com/beginners-guide/how-to-install-google-analytics-in-wordpress/

Here is a screenshot of it working on my site after adding the Global site tag code on my header: https://share.getcloudapp.com/NQuNjxQn

To reiterate, you only need this code: https://www.wpbeginner.com/beginners-guide/how-to-install-google-analytics-in-wordpress/#:~:text=you%20click%20the%20%E2%80%98Global%20site%20tag, and couple of other steps shown in the article to make Google analytics work.

Hope this clarifies. :)

Hi Fernando

That document is very dense and I'm a bit lost in it to be honest. Are you saying to simply add the GA code into the header section in the theme editor? If so that is what I did originally and it keeps dropping off every time the theme is automatically updated..

I've added the first lot of code into the hook as Elvin suggested. Do I need to do anything else?

Thanks

Are you saying to simply add the GA code into the header section in the theme editor?

NO, please add the code via a hook element.

I’ve added the first lot of code into the hook as Elvin suggested. Do I need to do anything else?

That should be good.

This archived topic is closed to new replies.