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 Analytics 4 #108

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ You can see the full set of partials you can replace in the
If you don't want Disqus or want to use something else, override
`comments.html`.

* For Google Analytics support, define a `google_analytics` variable with
* For Google Analytics support, you can define a `google_analytics` variable for **Universal Analytics** or a `google_analytics_4` variable for **Google Analytics 4** with
your property ID in your config file.

There's also a bunch of minor tweaks and adjustments throughout the
Expand Down
12 changes: 11 additions & 1 deletion _includes/google-analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,14 @@
ga('create', '{{ site.google_analytics }}', 'auto');
ga('send', 'pageview');
</script>
{% endif %}
{% elsif jekyll.environment == 'production' and site.google_analytics_4 %}
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.google_analytics_4 }}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '{{ site.google_analytics_4 }}');
</script>
{% endif %}