Google Analytics

This chapter first discusses the Google anlytics web service, and then moves on to integration of this in Drupal.

Table of contents

Introduction

The Google analytics web service

Logging in

Login to Google Analytics is through Google's single sign-on. If you're logged into your Google account, clicking “Sign in to Google Analytics” on the Google Analytics home page will log you in.

Adding a site

A Google Analytics user may manage more than one account. An account may contain up to 50 properties and 25 views. A property is any resource associated with a specific tracking code. The normal use is to make a specific website a property. To add a property:

  1. Sign in to your Google Analytics account.
  2. Select the Admin tab.
  3. In the ACCOUNT column, use the dropdown menu to select the account to which you want to add the property. (If you have a lot of accounts, use the search box to help you find the right one.)
  4. In the PROPERTY column, select Create new property from the dropdown menu. (If you don't have Edit permission on the account, you won't see the Create new property option.)
  5. Select Website or Mobile app.
  6. Enter the Website or App Name. If you plan on tracking more than one app in your account, use a very specific and descriptive name that includes the edition or version number. This will help you keep your app properties organized.
  7. (Web only) Enter the Web Site URL. Do not use a trailing slash.
  8. Select an Industry Category.
  9. Select the Reporting Time Zone. This will be used as the day boundary for your reports, regardless of where the data originates.
  10. Click Get Tracking ID.

Your property is created after you click this button, but you must set up the tracking code to collect data.

Getting tracking information

To find the tracking information for a property set up for tracking, do the following:

  1. Select the Admin tab.
  2. Select the account you are going to work from the dropdown in the “Account” column.
  3. Select a property you are going to work from the dropdown in the “Property” column.
  4. In the “Property” column, click Tracking Info → Tracking Code. This gives access to the Tracking ID the Javascript Tracking code, and other information.

Reports

Slater: How To Find Your Most Popular Content Using Google Analytics.

Adding other users

To give an external user access, add the user's Google email address to the profile you want to share.

First select “Admin” from the top menu, then select the account to share from your accounts list.

Grant access either to the full account or to an individual property by clicking “User Management” under the appropriate column.

In the “Add permissions for:”-box, enter the person's Google email address. Select how much access the user shall have. Choose “read and analyze” for read-only access. (and “colaborrate” for less access). Add the “Edit” and “Manage Users” options if the user shall have an administrative role. Choose the “Notify this person by email” box to alert them that they have been given access.

Drupal Integration

Google Analytics

The module Google Analytics provide JavaScript to add the GA tracking code to pages you want tracked.

After installing the module, the only thing required to enable it is to navigate to Administration → Configuration → System → Google Analytics and add your “Web Property ID” (aka. tracking id) for the site to track to the general settings.

googleanalytics01.png

After doing this click Save configuration. The necssary JavaScript should now be added to all pages.

redflagBy default, the Google Analytics module is set up to respect the “Do-not-track” protocol. If your browser is set up to send the “Do-not-track” header, no tracking code will be embedded. If you examine the source code served, and the tracking code javascript is not showing up, the most likely cause is that your browser requests no tracking. It is possible to disable this behaviour by unticking the “Universal web tracking opt-out“ ckeckbox (see below). However if you do so, your side will forward tracking information to Google for visitors that do not want to be tracked. It is strongly recommended that you keep the default.
  googleanalytics01.png

Administration → Configuration → System → Google Analytics Reports API

Google Analytics Reports

Amazeelabs: Create the ultimate Google Analytics Dashboard for Drupal.

Lullabot: Karen S. (slightly outdated - should be updated and repurposed.

First, install Google Analytics Reports as you normally install a contributed Drupal project.

Then navigate to Administration → Configuration → System → Google Analytics Reports API. This will take you to the Inital setup form shown below.

googleanalyticsreport01.png

Save a copy of the URI shown in point #6 in this form.

Before you can use Google Analytics Reports to access data from Google Analytics you should have a suitable project set up in Google Developers Console.

If you don't have a project, make sure you're logged into your Google account and click the Create a project… link, enter project name, agree to the terms of service and press Create.

googledevcon01.png

Then, go though the following steps with the newly created project:

  1. Navigate to the Open APIs & auth → APIs. Search for “Analytics API”. Open the API page and press Enable API.
  2. Navigate to the Open APIs & auth → Credentials → OAuth consent screen. Enter Product name an other information and press Save button.
  3. Navigate to the Open APIs & auth → Credentials → Credentials → Add credentials. Select the OAuth 2.0 Client ID link.
  4. Select Web application as Application type. Leave the textfield Authorized JavaScript origins empty. Fill in Authorized redirect URIs with the URI saved from point #6 in the Initial setup form and press Create button.
  5. Copy “Client ID” and “Client secret” from the modal to the appropriate fields in the Initial setup form.
  6. Press Start setup and authorize account. This will allow the project to access Google Analytics data.

You are now taken to a consent form and form where you select the profile to access.

If you need to find the “Client ID” and “Client secret” for an existing project, select the project in the top pull-down menu, click on AI & auth → Credentials, and then on the project.

Final word


Last update: 2013-09-01 [gh].