-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for Google gtags (Google Analytics v4) #64
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@f0rked good implementation allowing both support!!
Remember that to pass W3C validation the meta charset
must be in the first 1024 characters of page.
Can you move the scripts blocks below? For example at the end of head tag
Thanks in advance.
{% if site.google_analytics_v4 %} | ||
<!-- Global site tag (gtag.js) - Google Analytics --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics_v4 }}"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
|
||
gtag('config', '{{ site.google_analytics_v4 }}'); | ||
</script> | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@f0rked good implementation allowing both support!!
Remember that to pass W3C validation the meta charset must be in the first 1024 characters of page.
Can you move the scripts blocks below, for example at end of head tag?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, the Google script has to be the first one so I moved all the meta tags to the beginning. Now is passing the html validations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK. Thanks for moving to top 🤗
{% if site.google_analytics_v4 %} | ||
<!-- Global site tag (gtag.js) - Google Analytics --> | ||
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics_v4 }}"></script> | ||
<script> | ||
window.dataLayer = window.dataLayer || []; | ||
function gtag(){dataLayer.push(arguments);} | ||
gtag('js', new Date()); | ||
|
||
gtag('config', '{{ site.google_analytics_v4 }}'); | ||
</script> | ||
{% endif %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -12,9 +15,6 @@ | |||
gtag('config', '{{ site.google_analytics_v4 }}'); | |||
</script> | |||
{% endif %} | |||
<meta charset='utf-8'> | |||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | |||
<meta name="viewport" content="width=device-width, initial-scale=1"> | |||
<link rel="stylesheet" href="{{ '/assets/css/style.css?v=' | append: site.github.build_revision | relative_url }}"> | |||
|
|||
{% seo %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @f0rked, thank you so much for your proposal! We've gone with a modular approach with hacker v0.2.0. In #79, you'll see that we added a We plan to freeze all Google Analytics code at v3 to maintain backwards compatibility and since we have generally worked to remove any unnecessary tracking code. We can't remove GAv3 outright due to this backwards compatibility requirement, so we've given this as an alternative. Thank you! |
With this pull request will be support for Google Analytics v4 by using the google_analytics_v4 variable in _config.yml.
Old Google Analytics (analytics.js) is still supported by means of google_analytics variable but v4 takes precedence if both variables are set.
This pull request should address issue #63.