Google Analytics Referrer
Example output of the moduleLightweight, scalable, no-nonsense, enable-and-forget collector of referrers for all pages on your site, drawing on data collected by Google Analytics. Hardly any load on your server, no negative impact on the user. Highly customizable. Suitable even for large and high-traffic sites.
Installing is a breeze -- authenticate to Google Analytics (see instructions below) and review the default settings (which should be fine in most cases). And make sure your cron is running. You can check the stats retrieval progress at /admin/config/system/google_analytics_referrer/details!
Features
- Virtually no burden on your server; the heavy work is done by Google Analytics
- Provides a block listing referrers for the current page
- Provides an input filter to list referrers for the current or any other page, or even for the whole website
- Works for any Drupal path (nodes, views, user profiles, even admin pages ... anything not excluded from Google Analytics tracking).
- Themeable (classes provided)
- 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
- Takes into account system paths, aliases, even redirects (if using the Redirect module); e.g. if you your "node/3" has alias "projects" but previously it was on path "plans", this module will create one coherent list of referrers for the page, taking all the variants into consideration
- 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 an update to the list of referrers for each of these pages once a day!)
Installation
- You will obviously need Google Analytics Referrer. Download and enable just like any other Drupal module. There is no dependency.
- You will also need to have your site tracked by Google Analytics. You may use the Drupal module Google Analytics or other method.
- Authenticate a Google Analytics profile for your website (there will be a Status page warning until you do that) by navigating to
Configuration -> System -> Google Analytics Referrer -> GA authentication
. You will need Client ID and Client Secret. To get them, visit the Google Developers Console, create a new project, enable "Analytics API", under "APIs & auth -> Credentials" create an Oauth 2.0 Client ID with application type "Web application" (configure consent screen as you wish), configure Client ID settings: Redirect URIs (https://example.com/admin/config/system/google\_analytics\_referrer/authentication) and JavaScript origins (https://example.com), copy the Client ID and Client Secret to the configuration form of the module in /admin/config/system/google_analytics_referrer/authentication - You can configure this module at
Configuration -> System -> Google Analytics Referrer
(but defaults will work fine for a start) - You can check the stats retrieval progress and other relevant information at
Configuration -> System -> Google Analytics Referrer -> Dashboard
- Set access permissions for Google Analytics Referrer at
Configuration -> System -> Google Analytics Referrer -> Permissions
- Make sure your usual Drupal cron is functioning well (for testing, you can also run it manually directly from the provided Dashboard page)
- Set access permissions for Google Analytics Referrer at
Configuration -> Google Analytics Referrer -> Permissions
Usage
- Go to
Configuration -> Content authoring -> Text formats
and enable the Google Analytics Referrer filter for the input type you will be using - Either enable block Google Analytics Referrer, or place [
gar
] in any page or custom block. If you need to show referrers for a page other than the current one, use: [gar|path/without/wrapping/slashes
] (e.g. [gar|node/1
]) - To show all referrers of a website, use the following special tag: [
gar|all
] - If you wish to load the referrers using PHP, e.g. if you are integrating it in your template, use the output of function
google_analytics_referrer_display(($path = '', $number = '', $removevague = '', $removeprecise = '')
. Again, to show referrer for the actual page, useecho google_analytics_referrer_display();
, for some other page use e.g.echo google_analytics_referrer_display('node/145');
, and to show the total count for the whole site useecho google_analytics_referrer_display('all');
. - In [
gar
] token or if calling the functiongoogle_analytics_referrer_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).
Troubleshooting
In case of troubles with the OAuth2 authentication it helps to reset its variables and try again. You can use a settings reset link at /admin/config/system/google_analytics_referrer/dashboard.
Spelling note
Yes, I know the spelling of "referer" in the project name is wrong! The field in the HTTP header has the correct number of Rs indeed (see this). I chose the 4R version just because the Google Analytics calls referers referrers; the relevant dimension is called "ga:referrer". Sorry :-)
Roadmap
A good idea, anybody?
More information
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.
- Kinpedia
- Brilliant Gallery
- Hypergraph
- TrailScout
- Google Analytics Counter
- PagePeeker Screenshots
- Drupal Performance Mantra: Crawl, Boost, Expire
- Link Replace Filter
- Puzzler
- Recacher
- reSmush.it image style optimizer
- Gatsby & Drupal: In Quest of an Ideal Coupling
ENGLISH ARTICLEOCTOBER 20, 2018 AT 01:46:40 UTC