mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-09 10:54:11 -04:00
Wrap analytics code in GOVUK interface
Wraps our analytics code in a stripped down version of GOVUK.Analytics to allow us to plug in the GOVUK code for consent.
This commit is contained in:
39
app/assets/javascripts/analytics/init.js
Normal file
39
app/assets/javascripts/analytics/init.js
Normal file
@@ -0,0 +1,39 @@
|
||||
(function (window) {
|
||||
"use strict";
|
||||
|
||||
window.GOVUK = window.GOVUK || {};
|
||||
|
||||
const trackingId = 'UA-26179049-1';
|
||||
|
||||
// Disable analytics by default
|
||||
window[`ga-disable-${trackingId}`] = true;
|
||||
|
||||
const initAnalytics = function () {
|
||||
|
||||
// guard against being called more than once
|
||||
if (!('analytics' in window.GOVUK)) {
|
||||
|
||||
window[`ga-disable-${trackingId}`] = false;
|
||||
|
||||
// Load Google Analytics libraries
|
||||
window.GOVUK.Analytics.load();
|
||||
|
||||
// Configure profiles and make interface public
|
||||
// for custom dimensions, virtual pageviews and events
|
||||
window.GOVUK.analytics = new GOVUK.Analytics({
|
||||
trackingId: trackingId,
|
||||
cookieDomain: 'auto',
|
||||
anonymizeIp: true,
|
||||
displayFeaturesTask: null,
|
||||
transport: 'beacon'
|
||||
});
|
||||
|
||||
// Track initial pageview
|
||||
window.GOVUK.analytics.trackPageview();
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
window.GOVUK.initAnalytics = initAnalytics;
|
||||
})(window);
|
||||
Reference in New Issue
Block a user