Skip to content

Commit 9c3f1aa

Browse files
authored
Add Google Analytics Support (yousinix#43)
fixes yousinix#44
1 parent 42edeb0 commit 9c3f1aa

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

_includes/analytics.html

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{%- if jekyll.environment == 'production' and site.analytics.enabled == true -%}
2+
<!-- Global site tag (gtag.js) - Google Analytics -->
3+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.analytics.google.tracking_id }}"></script>
4+
<script>
5+
window.dataLayer = window.dataLayer || [];
6+
function gtag(){dataLayer.push(arguments);}
7+
gtag('js', new Date());
8+
9+
gtag('config', '{{ site.analytics.google.tracking_id }}');
10+
</script>
11+
{%- endif -%}

_layouts/default.html

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
</main>
1919

2020
{% include footer.html %}
21+
{% include analytics.html %}
2122
{% include scripts.html %}
2223

2324
</body>

docs/_config.yml

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ collections:
6363
disqus: your-short-name-disqus # Your website Shortname on disqus
6464

6565

66+
### Analytics ###
67+
analytics:
68+
enabled: false # Set true to enable analytics
69+
google:
70+
tracking_id: your-google-tracking-id
71+
72+
6673
### Defaults for collections ###
6774
defaults:
6875
- scope:

test/_config.yml

+7
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ collections:
3535
output: true
3636

3737

38+
### Analytics ###
39+
analytics:
40+
enabled: true
41+
google:
42+
tracking_id: google-tracking-id
43+
44+
3845
### Defaults for collections ###
3946
defaults:
4047
- scope:

0 commit comments

Comments
 (0)