starterkits/rails4-starterkit

Google Analytics isn't reporting

Opened this issue · 1 comments

Has anyone else been successful in implementing Google Analytics with the existing code?

I've compared the app/views/layouts/_analytics.html.haml with the code on the Google Developer page, and there's a difference. Where Google's has:

$(document).on('page:change', 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);
  });

There is only:

$(document).on('page:change', function(){
    _gaq.push(['_trackPageview'])
});

I've added my property's analytics code as an environmental variable on Heroku, as I've done with many other sites, but this doesn't seem to be working.

Any analytics packages have to be handled in a special way due to Turbolinks. The Google Analytics script should already be loaded in the page before the _gaq.push is triggered.

Double check that you have analytics configured in config/analytics.yml. If a Google Analytics key is provided, the script should automatically be injected for you.

Please let me know if this works. It could be a regression bug, but it used to be working just fine.