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 (GA4) #194

Open
wants to merge 2 commits 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ additional_links:
# gtm: "GTM-0000000"
# gtag: "UA-00000000-0"
# google_analytics: "UA-00000000-0"
# google_analytics_4: "G-ABCDEFGHIJ"

# About Section
# about_title: About Me (Use this to override about section title)
Expand Down
9 changes: 9 additions & 0 deletions _includes/ga4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Google tag (gtag.js) -->
<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>
3 changes: 3 additions & 0 deletions _includes/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
<link rel="stylesheet" href="{{ '/assets/main.css' | relative_url }}">
<link rel="shortcut icon" type="image/x-icon" href="{{ site.favicon | default: '/assets/favicon.ico' | relative_url }}">

{%- if jekyll.environment == 'production' and site.google_analytics_4 -%}
{%- include ga4.html -%}
{%- endif -%}
{%- if jekyll.environment == 'production' and site.google_analytics -%}
{%- include google-analytics.html -%}
{%- endif -%}
Expand Down