Google Analytics

LiveWhale integrates with Google Analytics 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.

Enabling Google Analytics Tracking

LiveWhale can automatically insert the Google Analytics tracking code into your LiveWhale sites. (Note: Google Tag Manager is also supported natively in LiveWhale 1.6.1+)

Step 1: Obtain your Google Analytics Profile ID

To enable tracking, you’ll need your analytics profile id from Google (e.g. UA-#######-#) and the ability to SFTP to your LiveWhale server.

Step 2: Add your Profile ID to LiveWhale

  • SFTP to your server and open your master configuration file, /livewhale/core/config.php
  • In the host configuration, add or update the GA_SITE_IDS variable, this is typically listed after the FTP settings. Save your file when you are done (see code snippet below)
  • Note: If you are upgrading to universal analytics from non-universal analytics, you may need to change your existing GA_SITE_ID setting to GA_SITE_IDS.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$GLOBALS['LIVEWHALE_CONFIG']['HOSTS']=array(
'%HOSTNAME%'=>array(
'HTTP_HOST'=>'',
'DATABASE_HOST'=>'',
'DATABASE_USER'=>'',
'FTP_MODE'=>'',
...,
'GA_SITE_IDS' => array(
'main'=>array(
'tracker'=>'UA-#######-#'
)
),
...
)
);

Including Multiple Trackers
In this example, the one and only tracker has been called “main”, but you may give it any name you wish. If you want to insert multiple trackers, simply include multiple trackers in this array:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$GLOBALS['LIVEWHALE_CONFIG']['HOSTS']=array(
'%HOSTNAME%'=>array(
'HTTP_HOST'=>'',
'DATABASE_HOST'=>'',
'DATABASE_USER'=>'',
'FTP_MODE'=>'',
...,
'GA_SITE_IDS' => array(
'main'=>array(
'tracker'=>'UA-#######-#'
),
'secondary'=>array(
'tracker'=>'UA-#######-#'
)
),
...
)
);

Using Google Tag Manager
When setting up Google Tag Manager, make sure to track page views using GTM and use the following in place of the regular Google Analytics code above. Otherwise you may accidentally double-track page views:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$GLOBALS['LIVEWHALE_CONFIG']['HOSTS']=array(
'%HOSTNAME%'=>array(
'HTTP_HOST'=>'',
'DATABASE_HOST'=>'',
'DATABASE_USER'=>'',
'FTP_MODE'=>'',
...,
'GA_SITE_IDS' => array(),
'GTM' => array(
'id'=>'GTM-#######'
),
...
)
);

Step 3: Include any optional Google Analytics variables

You may also add Google Analytics variables that you’d like to include in the script’s configuration. For example, you can use these variables to add event tracking, merge data across sub-domains or domains, or add additional profiles to simultaneously track.

To add custom variables, add them along side the tracker you are enabling them for:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
$GLOBALS['LIVEWHALE_CONFIG']['HOSTS']=array(
'%HOSTNAME%'=>array(
'HTTP_HOST'=>'',
'DATABASE_HOST'=>'',
'DATABASE_USER'=>'',
'FTP_MODE'=>'',
...,
'GA_SITE_IDS' => array(
'main'=>array(
'tracker'=>'UA-#######-#',
'vars'=>array('variableName1'=>'value1', 'variableName2'=>'value2')
),
'secondary'=>array(
'tracker'=>'UA-#######-#'
)
),
...
)
);

Note: If you are upgrading to universal analytics from non-universal analytics, these variables correspond to what was previously the GA_VARS setting. You may remove GA_VARS after moving any previously tracked variables here.

Step 4: Verify your Change

Adding your Google Analytics tracking id above is all that LiveWhale needs to insert the code. Visit any front-end page for that host and view-source to confirm that the tracking code is present or has been updated. (It is typically immediately before the closing head tag.)

Additional Tips

Excluding Directories or Pages from Google Analytics`

You may selectively exclude certain pages or directories from Google Analytics by specifying them in a config array. To do this:

  • Open the public client config, /livewhale/client/public.config.php, using an FTP client or via the command line
  • Define a $_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'] = array('/admissions-test/','/faculty/committees/');
or $_LW->CONFIG['GTM_EXCLUDE'] = array('/admissions-test/','/faculty/committees/');

Viewing Google Analytics Data in LiveWhale

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.

Step 1: Create a Google Developers Project

  1. Log into the Google Developers console (https://console.developers.google.com/).
  2. If you don’t have a project yet, click: Create project
  3. Name the project LiveWhale Analytics. (You can use another name of your preference.)
  4. Give the project the ID such as livewhale-analytics. (Again, or anything that works for you.)
  5. Wait for project to be created.
  6. Once you have a project, click: Enable APIs and Services
  7. Find and enable the “Analytics API”
  8. Go back to the console and click: Credentials
  9. Click: Create Credentials > OAuth client ID, and choose type Other. Name your Client ID “LiveWhale Analytics Client ID” or whatever you like.
  10. Then, click: Create Credentials > Service account key, and choose P12 as the key type. Call it “LiveWhale Analytics Service Account” or whatever you like. Creating this will trigger a download of a file ending in “.p12”; save it to your desktop for later.
  11. While here, also get the Email address listed under Service Account.
    Google Analytics Service Account
  12. After it’s created, scroll down in your Credentials screen to find the Client ID.
    Google Analytics Client ID

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”.

Step 2: Give the Project Access to your Data

Now switch to Google Analytics and add the service account as a new user able to access your profile data.

  1. Log into Google Analytics (www.google.com/analytics).
  2. Click Admin
  3. Select the account you specified for your website.
  4. Click User Management
  5. Add new user with the email address you obtained above with permission to Read & Analyze.

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.

Step 3: ​Add the configuration to LiveWhale

SFTP to your LiveWhale server to complete the configuration.

  1. Login to your server and locate your back-end LiveWhale folder.
  2. Upload the .p12 file you collected above to /livewhale/integrations/google-analytics. (Before LiveWhale 1.7, instead you’d upload .p12 file to your livewhale/data directory, and if necessary, change the permissions on it to match everything else in the data directory).
  3. Open your main livewhale/core/config.php file and add/change the following values in your matching site HOST:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$GLOBALS['LIVEWHALE_CONFIG']['HOSTS']=array(
'%HOSTNAME%'=>array(
'HTTP_HOST'=>'',
'DATABASE_HOST'=>'',
'DATABASE_USER'=>'',
'FTP_MODE'=>'',
...,
'GA_EMAIL'=>'value', // set this to the email address obtained above
'GA_CLIENT_ID'=>'value', // set this to the client ID obtained above
'GA_KEY_FILE'=>'filename.p12', // set this to the name of the file you uploaded to /livewhale/integrations/google-analytics
'GA_PROFILE_ID'=>'value', // set this to the profile ID for your web site, you can obtain this from the url when viewing a profile in Google Analytics
...
)
);

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.

Custom Analytics Tracking

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
2
3
4
5
6
7
(function($, LW) {

livewhale.custom_tracking = function(pageview) {
console.log('Replace this line with custom tracking for the page ' + pageview);
}

}(livewhale.jQuery, livewhale));