-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle GA cookies when usage cookies are denied (#1755)
Handle GA cookies when usage cookies are denied
- Loading branch information
Showing
3 changed files
with
58 additions
and
21 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,34 @@ | ||
(function() { | ||
"use strict"; | ||
|
||
// Load Google Analytics libraries | ||
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; | ||
|
||
var universalId = '<%= Rails.application.config.ga_universal_id %>'; | ||
|
||
// Configure profiles, setup custom vars, track initial pageview | ||
var analytics = new GOVUK.StaticAnalytics({ | ||
universalId: universalId, | ||
cookieDomain: cookieDomain, | ||
allowLinker: true, | ||
// This is served by Fastly in production, and returns an empty 200 response | ||
govukTrackerUrl: '<%= asset_path "/static/a" %>' | ||
}); | ||
|
||
// Make interface public for virtual pageviews and events | ||
GOVUK.analytics = analytics; | ||
var consentCookie = window.GOVUK.getConsentCookie(); | ||
|
||
// Disable analytics by default | ||
// This will be reversed below, if the consent cookie says usage cookies are allowed | ||
window['ga-disable-UA-26179049-1'] = true; | ||
|
||
if (!consentCookie || consentCookie["usage"]) { | ||
window['ga-disable-UA-26179049-1'] = false; | ||
|
||
// Load Google Analytics libraries | ||
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; | ||
|
||
var universalId = '<%= Rails.application.config.ga_universal_id %>'; | ||
|
||
// Configure profiles, setup custom vars, track initial pageview | ||
var analytics = new GOVUK.StaticAnalytics({ | ||
universalId: universalId, | ||
cookieDomain: cookieDomain, | ||
allowLinker: true, | ||
// This is served by Fastly in production, and returns an empty 200 response | ||
govukTrackerUrl: '<%= asset_path "/static/a" %>' | ||
}); | ||
|
||
// Make interface public for virtual pageviews and events | ||
GOVUK.analytics = analytics; | ||
} | ||
})(); |
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
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