-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1757 from alphagov/change-analytics-calls
Change analytics calls
- Loading branch information
Showing
3 changed files
with
52 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
app/assets/javascripts/govuk_publishing_components/analytics/init.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
50 changes: 0 additions & 50 deletions
50
app/assets/javascripts/govuk_publishing_components/analytics/init.js.erb
This file was deleted.
Oops, something went wrong.