- This topic has 5 replies, 2 voices, and was last updated 12 months ago by
Tom.
-
AuthorPosts
-
January 18, 2020 at 12:59 pm #1136343
Artem
Hi,
I need to put the script of my cookie banner at the top of the <head> section of my site. So it should be the very first.
I do it via Hook wp-head.
The problem is that the google analytics script is always on top.
<script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script>
For analytics, I use Global Site Tag (gtag.js) tracking code. I put it in the Hook wp-head with a priority 15.
My cookie banner script I put in the Hook wp-head with a priority 1.When I see html – Global Site Tag (gtag.js) tracking code
<script src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXX-1" type="text/javascript"></script>
is below my cookie banner script. So, it’s OK. But I don’t know how to move google analytics script.So, how can I put my script at the top?
Thank you.January 18, 2020 at 6:38 pm #1136488Tom
Lead DeveloperLead DeveloperHi there,
Have you tried putting the analytics and gtag scripts in the same hook element? That way they should both appear above the cookie script.
Let me know π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJanuary 19, 2020 at 5:33 am #1136735Artem
The thing is that I don’t have any other analytics script. Just this:
<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=UA-XXXXXXXXXX"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'UA-XXXXXXXX', { 'anonymize_ip': true }); </script>
When I put this in the Hook wp-head I automaticaly get
<script type="text/javascript" async="" src="https://www.google-analytics.com/analytics.js"></script>
as a first script in the head.
You can see it on my site.
Thank you.January 19, 2020 at 4:17 pm #1137312Tom
Lead DeveloperLead DeveloperI’m not seeing that code in the source of your website.
Can you try clearing your browser cache?
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-developmentJanuary 20, 2020 at 1:12 am #1137527Artem
Tom,
Thank you very much!
I was struggling with this stuff for several days. And the solution was so simple.
The issue resolved by clearing browser cache.
Thanks again.January 20, 2020 at 10:19 am #1138235Tom
Lead DeveloperLead DeveloperYou’re very welcome π
Documentation: http://docs.generatepress.com/
Adding CSS: http://docs.generatepress.com/article/adding-css/
Ongoing Development: https://generatepress.com/ongoing-development -
AuthorPosts
- You must be logged in to reply to this topic.