~xdavidwu/xdavidwu.link

0ff9dcc8936b3a438f9125d34e635b8b54ee280a — Matías E. Fernández 6 years ago bb7cf77
Add support for Google Analytics with global site tag (gtag.js) (#1563)

For documentation see https://developers.google.com/analytics/devguides/collection/gtagjs/
and https://support.google.com/analytics/answer/7538414.
3 files changed, 12 insertions(+), 1 deletions(-)

M _config.yml
A _includes/analytics-providers/google-gtag.html
M _includes/analytics.html
M _config.yml => _config.yml +1 -1
@@ 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          :


A _includes/analytics-providers/google-gtag.html => _includes/analytics-providers/google-gtag.html +9 -0
@@ 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>

M _includes/analytics.html => _includes/analytics.html +2 -0
@@ 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 %}