-
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 #2915 from alphagov/ga4-consent
Integrate GA4 analytics code with cookie consent mechanism
- Loading branch information
Showing
11 changed files
with
321 additions
and
97 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
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
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
26 changes: 26 additions & 0 deletions
26
app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.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,26 @@ | ||
window.GOVUK = window.GOVUK || {} | ||
window.GOVUK.analyticsGA4 = window.GOVUK.analyticsGA4 || {} | ||
|
||
var initFunction = function () { | ||
// to be added: digital identity consent mechanism | ||
|
||
var consentCookie = window.GOVUK.getConsentCookie() | ||
|
||
if (consentCookie && consentCookie.usage) { | ||
var analyticsModules = window.GOVUK.analyticsGA4.analyticsModules | ||
for (var property in analyticsModules) { | ||
var module = analyticsModules[property] | ||
if (typeof module.init === 'function') { | ||
module.init() | ||
} | ||
} | ||
// to be added: attach JS from Google to the DOM and execute | ||
// to be added: cross domain tracking code | ||
} else { | ||
window.addEventListener('cookie-consent', function () { | ||
window.GOVUK.analyticsGA4.init() | ||
}) | ||
} | ||
} | ||
|
||
window.GOVUK.analyticsGA4.init = initFunction |
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
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
Oops, something went wrong.