Google Analytics – Useful Chrome Extensions

1.Google Analytics Debugger

This Debugger will list all the commands run and parameters sent.

Typical commands are: initialize Google Analytics, send page view hits and send Event hits.

https://chrome.google.com/webstore/detail/google-analytics-debugger/jnkmfdileelhofjcijamephohjechhna?hl=en

7

Here is an example:

8

 

2.Event tracking tracker

Logs event tracking calls.

https://chrome.google.com/webstore/detail/event-tracking-tracker/npjkfahkbgoagkfpkidpjdemjjmmbcim?hl=en-US

9

 

3. Page Analytics

It’s a mini-version of the Google Analytics on the top of the page. I use it to view in-page analytics. Since my in-page Analytics is not working in Google Analytics reporting dashboard.

https://chrome.google.com/webstore/detail/page-analytics-by-google/fnbdnhhicmebfgdgglcdacdapkcihcoh?hl=en

10

Here is an example:

11

 

 

Advertisements

Google Analytics – Implementation in Rails App Step by Step

1. Create _google_analytics.html.erb view:

 

<!– Google Analytics –>

window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;

// Create tracker.

ga(‘create’, ‘<%= ENV[‘GOOGLE_ANALYTICS_TRACKING_ID’] %>’, ‘auto’);

<!– End Google Analytics –>

 

This code download Google Analytics code and set up a tracker. Understand Google Analytics trackers

Here we set the tracking ID as an environment variable, so that we could set up different Google Analytics accounts for different environments.

 

2. Set up the tracking ID environment variable.

2.1 For local environment: Add GOOGLE_ANALYTICS_TRACKING_ID=UA-XXXXXXX-X in .env file

2.2 For remote environments: Add GOOGLE_ANALYTICS_TRACKING_ID=UA-XXXXXXX-X to files under config/environments files. Example files listed as follows:

6

 

 

3. Add Google Analytics view to application layout:

In order to use Google Analytics for all the pages in our site, add this to application.html.erb

<head>
<!– Only set up google analytics when running in certain environments–>
<% if %w(development production).include? Rails.env %>
<%= render partial: ‘shared/google_analytics’ %>
<% end %>
</head>

 

 

4. Add track pageview code in a separate javascript file:

Here we create a separate javascript file instead of just adding the code in the view, with the consideration that we might need to add other tracking code later, such as form event tracking.

To understand how to custom pageview,  check out this instruction page

(function() {
// If google analytics is not set up, skip tracking code
if(window.ga === undefined) return;

//// Track page view
// Set the page value on the tracker. Url: get rid of parameters and trailing ‘/’
ga(‘set’, ‘page’, document.location.pathname.split(‘?’)[0]);

// Send page view
ga(‘send’, ‘pageview’);
})();

 

 

Google Analytics – Set Up in Dashboard Step by Step

1.Create a Google Analytics Account.

2. Create new property:

Click Admin on the top left of the navigation bar. Then under Property, click dropdown list:

1

Select “create new property”:

2

3.Type in all the required field:

3

Recommend turn on In-page analysis:

What is in-page analysis

4

4. Get tracking code:

Click “Get tracking ID”, get basic pageview tracking code(each property has a unique tracking ID):

5

5. Add tracking code to your site.

Don’t recommend just copy and paste the above tracking code. Instead, I recommend using the async tracking code explained here:

https://developers.google.com/analytics/devguides/collection/analyticsjs/