Skip to content
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

Closed
wants to merge 2 commits into from

Conversation

f0rked
Copy link

@f0rked f0rked commented Nov 1, 2020

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.

Copy link

@davorpa davorpa left a 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.

Comment on lines +4 to +14
{% 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 %}
Copy link

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?

Copy link
Author

@f0rked f0rked Nov 4, 2020

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.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion should be placed after {% seo %} tag.

I have installed this theme in my sites and this is what generates:
Screenshot from 2020-11-05 22-15-14

For SEO I think it's better have the metas, title... near to top. I usually put scripts as lastest, not all browsers accepts async or defer attributes in them:

Are you agree?

Copy link

@davorpa davorpa left a 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 🤗

Comment on lines +4 to +14
{% 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 %}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion should be placed after {% seo %} tag.

I have installed this theme in my sites and this is what generates:
Screenshot from 2020-11-05 22-15-14

For SEO I think it's better have the metas, title... near to top. I usually put scripts as lastest, not all browsers accepts async or defer attributes in them:

Are you agree?

@@ -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 %}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion should be placed after {% seo %} tag.

I have installed this theme in my sites and this is what generates:
Screenshot from 2020-11-05 22-15-14

For SEO I think it's better have the metas, title... near to top. I usually put scripts as lastest, not all browsers accepts async or defer attributes in them:

Are you agree?

@parkr
Copy link
Contributor

parkr commented Jul 26, 2021

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 _includes/head-custom-google-analytics.html file. This is the v3 code. In order to use v4 in your site, simply add a _includes/head-custom-google-analytics.html file to your Jekyll site and add the v4 code.

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!

@parkr parkr closed this Jul 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants