analytics script tag is duplicated after using the plugin
See original GitHub issueWhen using google analytics script code, the prerendered html in the head looks like:
<script async="" src="https://www.google-analytics.com/analytics.js"></script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
When the page is opened in a browser, it keeps the generated script tag, and the analytics code then when executed it adds another script tag, ending with double script tag
<script async="" src="https://www.google-analytics.com/analytics.js"></script>
<script async="" src="https://www.google-analytics.com/analytics.js"></script>
Issue Analytics
- State:
- Created 6 years ago
- Comments:12 (1 by maintainers)
Top Results From Across the Web
Duplicate tag for analytics - WordPress.org
I'm using the plugin “Header Footer Code Manager” to add the scripts in the whole site. The page I need help with: [log...
Read more >Find & Fix Duplicated Google Analytics Codes | GrowthSavvy
By copying and pasting the latest version of the analytics code into the section of your website's code. You can find this code...
Read more >Same web property ID is tracked twice - Mixed Analytics
Hi Ana! The problem is that you have both on-site GA code (gtag.js) and Google Tag Manager running on your site. Since you're ......
Read more >How can i remove duplicate Google Analytics code in my ...
I have installed Monster Insights plugin in my Wordpress site. I have also put GA code in theme options previously, but later I...
Read more >How does duplicate Google Analytics tracking code affect a site?
The consequences of having two Google Analytics scripts, especially if they are pointing to the same UA-ID, is that you'll end up double ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In case this is useful, here’s what I’ve been doing to circunvent this:
I created a file called
extraScripts.js
, which exports a string with all the extra content I want to be added to each and every rendered page:extraScripts.js
Then, in
webpack.prod.conf.js
:webpack.prod.conf.js
This produces the desired output for me. Of course you can modify the
postProcess
function to insert whatever string in whatever position in your final HTML.All of my (async) scripts get duplicated upon prerendering. This screws all dynamically rendered content (external iframes, like Analytics, Repuso and Tawk.to in my case, don’t even render at all).
I’m surprised this is not addressed, and is deflected as “out of the scope” of the plugin or vague solutions are provided.
Hope we can shed some light into this and get a consistent solution.