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 with global site tag (gtag.js) #1563

Merged
merged 1 commit into from
Mar 12, 2018
Merged
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 _config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ social:

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

Expand Down
9 changes: 9 additions & 0 deletions _includes/analytics-providers/google-gtag.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Global site tag (gtag.js) - Google Analytics -->
<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-gtag" %}
{% include /analytics-providers/google-gtag.html %}
{% when "custom" %}
{% include /analytics-providers/custom.html %}
{% endcase %}
Expand Down
3 changes: 2 additions & 1 deletion docs/_docs/05-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -679,13 +679,14 @@ Analytics is disabled by default. To enable globally select one of the following
| -------------------- | --------------------------------------------------------------- |
| **google** | [Google Standard Analytics](https://www.google.com/analytics/) |
| **google-universal** | [Google Universal Analytics](https://www.google.com/analytics/) |
| **google-gtag** | [Google Analytics Global Site Tag)](https://www.google.com/analytics/) |
| **custom** | Other analytics providers |

For Google Analytics add your Tracking Code:

```yaml
analytics:
provider: "google-universal"
provider: "google-gtag"
google:
tracking_id: "UA-1234567-8"
```
Expand Down