MENU

WDV 351 HOMEWORK

Google Analytics


Google Analytics is a freemium (free and paid versions available) web analytics service offered by Google that tracks and reports website traffic. Google launched the service in November 2005 and is now the most widely used web analytics service on the Internet.

Google Analytics shows high-level, dashboard-type data for the casual user, and offers more in-depth data further into the report. Google Analytics analysis can identify poorly performing pages with techniques such as funnel visualization, where visitors came from, how long they stayed, and their geographical position.

Google Analytics is implemented with "page tags", in this case, called the Google Analytics Tracking Code, which is a snippet of JavaScript code that the website owner adds to every page of the website. The tracking code runs in the client browser when the client browses the page and collects visitor data and sends it to a Google data collection server.

Google Analytics Code Example


The code should be added near the top of the head tag and before any other script or CSS tags, and the string 'UA-XXXXX-Y' should be replaced with the property ID (also called the "tracking ID") of the Google Analytics property you wish to track.

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

  ga('create', 'UA-XXXXX-Y', 'auto');
  ga('send', 'pageview');

The above code does four main things:

1. Creates a script element that starts asynchronously downloading the analytics.js JavaScript library.

2. Initializes a global ga function (called the ga() command queue) that allows you to schedule commands to be run once the analytics.js library is loaded and ready to go.

3. Adds a command to the ga() command queue to create a new tracker object for the property specified via the 'UA-XXXXX-Y' parameter.

4. Adds another command to the ga() command queue to send a pageview to Google Analytics for the current page.


Google Analytics Report Example


Example Google Analytics