Google Analytics

by Gisle Hannemyr

The Google Analytics module XXXX.

Table of contents

Drupal projects discussed in this chapter: Charts, Google Analytics, Google Analytics Reports.

Introduction

Get analytics code.

Installing and enabling the modules

  1. Install and enable as you would normally install and enable a contributed Drupal module.

Configuration

Google Analytics

Google Analytics Reports

The project depends Views project. access google analytics reports

Install Charts module and enable the Google Charts submodule for dispalying charts. For better page loading with reports blocks is recommended to install and setup Ajaxblocks module.

To access data from Google Analytics you have to use project in Google Developers Console. You may use an existing or create a new.

The Google Developers Console UI has been updated since the projects README.txt (re: this issue at Drupal.org). Here are updated instructions.

Before you can get the credentials you may need to create a new project and enable the analytics API for it:

  1. Open Google Developers Console. Log in to you Google account if required.
  2. This will take you to a screen to manage your Google analytics APIs. In the top bar there will be a menu to select an API project (if you have one), and to create a new project. Click on the down-triangle of the menu.
  3. This will produce a modal pop-up. To create a new project, click on the plus (+) sign.
  4. Give the project a name and press “Create”.
  5. Make this the active project.
  6. Use the hamburger menu to select API & Services » Library Filter on “Analytics”. Select “Analytics API”
  7. Press “Enable”,

Then get the credentials:

  1. Use the hamburger menu to select API & Services » Credentials.
  2. Click the pull-down menu “Create credentials”. Select “Help me choose”.
  3. Under “What API are you using”, select “Analytics API”. (If this option does not appear, you have not yet enabled this API for this project, see steps 6 and 7 above).
  4. Under “Where will you be calling the API from?” select “Web Browser (Javascript)”. Under “What data will you be accessing?”, select “User Data”.
  5. Press “What credentials do I need?” and edit the name if necessary.
  6. Leave empty “Authorized JavaScript origins”.
  7. Fill in “Authorized redirect URIs” with “https://example.com/admin/config/system/google-analytics-reports-api”. Replace “example.com” with the base URL of your site.
  8. Press “Create Client ID”-button.
  9. Type a product name to show to users and hit “Continue” and then “Done”.
  10. Use the hamburger menu to select API & Services » Credentials.
  11. Click on the name of your new client ID to be shown both the “Client ID” and “Client Secret”.
On the Drupal site navigate to Configuration » System » Google Analytics Reports API and copy ”Client ID“ and “Client secret” from the Google Developers console into the fields. Press “Start setup and authorize account” to allow the project access to Google Analytics data.

Final word

[TBA]


Last update: 2015-05-14 for D7 [gh].