Posted to Ben Finklea's blog on October 15th, 2010

How to Install Google Analytics on your Drupal Site

When it comes to tracking data on your Drupal site, there are dozens of analytics packages you can choose from... but it sure is hard to beat Google Analytics. It’s free, easy to install, quick to get started, and is very user-friendly with easy-to-read charts and graphs. And yet, it includes robust features that show you advanced segmentation, customizable reporting, and industry benchmarking.

When you use Google Analytics with Drupal, it gets even better. Thanks to the Google Analytics module, it’s easy to install, configure and test. The Google Analytics module was created by Mike Carter and is now maintained by Alexander Hass. A tip of the hat and a bow, gentlemen! Thank you from the entire Volacci team!

Creating a Google Analytics Account

The first move you need to make, if you haven’t already, is to create a Google Analytics account and install it on your Drupal site. Just carry out the following steps:

1. Visit and click the Sign Up Now link.

2. Log in using your Google account.

3. Fill out your website information.

4. Click on Continue and fill in your contact information.

5. Click on Continue. Here you’ll read and agree to the User Agreement. You’ll also notice that you’re opted in to anonymously share your Google Analytics data. According to Google, shared data will be used to improve the services we provide you and will help create more powerful features for you to choose from. There are two levels of sharing.

6. Finally, click on Create New Account. Congrats, you’re done!

7. Now it’s time to install the Google Analytic module, which installs just like any other normal Drupal module. Download the module, drop it into your sites/all/modules folder, go to /admin/build/modules, and turn it on.

8. To configure the module, point your browser to at the top of the page and you will be able to see a screen similar to the following screenshot:

9. Go back to your Google Analytics account and you should see a number next to your URL name that starts with UA-, as shown in the following screenshot:

10. Copy and paste your site’s UA number into your Drupal site. If you don’t see this, click the Analytics Settings link, located at the upper left corner.

11. Under User Specific Tracking Settings, make sure that User cannot control whether they are tracked or not option is selected. This makes sure that you’re tracking all your visitors and they can’t turn off the tracking.

12. Under Role specific tracking settings, you will have a few options. For most sites, you want to check everything except the authenticated user option, as shown in the following screenshot:

What is role specific tracking settings?

Role specific tracking settings is one of the best things about the Google Analytics module. One of the most common problems with Google Analytics is that it tracks everything that happens on your site – even your own activity. So, if you visit your site a lot (which you probably do) then you’ll skew your own Analytics. Telling Drupal to not track admin users will dynamically show or not show Google’s tracking code depending on if a user is the site admin. There are many uses for this. Say you don’t want to track any of your company’s users. Just give them a custom account type (staff) and deselect the checkbox in the Google Analytics module. Clean, easy, and works like a champ!

13. Except for advanced needs, the rest of the settings should be left as the defaults. Click on Save configuration. “The dishes are done, dude!”

Common mistake when configuring the Google Analytics module

Under Advanced settings, there is a field called Custom JavaScript Code. DO NOT put your Google code there. If you’ve put your Google account information at the top of the admin page then the module will write all the code automatically. The Custom JavaScript Code field is for special code snippets that are added to the tracking code. If you put the full there then you will track every user on your site twice. This is not cool for school.

Once you’ve correctly installed your tracking code, Google recommends waiting about 24 hours for data to start appearing in your account. Check back tomorrow and see some data, you should. After several months of data collection, your analytics should get very interesting to dig through. Until then, be patient - it is well worth the wait.

Thank You For Reading!

No one likes people who don’t share, especially Keanu Reeves and his gang of crazy dogs, giant flying cats, and magical monocle. So if you liked what you read, please share my post with any of our socially-labeled buttons, or we’ll sick the whole gang after you! Please subscribe to our RSS feed as well so you can receive daily fodder from our blog.