-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathapplication.js
More file actions
58 lines (49 loc) · 1.8 KB
/
application.js
File metadata and controls
58 lines (49 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import { initAll } from 'govuk-frontend'
import dfeAutocomplete from 'dfe-autocomplete'
import {
loadConsentStatus,
CONSENT_STATUS
} from '../javascript/utils/cookie-consent'
import {
installAnalyticsScript,
setDefaultConsent,
sendPageViewEvent,
attachExternalLinkTracker,
attachDetailsOpenTracker
} from '../javascript/utils/google-analytics'
import { CookieBanner } from '../../components/cookie_banner_component/cookie-banner'
import { CookiePage } from '../../components/cookie_consent_form_component/cookie-consent-form'
import { initFileValidation } from '../javascript/utils/file-validation'
const analyticsConsentStatus = loadConsentStatus()
setDefaultConsent(analyticsConsentStatus === CONSENT_STATUS.GRANTED)
if (document.body.dataset.googleAnalyticsEnabled === 'true') {
if (analyticsConsentStatus === CONSENT_STATUS.GRANTED) {
installAnalyticsScript(window)
}
// Initialise cookie banner
const banners = document.querySelectorAll('[data-module="cookie-banner"]')
banners.forEach(function (banner) {
new CookieBanner(banner).init({
showBanner: analyticsConsentStatus === CONSENT_STATUS.UNKNOWN
})
})
// Initialise cookie page
const $cookiesPage = document.querySelector(
'[data-module="app-cookies-page"]'
)
if ($cookiesPage) {
new CookiePage($cookiesPage).init({
allowAnalyticsCookies: analyticsConsentStatus === CONSENT_STATUS.GRANTED
})
}
// push events regardless of consent value - if consent has not been granted
// yet, GTM won't be loaded and no data is sent to Google analytics. Doing
// this now means that if consent is granted later on this page, the event
// will be sent
sendPageViewEvent()
attachExternalLinkTracker()
attachDetailsOpenTracker()
}
initAll()
initFileValidation()
window.dfeAutocomplete = dfeAutocomplete