Skip to content

Commit

Permalink
feat: update google analytics to gtag.js, close kitian616#87
Browse files Browse the repository at this point in the history
  • Loading branch information
kitian616 committed Aug 26, 2018
1 parent f9726f9 commit 6f0e283
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
16 changes: 7 additions & 9 deletions _includes/analytics-providers/google.html
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
{%- if site.analytics.google.tracking_id -%}

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id={{ site.analytics.google.tracking_id }}"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

ga('create', '{{ site.analytics.google.tracking_id }}', 'auto');
ga('send', 'pageview');
gtag('config', '{{ site.analytics.google.tracking_id }}');
{% if site.analytics.google.anonymize_ip == true %}
ga('set', 'anonymizeIp', true);
gtag('config', '{{ site.analytics.google.tracking_id }}', { 'anonymize_ip': true });
{% endif %}
</script>

{%- endif -%}
1 change: 1 addition & 0 deletions _layouts/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
{%- include snippets/get-lang.html -%}
<html lang="{{ __return }}">
<head>
{%- include analytics.html -%}
{%- include head.html -%}
<script>
{%- include scripts/utils.js -%}
Expand Down
3 changes: 1 addition & 2 deletions _layouts/page.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,5 +158,4 @@


{%- include markdown-enhancements.html -%}
{%- include pageview.html -%}
{%- include analytics.html -%}
{%- include pageview.html -%}

0 comments on commit 6f0e283

Please sign in to comment.