starterkits / rails4-starterkit

Rails 4.1 starter app with production ready performance, security, and authentication.
MIT License
388 stars 103 forks source link

Google Analytics isn't reporting #26

Open kbarre123 opened 9 years ago

kbarre123 commented 9 years ago

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.

simple10 commented 9 years ago

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.