Skip to content

Commit

Permalink
Merge pull request #1183 from sonnyarora/add-google-analytics-4
Browse files Browse the repository at this point in the history
Add Google Analytics 4 Support (Issue #1152)
  • Loading branch information
rjzupkoii authored Feb 14, 2024
2 parents aa9ed61 + 96d1b6e commit dfc3ce3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ social:

# Analytics
analytics:
provider : "google-universal" # false (default), "google", "google-universal", "custom"
provider : "google-universal" # false (default), "google", "google-universal", "google-analytics-4", "custom"
google:
tracking_id :

Expand Down
8 changes: 8 additions & 0 deletions _includes/analytics-providers/google-analytics-4.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<script async src="https://www.googletagmanager.com/gtag/js?id={{site.analytics.google.tracking_id}}"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', '{{site.analytics.google.tracking_id}}');
</script>
2 changes: 2 additions & 0 deletions _includes/analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
{% include /analytics-providers/google.html %}
{% when "google-universal" %}
{% include /analytics-providers/google-universal.html %}
{% when "google-analytics-4" %}
{% include /analytics-providers/google-analytics-4.html %}
{% when "custom" %}
{% include /analytics-providers/custom.html %}
{% endcase %}
Expand Down

0 comments on commit dfc3ce3

Please sign in to comment.