Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
In this tutorial I will outline how I managed to set up Google Analytics Reports with the Aegir hostmaster system (i.e. give each site an extra tab with Google Analytics summary reports).
Requirements:
- Aegir 3.x hostmaster with the following additional modules:
- Google Analytics account with a distinct property ID configured for each Aegir site.
- You need to configure a web application for the Google Analytics API (see instructions for Google Analytics Reports).
Steps:
- Install the required modules on Aegir hostmaster site
- For each site, click the tab "variables" and set the variable
google_analytics_reports_api_profile_id
to the profile ID provided by the Analytics API (note that this is not the same as the property ID!) - Edit the view called
Google Analytics Reports Summary (Google Analytics)
- Change the path to
node/%/google-analytics-reports/summary
- Click "menu" and change to "menu tab" and change menu to "navigation".
- Add a new contextual filter for
Google Analytics: Profile ID
- WHEN THE FILTER VALUE IS NOT IN THE URL: Display "Access Denied"
- WHEN THE FILTER VALUE IS IN THE URL OR A DEFAULT IS PROVIDED: Specify the following validation with PHP code:
$vars = hosting_variables_get_site_variables($argument); $handler->argument = isset($vars['google_analytics_reports_api_profile_id']) ? $vars['google_analytics_reports_api_profile_id'] : NULL; return isset($handler->argument);
That's it, you should now have an extra tab for each site with Google Analytics summaries!
Additional hint: if you want the correct urls for the "top pages" view, just add the "hostname" field and then for "page title" change the link in the rewrite rule to http://[hostname][pagePath]
.
Attachment | Size |
---|---|
analytics.png | 28.61 KB |