This describes how to work with Google Analytics (GA)
Always discuss the reporting requirements with data solutions and google analytics teams before you implement any new dimensions.
Talk to the mobile apps team early, things can be a slightly different once you take their needs into account (eg: web pages vs app screens)
The main entry point for google pageview tracking is in
analytics/base.scala.html
We are careful about how many tracking events we push to the GA test so only send 5% of traffic to the test account. In your local environment we are sending 100% to make development easier.
We implement the standard async GA tracking
We then send through all the custom dimensions
to GA.
All of our custom dimensions
are hit scoped
(scopes are user
, session
or hit
)
apart from dimension15
(identityId) and dimension2
(ophanBrowserId) which is a user
scoped
We maintain documentation that describes all the custom dimensions
, events
and metrics
used within GA
The main entry point for Media (Video and Audio) tracking is
video/events.js
This is an example of the media event using the following custom dimensions
var fieldsObject = {
eventCategory: category,
eventAction: action,
eventLabel: canonicalUrl,
dimension19: mediaEvent.mediaId,
dimension20: playerName
};
// Increment the appropriate metric based on the event type
var metricId = metrics[mediaEvent.eventType];
if (metricId) {
fieldsObject[metricId] = 1;
}
and the following custom metrics
var events = {
'play': 'metric1',
'skip': 'metric2',
'watched25': 'metric3',
'watched50': 'metric4',
'watched75': 'metric5',
'end': 'metric6'
};
Incrementing metrics in this way is done to give a truer account of the actions that are happening on the video. Out of the box it would give a session level interaction, not a hit level.
The main entry point for click tracking is analytics/interaction-tracking.js
The click actions currently being tracked are:
- In-page clicks (opening nav) that don't cause page load
- Internal clicks (navigating to another internal page on gu.com)
- External clicks (going to another domain)
- Clicks on sponsors' logos (regardless of destination)
- Clicks on native ads
interaction-tracking.js is an abstraction over the top of clickstream.js that sends the events to both Omniture and Google.
TODO:
- When Omniture is removed:
- Re-implement delay when clicking external links which is currently handled by the omniture JS
- Re-implement the deletion of session storage which is tracked between pages
The comments event is a custom event defined in analytics/discussion
Most discussion events can be tracked with click events so the only GA custom event for discussion is for 'scroll'.
The custom category for tracking a user scrolling to the comments is element view with an action of onpage item and a label of scroll to comments.
Check chris's PR for implementation details
Main entry point for AMP analytics is amp/googleAnalytics.scala.html