Viral Rails

Adding Google Analytics -Video 9

Adding Google Analytics -Video 9

On February 11, 2016, Posted by , In Google Analytics, By , With No Comments

Table Of Contents

How to add google analytics Part 1

Scope analytics for production Part 2:

This is what your code should look like in the views/layouts/application.rb file when you’re done:

 

<% if Rails.env.production? %>

    <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’, ‘YOUR CODE GOES HERE’, ‘auto’);
ga(‘send’, ‘pageview’);

</script>

<% end %>

Leave a Reply

Your email address will not be published. Required fields are marked *