Minimal-mistakes: Google Analytics Script Code

Created on 17 Sep 2014  路  3Comments  路  Source: mmistakes/minimal-mistakes

My google analytics says you should use the following code to analysis site.

<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXXX-X', 'auto');
  ga('send', 'pageview');

</script>

so why we do use this script in _includes/_scripts.html? Are they the same code?

<script>
  var _gaq = _gaq || [];
  var pluginUrl = 
 '//www.google-analytics.com/plugins/ga/inpage_linkid.js';
  _gaq.push(['_require', 'inpage_linkid', pluginUrl]);
  _gaq.push(['_setAccount', '{{ site.owner.google.analytics }}']);
  _gaq.push(['_trackPageview']);

  (function() {
    var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
    var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
  })();
</script>
Won't Fix Support

Most helpful comment

For anyone bumping into this as I did:

  1. The so called "Universal Analytics" tracking code requested by @muhasturk is available using google-universal as the analytics provider in _config.yml: https://github.com/mmistakes/minimal-mistakes/blob/master/_includes/analytics-providers/google-universal.html.
  2. It's trivial to just paste whatever analytics code you want (e.g. Google's new "Global Site Tag" I pasted above) in the _includes/analytics-providers/custom.html override and specify custom as the analytics provider ( per the Analytics section in the docs).

All 3 comments

The theme is using the Classic Google Analytics script. What you included above is the new Universal one that everyone should eventually move to.

I didn't update it to avoid breaking things for those who haven't turned it on yet in GA.

Just update your copy of _scripts.html to match the new Universal script and you should be fine.

@mmistakes any news here? Looks like the old code is still there... BTW The latest recommendation looks like this (note that the tracking code appears twice, in the script query string and in the gtag call):

<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-12345678-9"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments)};
  gtag('js', new Date());

  gtag('config', 'UA-12345678-9');
</script>

For anyone bumping into this as I did:

  1. The so called "Universal Analytics" tracking code requested by @muhasturk is available using google-universal as the analytics provider in _config.yml: https://github.com/mmistakes/minimal-mistakes/blob/master/_includes/analytics-providers/google-universal.html.
  2. It's trivial to just paste whatever analytics code you want (e.g. Google's new "Global Site Tag" I pasted above) in the _includes/analytics-providers/custom.html override and specify custom as the analytics provider ( per the Analytics section in the docs).
Was this page helpful?
0 / 5 - 0 ratings

Related issues

m1evankaiser picture m1evankaiser  路  3Comments

LongQi picture LongQi  路  5Comments

floatingpurr picture floatingpurr  路  3Comments

adinriv picture adinriv  路  3Comments

ashleyconnor picture ashleyconnor  路  4Comments