Skip to content Skip to navigation

Getting Started on Sites: Adding Google Analytics to Your site

Google Analytics gives you critical insights that help drive innovation and evolution by showing you exactly how people are using your site. Understanding how your site is being used can aid in identifying where improvements can and should be made. This post will cover how to add Google Analytics to your Drupal site.

Once your Google Analytics account is set up, there are three main steps that need to be completed in order to begin tracking your site: 1. Creating a new property for your site, 2. Enabling the Google Analytics module, and 3. Configuring the Google Analytics module.

Create a new property for your site

  1. Log in to your Google Analytics account.
  2. Click the Admin tab.
  3. In the Account column, use the dropdown menu to select the account to which you want to add the property.
  4. In the Property column, click Create new property from the dropdown menu.

    click create new property
     

  5. Select Website.
  6. Enter your Website Name.
  7. Enter your Website URL.
  8. Select an Industry Category and Reporting Time Zone.
  9. Click Get Tracking ID (copy/note the tracking ID for later step).

Enable the Google Analytics module

  1. Log in to the site you wish to track as an administrator.
  2. Navigate to Admin -> Modules.
  3. Enable the Google Analytics module.

    enable google analytics module
     

  4. Click Save configuration.

Configure the Google Analytics module

  1. Navigate to Admin -> Configuration -> System -> Google Analytics.
  2. Enter the Web Property ID (UA-xxxxxxx-yy) from your Google Analytics account into the Web Property ID field.

    enter the web property id

  3. Click Roles.
  4. Check Add to every role except the selected ones, then select the roles that you don’t want to be tracked (i.e., administrator).

    select the roles you don't want to track

  5. Click Users.
  6. Check Tracking on by default, users with opt-in or out of tracking permission can opt out.

    select the user setting

  7. Adjust other settings as necessary.
  8. Click Save configuration.

Your Drupal site is now being tracked by Google Analytics. You can generate detailed statistics about your site's traffic, measure visitor behavior, monitor browser usage and other important things from your Google Analytics account.

But wait, there's more! Adding views and filters

It's possible that other sites may copy your header markup and paste it into their site verbatim as a template. This could include your site's Google Anayltics code and property ID. When this happens, it can result in data being sent to your property in Google Analytics from sites that are not yours, and that are unrelated to your content.

One way to solve this is by creating a View in Google Analytics and adding a Filter to it that only includes data from the hostname that you want to monitor. This is something to consider doing for all new properties after set up, as Views are not retroactive and only affect new data being sent to Google Analytics.

Here's how to do it:

  1. Log in to your Google Analytics account.
  2. Select the Admin tab.
  3. Navigate to the Account and Property to which you want to add the view and filter.
  4. In the View column, click Create new view from the dropdown menu.

    click create new view

  5. Select Website.
  6. Enter the Reporting View Name (i.e., mysite.stanford.edu only).
  7. Select a Reporting Time Zone.
  8. Click Create View.
  9. From the View column, click Filters.

    click filters

  10. Click + New Filter.
  11. Select Create new Filter.
  12. Enter a name for the filter in the Filter Name filter.
  13. Select Custom Filter.
  14. Select Include.
  15. Select Hostname from the Filter Field dropdown.
  16. Enter your site URL in the Filter Pattern field (i.e., mysite\.stanford\.edu).

    adjust the settings for the new filter on the view

  17. Click Save.

The more you know

I hope these steps were helpful! Google Analytics can be a great tool for managing your site and planning improvements based on what your viewers need. Do you have other Google Analytics tricks to share? Share more in the comments below!