{"version":3,"file":"init-google-analytics.bundle.mjs","sources":["../../../../src/digitalmarketplace/scripts/analytics/tag-manager.ts","../../../../../../node_modules/js-cookie/dist/js.cookie.mjs","../../../../src/digitalmarketplace/scripts/analytics/data-layer.types.ts","../../../../src/digitalmarketplace/scripts/cookies/manage.ts","../../../../src/digitalmarketplace/scripts/analytics/init-google-analytics.ts"],"sourcesContent":["const GOOGLE_TAG_MANAGER_ID = 'GTM-WCGFX3GW'\n\nconst googleTagManagerInit = (w: Window, d: Document, s: 'script', l: 'dataLayer', i: string) => {\n  w[l] = w[l] || []\n  w[l].push({\n    'gtm.start': new Date().getTime(),\n    event: 'gtm.js'\n  })\n  const f = d.getElementsByTagName(s)[0]\n  const j = d.createElement(s)\n  const dl = l != 'dataLayer' ? '&l=' + l : ''\n  j.async = true\n  j.src ='https://www.googletagmanager.com/gtm.js?id=' + i + dl;\n  (f.parentNode as ParentNode).insertBefore(j, f)\n}\n\nconst loadGoogleTagManager = () => googleTagManagerInit(window, document, 'script', 'dataLayer', GOOGLE_TAG_MANAGER_ID)\n\nexport { loadGoogleTagManager }\n","/*! js-cookie v3.0.5 | MIT */\n/* eslint-disable no-var */\nfunction assign (target) {\n  for (var i = 1; i < arguments.length; i++) {\n    var source = arguments[i];\n    for (var key in source) {\n      target[key] = source[key];\n    }\n  }\n  return target\n}\n/* eslint-enable no-var */\n\n/* eslint-disable no-var */\nvar defaultConverter = {\n  read: function (value) {\n    if (value[0] === '\"') {\n      value = value.slice(1, -1);\n    }\n    return value.replace(/(%[\\dA-F]{2})+/gi, decodeURIComponent)\n  },\n  write: function (value) {\n    return encodeURIComponent(value).replace(\n      /%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,\n      decodeURIComponent\n    )\n  }\n};\n/* eslint-enable no-var */\n\n/* eslint-disable no-var */\n\nfunction init (converter, defaultAttributes) {\n  function set (name, value, attributes) {\n    if (typeof document === 'undefined') {\n      return\n    }\n\n    attributes = assign({}, defaultAttributes, attributes);\n\n    if (typeof attributes.expires === 'number') {\n      attributes.expires = new Date(Date.now() + attributes.expires * 864e5);\n    }\n    if (attributes.expires) {\n      attributes.expires = attributes.expires.toUTCString();\n    }\n\n    name = encodeURIComponent(name)\n      .replace(/%(2[346B]|5E|60|7C)/g, decodeURIComponent)\n      .replace(/[()]/g, escape);\n\n    var stringifiedAttributes = '';\n    for (var attributeName in attributes) {\n      if (!attributes[attributeName]) {\n        continue\n      }\n\n      stringifiedAttributes += '; ' + attributeName;\n\n      if (attributes[attributeName] === true) {\n        continue\n      }\n\n      // Considers RFC 6265 section 5.2:\n      // ...\n      // 3.  If the remaining unparsed-attributes contains a %x3B (\";\")\n      //     character:\n      // Consume the characters of the unparsed-attributes up to,\n      // not including, the first %x3B (\";\") character.\n      // ...\n      stringifiedAttributes += '=' + attributes[attributeName].split(';')[0];\n    }\n\n    return (document.cookie =\n      name + '=' + converter.write(value, name) + stringifiedAttributes)\n  }\n\n  function get (name) {\n    if (typeof document === 'undefined' || (arguments.length && !name)) {\n      return\n    }\n\n    // To prevent the for loop in the first place assign an empty array\n    // in case there are no cookies at all.\n    var cookies = document.cookie ? document.cookie.split('; ') : [];\n    var jar = {};\n    for (var i = 0; i < cookies.length; i++) {\n      var parts = cookies[i].split('=');\n      var value = parts.slice(1).join('=');\n\n      try {\n        var found = decodeURIComponent(parts[0]);\n        jar[found] = converter.read(value, found);\n\n        if (name === found) {\n          break\n        }\n      } catch (e) {}\n    }\n\n    return name ? jar[name] : jar\n  }\n\n  return Object.create(\n    {\n      set,\n      get,\n      remove: function (name, attributes) {\n        set(\n          name,\n          '',\n          assign({}, attributes, {\n            expires: -1\n          })\n        );\n      },\n      withAttributes: function (attributes) {\n        return init(this.converter, assign({}, this.attributes, attributes))\n      },\n      withConverter: function (converter) {\n        return init(assign({}, this.converter, converter), this.attributes)\n      }\n    },\n    {\n      attributes: { value: Object.freeze(defaultAttributes) },\n      converter: { value: Object.freeze(converter) }\n    }\n  )\n}\n\nvar api = init(defaultConverter, { path: '/' });\n/* eslint-enable no-var */\n\nexport { api as default };\n","\nenum GrantType {\n  GRANTED = 'granted',\n  NOT_GRANTED = 'not granted'\n}\n\nexport { GrantType }","import Cookies from 'js-cookie'\nimport { CookiePreferences, CookieUpdateOption } from './manage.types'\nimport { updateDataLayer } from '../analytics/data-layer'\n\nconst cookieUpdateOptions: CookieUpdateOption[] = [\n  {\n    cookieName: 'usage',\n    cookiePrefixes: ['_ga', '_gi']\n  },\n  {\n    cookieName: 'glassbox',\n    cookiePrefixes: ['_cls']\n  }\n]\n\nconst DOMAINS = [\n  '.marketplace.team',\n  '.digitalmarketplace.service.gov.uk',\n  'www.applytosupply.digitalmarketplace.service.gov.uk'\n]\n\n// When not in production we want to delete cookies in localhost too\nconst getDomains = () => {\n  if (window.location.hostname === 'localhost') {\n    return DOMAINS.concat(['localhost'])\n  }\n\n  return DOMAINS\n}\n\nconst getCookiePreferences = (): CookiePreferences => {\n  const defaultCookieSettings = '{\"usage\":false,\"glassbox\":false}'\n\n  return JSON.parse(Cookies.get('cookie_preferences_dmp') ?? defaultCookieSettings)\n}\n\nconst setCookiePreferences = (usage: boolean) => {\n  const cookiePreferences: CookiePreferences = getCookiePreferences()\n\n  cookiePreferences.usage = usage\n  cookiePreferences.settings_viewed = true\n\n  Cookies.set('cookie_preferences_dmp', JSON.stringify(cookiePreferences), { expires: 365 })\n\n  updateDataLayer(cookiePreferences)\n  removeUnwantedCookies()\n}\n\nconst removeUnwantedCookies = (): void => {\n  const cookieList: string[] = Object.keys(Cookies.get())\n  const cookiesToRemove: string[] = ['digitalmarketplace_cookie_settings_viewed', 'digitalmarketplace_google_analytics_enabled', 'digitalmarketplace_cookie_options_v1', 'dm_cookies_policy']\n  const cookiePreferences: CookiePreferences = getCookiePreferences()\n  const cookiePrefixes: string[] = []\n\n  cookieUpdateOptions.forEach((cookieUpdateOption) => {\n    if (!cookiePreferences[cookieUpdateOption.cookieName]) cookiePrefixes.push(...cookieUpdateOption.cookiePrefixes)\n  })\n\n  for (let i = 0; i < cookieList.length; i++) {\n    const cookieName = cookieList[i]\n\n    if (cookiePrefixes.some((cookiePrefix) => cookieName.startsWith(cookiePrefix))) cookiesToRemove.push(cookieName)\n  }\n\n  getDomains().forEach((domain) => {\n    cookiesToRemove.forEach((cookieName) => { Cookies.remove(cookieName, { path: '/', domain: domain }) })\n  })\n}\n\nexport {\n  getCookiePreferences,\n  setCookiePreferences,\n  removeUnwantedCookies\n}","import { loadGoogleTagManager } from './tag-manager'\nimport { removeUnwantedCookies } from '../cookies/manage'\n\nconst initGoogleAnalytics = () => {\n  loadGoogleTagManager()\n\n  removeUnwantedCookies()\n}\n\nexport { initGoogleAnalytics }\n"],"names":["assign","target","i","arguments","length","source","key","defaultConverter","read","value","slice","replace","decodeURIComponent","write","encodeURIComponent","init","converter","defaultAttributes","set","name","attributes","document","expires","Date","now","toUTCString","escape","stringifiedAttributes","attributeName","split","cookie","get","cookies","jar","parts","join","found","e","Object","create","remove","withAttributes","withConverter","freeze","api","path","Cookies"],"mappings":"AAAA,MAAM,qBAAqB,GAAG,cAAc;AAE5C,MAAM,oBAAoB,GAAG,CAAC,CAAS,EAAE,CAAW,EAAE,CAAW,EAAE,CAAc,EAAE,CAAS,KAAI;IAC9F,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE;AACjB,IAAA,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AACR,QAAA,WAAW,EAAE,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE;AACjC,QAAA,KAAK,EAAE;AACR,KAAA,CAAC;IACF,MAAM,CAAC,GAAG,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACtC,MAAM,CAAC,GAAG,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC;AAC5B,IAAA,MAAM,EAAE,GAAkC,EAAE;AAC5C,IAAA,CAAC,CAAC,KAAK,GAAG,IAAI;IACd,CAAC,CAAC,GAA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