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 GA4 for theme slate #82

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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ Additionally, you may choose to set the following optional variables:
```yml
show_downloads: ["true" or "false" (unquoted) to indicate whether to provide a download URL]
google_analytics: [Your Google Analytics tracking ID]
google_analytics_v4: [Your Google Analytics version 4 (GA4) tracking ID]
```

### Stylesheet
Expand Down Expand Up @@ -70,6 +71,8 @@ If you'd like to change the theme's HTML layout:

### Customizing Google Analytics code

<!-- TODO: this section should be removed? -->

Google has released several iterations to their Google Analytics code over the years since this theme was first created. If you would like to take advantage of the latest code, paste it into `_includes/head-custom-google-analytics.html` in your Jekyll site.

### Overriding GitHub-generated URLs
Expand Down
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ title: Slate theme
description: Slate is a theme for GitHub Pages.
show_downloads: true
google_analytics:
google_analytics_v4:
theme: jekyll-theme-slate
10 changes: 10 additions & 0 deletions _includes/head-custom-google-analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,13 @@
ga('send', 'pageview');
</script>
{% endif %}
{% if site.google_analytics_v4 %}
<!-- Google tag (gtag.js) -->
<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 %}