Sha256: 0e4db18b0b6cedd20eafb7c9173c689b17687c766f8181de722edd3a30be3ab6

Contents?: true

Size: 1.25 KB

Versions: 88

Compression:

Stored size: 1.25 KB

Contents

window.GOVUK = window.GOVUK || {}
window.GOVUK.analyticsGa4 = window.GOVUK.analyticsGa4 || {}

var initFunction = function () {
  window.removeEventListener('cookie-consent', window.GOVUK.analyticsGa4.init)
  var consentCookie = window.GOVUK.getConsentCookie()

  if (consentCookie && consentCookie.usage) {
    window.GOVUK.analyticsGa4.vars.internalDomains = []
    window.GOVUK.analyticsGa4.vars.internalDomains.push(window.GOVUK.analyticsGa4.core.trackFunctions.getHostname())
    window.GOVUK.analyticsGa4.core.trackFunctions.appendDomainsWithoutWWW(window.GOVUK.analyticsGa4.vars.internalDomains)
    window.GOVUK.analyticsGa4.core.load()

    var analyticsModules = window.GOVUK.analyticsGa4.analyticsModules
    for (var property in analyticsModules) {
      var module = analyticsModules[property]
      if (typeof module.init === 'function') {
        try {
          module.init()
        } catch (e) {
          // if there's a problem with the module, catch the error to allow other modules to start
          console.warn('Error starting analytics module ' + property + ': ' + e.message, window.location)
        }
      }
    }
  } else {
    window.addEventListener('cookie-consent', window.GOVUK.analyticsGa4.init)
  }
}

window.GOVUK.analyticsGa4.init = initFunction

Version data entries

88 entries across 88 versions & 1 rubygems

Version Path
govuk_publishing_components-51.1.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-51.0.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-50.0.1 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-50.0.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-49.1.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-49.0.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-48.0.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-47.0.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-46.4.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-46.3.1 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-46.3.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-46.2.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-46.1.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-46.0.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-45.10.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-45.9.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-45.8.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-45.7.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-45.6.1 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js
govuk_publishing_components-45.6.0 app/assets/javascripts/govuk_publishing_components/analytics-ga4/init-ga4.js