Google Analytics Counter

Lightweight, scalable, no-nonsense, enable-and-forget page view counter drawing on data collected by Google Analytics. Hardly any load on your server, no impact on the user. Integration with Views for nodes. Highly customizable. Suitable even for large and high-traffic sites.

New: Drupal 7 branch 7.x-2.x is now completely independent from Google Analytics Reports / its Google Analytics API submodule, and its dependency Chart. Google Analytics quota limit is no longer an issue. Much improved performance, more elegant and cleaner code (Drupal coding standards respected). Upgrading from 7.x-1.x is a breeze -- just make sure to run /update.php, re-authenticate to Google Analytics (see instructions below) and review the default settings (which should be fine for most and the old ones have not changed). And make sure your cron is running. You can check the stats retrieval progress at /admin/config/system/google_analytics_counter/details!

#D8CX: I pledge that Google Analytics Counter will have a full Drupal 8 release on the day that Drupal 8 is released.

Features (based on Drupal 7 version, branch 7.x-2.x)

  • Virtually no burden on your server; the heavy work is done by Google Analytics
  • Provides a block showing the page views for the current page
  • Provides an input filter for current or any other page, and also one counter for the whole website
  • Works for any Drupal path (nodes, views, user profiles, even admin pages ... anything not excluded from Google Analytics tracking). Any path that you find is tracked in Google Analytics can be counted using this module. The module http://drupal.org/project/google_analytics is pretty sophisticated and counts even outgoing links, file downloads, etc.
  • Themeable (class="google-analytics-counter")
  • Google Analytics data retrieved during cron runs (user experience not impacted); cron periodicity and batch sizes can be set on the configuration page
  • Using extremely little of the current Google Analytics API request quotas; on the configuration page you can set the quota and caching
  • Saves the values in Drupal's core's own table (node_counter), allowing you to show, sort and filter page access counts for all your nodes using Views; this for example allows you to show nodes sorted by their popularity
  • Each count per page includes count(s) of its alias(es), if any: e.g. if you your node/3 has path "projects" this module will provide the total of accesses to both variants
  • Each count per page also includes count(s) of its redirect(s), if any: e.g. if a page alias is now "projects" but in the past it used to be "ideas" and even before it was "assignments", the module will detect that and the sum of counts will also include those old path versions (of course this requires the Redirect module)
  • Provides a dashboard page with meta statistics relevant to the given Google Analytics profile and this module (totals, retrieval status, etc.)
  • The most important configuration tasks you need to do show as alerts on the Status page
  • Fully compatible with multilingual paths (i18n)
  • Consistently performant even on very large sites and extremely scalable (e.g. on a site with 100,000,000 pages you can still provide a counter update for each of these pages once a day!)

Installation (D7 version, branch 7.x-2.x)

  • You will obviously need to have Google Analytics and Google Analytics Counter, so there is just one single dependency, OAuth, needed for selecting of your Google Analytics profile. Download and enable them just like any other modules. Drupal core module Statistics will be automatically enabled as well.
  • Authenticate a Google Analytics profile for your website at by navigating to Configuration -> System -> Google Analytics Counter -> GA authentication.
  • You can configure this module at Configuration -> System -> Google Analytics Counter (but defaults will work fine for a start)
  • You can check the stats retrieval progress and other relevant information at Configuration -> System -> Google Analytics Counter -> Dashboard
  • Set access permissions for Google Analytics Counter at Configuration -> System -> Google Analytics Counter -> Permissions
  • Make sure your usual Drupal cron is functioning well (for testing, you can also run it manually directly from the provided Dashboard page)

Installation (D6 version or D7 branch 7.x-1.x)

  • Apart from Google Analytics and Google Analytics Counter, download Google Analytics Reports and modules it depends on: OAuth, Chart, and for D6 also Autoload.
  • Enable modules Google Analytics Counter and Google Analytics API (which is a submodule of Google Analytics Reports and depends on OAuth, Chart and in D6 also on Autoload). You do NOT need to enable modules Google Analytics Reports and Chart, although they have to be present!
  • Authenticate a Google Analytics account used on your website on the configuration page for Google Analytics Reports (there will be a Status page warning until you do that); note that to get the full quota of 10,000 requests per day you must register your Analytics API
  • You can configure this module at Configuration -> Google Analytics Counter (7.x-1.x) / Site configuration -> Google Analytics Counter (D6) (defaults will work fine for a start)
  • Set access permissions for Google Analytics Counter at Configuration -> Google Analytics Counter -> Permissions (7.x-1.x) / Site configuration -> Google Analytics Counter -> Permissions (D6)

Usage

  • Go to Configuration -> Content authoring -> Text formats (D7) / Site configuration -> Input formats (D6) and enable the Google Analytics Counter filter for the input type you will be using
  • Either enable block Google Analytics Counter, or place [gac] in any page or custom block. If you need to show page views counter for a page other than the current one, use: [gac|path/without/wrapping/slashes] (e.g. [gac|node/1])
  • To show all page views of a website, use the following special tag: [gac|all]
  • To use the counts in Views we make use of the Drupal core module 'Statistics' (enabled as a dependency; its own counting at should of course be disabled and any old values will be overwritten) and set its permissions the way you wish at People -> Permissions (D7) / User management -> Permissions (D6), and in your Views (of nodes!), show/sort/filter by variable 'Content/Node statistics: Total views'
  • If you wish to load the counter using PHP, e.g. if you are integrating it in your template, use the output of function google_analytics_counter_display($path = ''). Again, to show counter for the actual page, use echo google_analytics_counter_display();, for some other page use e.g. echo google_analytics_counter_display('node/145');, and to show the total count for the whole site use echo google_analytics_counter_display('all');.
  • In [gac] token or if calling the function google_analytics_counter_get_sum_per_path() directly, you may specify a node in any way -- either by its node/nid path, or by its alias my/alias or even with its language prefix nl/node/nid or nl/my/alias. Even old aliases are counted in (requires the Redirect module)! All these are summed together when retrieving pageviews from Google Analytics (it's always the same node). However, this is not true about non-node paths -- counts for e.g. nl/custom/path and custom/path are always counted separately because they may be completely different pages (it would be rather difficult to tell).

Roadmap

  • A good idea, anybody?

Detail installation and configuration instructions, demonstration and other information about this module are at vacilando.org/gac.

All comments and patches providing or leading to improvements are welcome in the issue queue. Accepting able co-maintainers with demonstrable vision for this module.

This module is developed and maintained by Tomáš Fülöpp / Vacilando. Any and all donations are welcome via GitTip. The maintainer is available for paid customizations of any Vacilando module, development of new modules, or urgent troubleshooting / patch reviewing.

Project page and download.

Project Information

Downloads