[Drupal] How to setup Google Analytics for Drupal website?

| | 2 min read

Google Analytics is a service offered by Google that generates detailed statistics about a website's traffic and traffic sources and measures conversions and sales. Sign up for a Google Analytics account and can get your “Tracking ID” under the "Property Setting" section, it should look something like, “UA-xxxxxxxx-x”.

Google Analytics module allows you to enter your Google Analytics account number into the modules settings page. It will then automatically add the required Javascript to every page generated by Drupal.

  • Install Google Analytics module and configure from the path:
  • Home » Administration » Configuration » System
  • Add Google Analytics account number.
  • You can go ahead and save your settings. For most users, Google Analytics module's default setting should get them started. For advanced users, this module offers some advanced features. You can also configure the following features.
  • Domains - This setting lets you select what you are tracking, like single or multiple domains.
  • Pages - This setting lets you select which pages you intend to track. You can provide a list of pages and paths that you want or don’t want to track.
  • Roles - This setting lets you choose what roles we want to track or not track.
  • Users - This is an interesting setting for those sites that have strict privacy policies. This option allows the site users to opt out of tracking depending on the option selected.To make this work, you will have to change permissions under Google Analytics, and allow users to Opt-in or out of tracking. There will be a checkbox in user profile that would allow users to opt-out of tracking.
  • In order to track file types, add in the file extensions (without the dot) separated by pipes "|".
  • Messages - This helps you track the messages shown to the users.
  • Search and Advertising - This lets you track your internal site searches and AdSense advertisements in your Google Analytics. Some additional settings might be required.
  • Privacy - This setting lets you anonymize visitors IP addresses, and also respect do not track policy.