End of Year Promotion - 10% off Zend Training
When your site matures and traffic begins to grow you may want to collect demographic information about your audience. If you find that a big percentage your audience comes from a particular foreign country, you may consider translating your content into their native language to best serve them. If you find that certain articles have more hits or referrals than others, you may want to investigate the source of the referrals or keywords used so we can replicate that success in other articles.

Google Analytics is a powerful tool for collecting demographic information and display trends as it pertains to visitors of your content. The main dashboard displays Site usage factors such as # of Visits, Total Pageviews, Bounce Rate, Avg Time on Site and Pages Per Visit. Map Overlay shows in various shades of green which countries your site visitors came from. Traffic Sources Overview displays a pie chart with the respective proportions of visits from Referring Sites, Direct Traffic and Search Engines. Content Overview shows the amount of Pageviews each Page on your site had. The list of features goes on and on.

An important point to mention, from the breakdown of Traffic Sources you can infer the following:

  • Higher Referring Sites means word of mouth to your site is growing and patrons of your site have plugged you on another website.
  • Higher Direct Traffic could mean past visitors may have bookmarked your site and continue revisiting your sites through this bookmark. Another scenario may be that your site is so popular, people just type your domain name directly into the address bar of their browser.
  • Higher Search Engines means that your keywords have scored highly on search engine algorithms and deemed relevant to the keyword search term of a search engine user. With effective Search Engine Optimization (SEO) a site can move up in the rankings and have a better chance of being noticed by a potential visitor.

Before we can proceed with enabling Google Analytics we'll need to sign up at http://www.google.com/analytics/ to obtain a free tracking code for your domain. Once logged in add a new Analytics account by entering your Domain Name, Account Name, Country and Time Zone. After the account is ready you will be provided with Javascript code to append to your website html code. Since we'll be using the Google Analytics Module only the tracking # will be needed. Copy the tracking number string which typically appears in the following syntax: UA-xxxxxxxx-x.

Now let's download and configure the Google Analytics Module. You can either download it to your local PC with your web browser, then FTP it to /home/public_html/sites/all/modules or we can just download and extract it from the console.

user@getondrupal.com:/home/public_html/sites/all$ cd modules
user@getondrupal.com:/home/public_html/sites/all/modules$ sudo wget 
                     http://ftp.drupal.org/files/projects/google_analytics-6.x-2.2.tar.gz
user@getondrupal.com:/home/public_html/sites/all/modules$ 
                     sudo tar zxvf google_analytics-6.x-2.2.tar.gz

The contents of the archive will be extracting to:

/home/public_html/sites/all/modules/google_analytics

We'll need to be logged into Drupal with an administrator account to enable new modules. On the navigation menu select Administer.

Drupal Administrator Navigation

The Administer section is divided up into five major task categories; Content management, Site building, Site configuration, User management and reports. Within the Site building task category, we want to select Modules.

Drupal Site Building Modules

The Modules page will display several collapsible menus listing the available modules, version, description and whether or not they are currently enabled. Go ahead and enable the Google Analytics Module in the Statistics section. Scroll to the bottom of the page and hit the Save configuration button.

Drupal Google Analytics Module

Once enabled, the Google Analytics Module will add a new menu option to Site configuration category under Administer labeled Google Analytics. If we navigate into the settings, we can add our tracking code under Google Analytics account number

Drupal Google Analytics Settings

There are also a variety of settings to manage Google Analytics. It is recommended that you notify patrons to your site that your are gathering statistics on them via an Opt-in Agreement or a Privacy Policy. Once the Module and tracking code are in place, Google Analytics will begin tracking hits to your content immediately. The results may be delayed by a couple hours on the Google Analytics website.