Skip to content

Commit

Permalink
Merge pull request #1757 from alphagov/change-analytics-calls
Browse files Browse the repository at this point in the history
Change analytics calls
  • Loading branch information
andysellick authored Oct 28, 2020
2 parents b67b6ab + 9070839 commit c88b54e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 50 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
useful summary for people upgrading their application, not a replication
of the commit log.

## Unreleased

* Change analytics calls ([PR #1757](https://github.com/alphagov/govuk_publishing_components/pull/1757))

## 23.1.0

* Add custom margin support for print link ([PR #1753](https://github.com/alphagov/govuk_publishing_components/pull/1753))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
var analyticsInit = function (gaProperty, gaPropertyCrossDomain, linkedDomains) {
'use strict'

var consentCookie = window.GOVUK.getConsentCookie()

var dummyAnalytics = {
addLinkedTrackerDomain: function () {},
setDimension: function () {},
setOptionsForNextPageView: function () {},
trackEvent: function () {},
trackPageview: function () {},
trackShare: function () {}
}

// Disable analytics by default
// This will be reversed below, if the consent cookie says usage cookies are allowed
var disabler = 'ga-disable-' + gaProperty
window[disabler] = true

if (consentCookie && consentCookie.usage) {
window[disabler] = false

// Load Google Analytics libraries
window.GOVUK.StaticAnalytics.load()

// Use document.domain in dev, preview and staging so that tracking works
// Otherwise explicitly set the domain as www.gov.uk (and not gov.uk).
var cookieDomain = (document.domain === 'www.gov.uk') ? '.www.gov.uk' : document.domain

// Configure profiles, setup custom vars, track initial pageview
var analytics = new window.GOVUK.StaticAnalytics({
universalId: gaProperty,
cookieDomain: cookieDomain,
allowLinker: true
})

// Make interface public for virtual pageviews and events
window.GOVUK.analytics = analytics

if (linkedDomains && linkedDomains.length > 0) {
window.GOVUK.analytics.addLinkedTrackerDomain(gaPropertyCrossDomain, 'govuk', linkedDomains)
}
} else {
window.GOVUK.analytics = dummyAnalytics
}
}

window.GOVUK.analyticsInit = analyticsInit

This file was deleted.

0 comments on commit c88b54e

Please sign in to comment.