LiveWhale integrates with Google Analytics or Google Tag Manager to allow you to easily track activity on your site and view browsing data from within LiveWhale. You can also add your own custom tracking.
If you are setting up a new LiveWhale site, you can track your site visitors by using Google Analytics 4. (If you are already tracking visitors with Google Analytics or Google Tag Manager in LiveWhale, skip ahead to the migration instructions.)
Note: This integration requires LiveWhale 2.5.0 or higher. If you haven’t yet upgraded and want to start tracking traffic to Google Analytics 4, you must either follow the instructions for adding GA4 to an existing Google Tag Manager integration, or manually add the GA4 tracking HTML code to a site-wide include in your theme.
To set up a new Google Analytics 4 integration:
Create a GA4 property for your site, if you don’t already have one.
Add a data stream (Admin > Property > Data Streams > Add stream) of type “Web.”
Open the stream details and find “Measurement ID” — it’s formatted as G-
followed by a series of letters and numbers (G-##########). Copy this and paste it into your /livewhale/core/config.php file.
1 | $GLOBALS['LIVEWHALE_CONFIG']['HOSTS']=[ |
In order to track calendar and event views (which load via AJAX), make sure you enable “Enhanced measurement” for page views in your GA4 settings. Specifically the setting to track “Page changes based on browser history events” will make sure that all of your calendar and event views are correctly tracked.
Copy this and paste it into your /livewhale/core/config.php file:
1 | $GLOBALS['LIVEWHALE_CONFIG']['HOSTS']=[ |
If you are already using Google Tag Manager (GTM-####### in your LiveWhale config and page source), you may not need to alter any LiveWhale settings at all. Instead, you can have your current GTM integration start collecting GA4 data as well.
If you are using Google Universal Analytics (UA-#######-# in your LiveWhale config and page source), you’ll want to either replace it with Google Tag Manager or add GA4 tracking code so you can start collecting GA4 data.
Note: LiveWhale will continue to support embedding Universal Analytics code until the Google end-of-life on July 1, 2023 using this syntax in /livewhale/core/config.php:
1 | 'GA_SITE_IDS' => [ |
If you are currently using Universal Analytics, we recommend migrating to Google Tag Manager or adding GA4 tracking using the above steps as soon as possible so you can start populating data into your GA4 property. You can track data to both at once by adding both trackers to your config.php file and giving them different names (for instance, “main” and “legacy”):
1 | 'GA_SITE_IDS' => [ |
You may selectively exclude certain pages or directories from Google Analytics by specifying them in a config array. To do this:
$_LW->CONFIG['GA_EXCLUDE']
array (or [$_LW->CONFIG['GTM_EXCLUDE']
for Google Tag Manager), containing the paths to the files you wish to exclude. This will remove the Google Analytics tracker from the specified pages.`$_LW->CONFIG['GA_EXCLUDE'] = ['/admissions-test/','/faculty/committees/'];
or $_LW->CONFIG['GTM_EXCLUDE'] = ['/admissions-test/','/faculty/committees/'];
LiveWhale can collect visitor analytics on your pages, news stories, events, etc. and not only share that with your site editors (visible on the details tab or when editing page details) but you can also then use it in widgets to create ranked lists, such as most viewed stories.
To set this up, you’ll need access to your primary Google Analytics account/profile (the one that should already be listed in LiveWhale for insertion of the tracking code) and the ability to SFTP to your LiveWhale server to edit the main LiveWhale config.php.
Your GA Client ID will look like “17435168185-456wef65sd3518w9ef4sdf651we8fssdf98w4.apps.googleusercontent.com”. The GA Email will also be generated in the above steps, and you’ll see it looks like “livewhale-analytics-service-account@livewhale-analytics.iam.gserviceaccount.com”.
Now switch to Google Analytics and add the service account as a new user able to access your profile data.
You’ll also need to know your Google Analytics Profile ID for the final step. To find it, select the site you want to monitor from within Google Analytics. In the url you will have something similar to this:
https://www.google.com/analytics/web/#report/visitors-overview/a5559982w55599512p12345678
The digits that follow the “p” at the end is your Profile ID.
SFTP to your LiveWhale server to complete the configuration.
HOST
:1 | $GLOBALS['LIVEWHALE_CONFIG']['HOSTS']=[ |
Note: If you are updating from an earlier LiveWhale analytics configuration and have GA_PASSWORD
set, you may safely remove that definition/line.
Note: Statistical results may take up to 24 hours to display.
Adding custom tracking in Livewhale is generally easy—simply add whatever JS you need to your theme so it loads on every page and you’re all set.
Keep in mind, though: visitors can navigate to different views/events in LiveWhale Calendar without refreshing the page. This can cause confusion for some trackers. Therefore, in LiveWhale 1.7.1+ you can add custom tracking code to make sure you capture every calendar and event view.
If you’re using Google Analytics, no extra work is required. LiveWhale will detect the Google Analytics JavaScript object (window.ga
or window._gaq
) and push individual calendar/event views to it.
If you’re not using or want to bypass Google Analytics, add the following to your theme’s custom calendar script and LiveWhale will detect the livewhale.custom_tracking
function and use that instead of any default Google Analytics handling.
1 | (function($, LW) { |