Google Analytics stripping <script> tags so code shows on page

I went to Google analytics and copied my tracking code, except now it says “google tag manager” for the tracking code, and there are two tags. When I paste the code into the Google Analytics, and “update”, it strips away the first tags so the actual code shows at the top of my website. I’m wondering how to fix this. i have x version 5.2.4

Hi there,

Unfortunately, the given URL is wrong, I found the URL but the user/pass is wrong too. Kindly give us the information in separate lines using the Secure Note:

WordPress Dashboard URL
WordPress Dashboard Username
WordPress Dashboard Password

We need to check the code you try to enter, but we also need to make sure that you have the latest version of the Google Analytics plugin.

Also, I see only the URL of the Tag manager on your homepage front end You should add the whole script. For more information:

Thank you.

Sorry about the URL. Here is the correct one:

I insert this code from GA:

However, it removed the first set of tags (but not the second set)

Hello There,

Thanks for the information. We have logged and regretfully we cannot checked your site because we are locked out.

Meanwhile, I have tested your code in our local testing and your code is working with no issues:

<script async src="https://www.googletagmanager.com/gtag/js?id=UA-58170584-1"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-58170584-1');
</script>

The output:

Could you please confirm that you are using the latest version? Please check out changelog here:
https://theme.co/changelog/#google-analytics-2-0-3

I apologize for the lockout. I installed temporary login without a password. It is still stripping the script tags once I hit “Update”. I believe I have the latest version. I’m attaching a screenshot. The original code that GA gives me is:

< script async src=“https://www.googletagmanager.com/gtag/js?id=UA-58170584-1”>
< script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());

gtag(‘config’, ‘UA-58170584-1’);

Hello There,

Thanks for updating in! I have logged in to your site and I can confirm that the <script> tag is removed by the plugin. Taking a closer look at your code, it seems that this is not a Google analytics code. Please keep in mind that this plugin is designed to easily insert Google Analytics code only. Please check out the knowledge base to know more the limitations and the sole purpose of this plugin here:

Hope this helps.

I do not understand. when I log into google analytics admin and “get tracking code”, that is the tracking code they give me. See screenshot. https://drive.google.com/file/d/1TI6Vo30m-d8k5sdga1kkun0HZTyUxTmH/view?usp=sharing

So you’re saying that code does not work with the plugin, but yet that is the code they keep giving me to use.

I see that the tracking code from GA is different than previous codes. Now it is called “Google tag manager tracking code”. I googled it but didn’t understand it all. From what I gather, all new properties are assigned the new GA tag manager code instead of the old format tracking code. I see no option to revert back to the original GA tracking code where there was only one script tag. No matter what I do, I can only get the tracking code in that screenshot - this new format caled Google tag manager tracking code".

So since that’s the only tracking code I can get from GA, if it doesn’t work with your Google Analytics plugin, I guess I will have to insert it directly into a header.php file somewhere?? That’s the best guess I have at this point.

I contacted Google and asked them why I now have a tag manager tracking code and how to revert to the old Universal tracking code so I could use it in your plugin. This was their reply:

The new analytics code is the Global Site Tag gtag.js.
Its’ main purpose is for users that don’t want a full blown tag management system like Google Tag Manager and to help simplify integration and data across a number of google products such as GA and Adwords for example.

< script async src=“https://www.googletagmanager.com/gtag/js?id=GA_TRACKING_ID”>
< script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments)};
gtag(‘js’, new Date());

gtag(‘config’, ‘GA_TRACKING_ID’);

So I guess they’re just saying that this new code is the default tracking code now and that’s what I have to use.

Hello There,

Thank you for sharing this. I will relay this to our developers so that they can make changes in the plugin. For the meantime, please disable Google Analytics plugin and make use of the Insert Header and Footer plugin instead (https://wordpress.org/plugins/insert-headers-and-footers/).

This should help you resolve the current issue while we have to fix this problem in our bundled plugin.

Thank you for your understanding.

thank you so much

You’re welcome! :slight_smile:

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.