{
  "version": 3,
  "sources": ["/cdn/shop/t/426/assets/url-cookies-utils.js?country=CH"],
  "sourcesContent": ["let currentUrlState = sanitizeUrl(window.location.href);\r\n\r\n/**\r\n * Sets the values of specified URL parameters as cookies.\r\n * If a cookie already exists with a different value, it will be updated with the new value.\r\n *\r\n * @param {Array<string>} urlParamsCaptureList - An array of URL parameter names to capture and set as cookies.\r\n * @param {number} expiration  - The number of days until the cookies expire (default:30).\r\n */\r\nfunction setURLParamsAsCookies(urlParamsCaptureList, expiration = 30) {\r\n\tconst urlParams = new URLSearchParams(currentUrlState.split('?')[1] || '');\r\n\tfor (const [key, value] of urlParams.entries()) {\r\n\t\tif (urlParamsCaptureList.includes(key)) {\r\n\t\t\tconst existingCookieValue = utilFetchCookieValue(key);\r\n\t\t\tif (value && (!existingCookieValue || existingCookieValue !== value)) {\r\n\t\t\t\tdocument.cookie = `${key}=${value};expires=${new Date(Date.now() + expiration * 24 * 60 * 60 * 1000)};path=/`;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n}\r\n\r\nfunction setAllURLParamsAsCookies(expiration = 30) {\r\n\tconst urlParams = new URLSearchParams(currentUrlState.split('?')[1] || '');\r\n\tfor (const [key, value] of urlParams.entries()) {\r\n\t\tif (value && utilFetchCookieValue(key) != value) {\r\n\t\t\tdocument.cookie = `${key}=${value};expires=${new Date(Date.now() + expiration * 24 * 60 * 60 * 1000)};path=/`;\r\n\t\t}\r\n\t}\r\n}\r\n\r\n/**\r\n * Sets the values of specified UTM from the target URL as cookies.\r\n * If a cookie already exists with a different value, it will be updated with the new value,\r\n * and non-existing cookies will be removed.\r\n *\r\n * @param {Array<string>} urlParamsCaptureList - An array of URL parameter names to capture and set as cookies.\r\n * @param {number} expiration - The number of days until the cookies expire (default: 30).\r\n */\r\nfunction setUTMParamsAsCookies(urlParamsCaptureList, expiration = 30) {\r\n\tconst urlParams = new URLSearchParams(currentUrlState.split('?')[1] || '');\r\n\tif (urlParamsCaptureList.some((e) => Array.from(urlParams.keys()).includes(e))) {\r\n\t  urlParamsCaptureList.forEach((key) => {\r\n\t\tif (urlParams.has(key)) {\r\n\t\t  const existingCookieValue = utilFetchCookieValue(key);\r\n\t\t  const newCookieValue = urlParams.get(key);\r\n\t\t  if (newCookieValue && (!existingCookieValue || existingCookieValue !== newCookieValue)) {\r\n\t\t\tdocument.cookie = `${key}=${newCookieValue};expires=${new Date(\r\n\t\t\t  Date.now() + expiration * 24 * 60 * 60 * 1000\r\n\t\t\t)};path=/`;\r\n\t\t  }\r\n\t\t} else {\r\n\t\t  if (utilFetchCookieValue(key)) {\r\n\t\t\tutilDeleteCookie(key);\r\n\t\t  }\r\n\t\t}\r\n\t  });\r\n\t}\r\n\tcaptureAffiliateData();\r\n}\r\n\r\n/**\r\n * Captures the affiliation params from the utm cookies\r\n * @return {void}\r\n */\r\n\r\nfunction captureAffiliateData(){\r\n\tconst affiliateProviders = ['rakuten','ShareASale','CJ','refersion'];\r\n\tif(utilFetchCookieValue('utm_source') &&  affiliateProviders.some(p=>p.toLowerCase() === utilFetchCookieValue('utm_source').toLowerCase()) && utilFetchCookieValue('utm_campaign')){\r\n\t\tutilSetCookie('affiliate_id',utilFetchCookieValue('utm_campaign'),30);\r\n\t\tutilSetCookie('affiliate_data',utilFetchCookieValue('landing_url'),30);\r\n\t}\r\n}\r\n\r\nfunction sanitizeUrl(url=\"\"){\r\n\tlet fixedUrl = url;\r\n\tconst urlParts = url.split('?');\r\n\tif(urlParts.length > 2){\r\n\t\turlParts.forEach((p,i)=>{\r\n\t\t\tif(i===0){\r\n\t\t\t\tfixedUrl = p;\r\n\t\t\t}\r\n\t\t\tif(i===1){\r\n\t\t\t\tfixedUrl += `?${p}`;\r\n\t\t\t}\r\n\t\t\tif(i>1){\r\n\t\t\t\tfixedUrl += `&${p}`;\r\n\t\t\t}\r\n\t\t})\r\n\t}\r\n\treturn mapUTMParametersFromTw(fixedUrl);\r\n}\r\n\r\nfunction mapUTMParametersFromTw(url=''){\r\n\tlet urlSegments = url.split('?');\r\n\tlet formattedUrl = url;\r\n\tif(urlSegments.length > 1){\r\n\t\tconst urlParams = urlSegments[1].split('&');\r\n\t\tconst modifiedParams = urlParams.map(p=>{\r\n\t\t\tlet [key,value] = p.split('=');\r\n\t\t\tif(key.includes('utm_') && (value == '' || value == null) && urlParams.some(param => param.startsWith(`tw_${key.substring(4)}`))){\r\n\t\t\t\tlet twAlterNativeKey = `tw_${key.substring(4)}`;\r\n\t\t\t\tlet twAlternativeValue = urlParams.find(param => param.startsWith(twAlterNativeKey)).split('=')[1];\r\n\t\t\t\treturn `${key}=${twAlternativeValue}`;\r\n\t\t\t}\r\n\t\t\treturn p;\r\n\t\t});\r\n\t\t// Check for \"tw_\" parameters without corresponding \"utm_\" parameters\r\n\t\turlParams.forEach(p => {\r\n\t\t\tlet [key, value] = p.split('=');\r\n\t\t\tif (key.startsWith('tw_') && !urlParams.some(param => param.startsWith(`utm_${key.substring(3)}`))) {\r\n\t\t\t\tmodifiedParams.push(`utm_${key.substring(3)}=${value}`);\r\n\t\t\t}\r\n\t\t});\r\n\t\tformattedUrl = `${urlSegments[0]}?${modifiedParams.join('&')}`;\r\n\t}\r\n\treturn formattedUrl;\r\n}\r\n\r\n/**\r\n * Retrieves the value of a single cookie.\r\n *\r\n * @param {string} key - The name of the cookie to retrieve.\r\n * @returns {string|null} The value of the cookie, or null if the cookie does not exist.\r\n */\r\nfunction utilFetchCookieValue(key) {\r\n\tconst name = `${key}=`;\r\n\tconst cookies = document.cookie.split(\";\");\r\n\tfor (let i = 0; i < cookies.length; i++) {\r\n\t\tlet cookie = cookies[i].trim();\r\n\t\tif (cookie.startsWith(name)) {\r\n\t\t\treturn cookie.substring(name.length, cookie.length);\r\n\t\t}\r\n\t}\r\n\treturn null;\r\n}\r\n\r\n/**\r\n * Retrieves the values of multiple cookies.\r\n *\r\n * @param {Array<string>} keys - An array of cookie names to retrieve.\r\n * @returns {Object} An object containing the name-value pairs of the specified cookies.\r\n */\r\nfunction utilFetchCookieValues(keys) {\r\n\tconst cookies = document.cookie.split(\";\");\r\n\tconst values = {};\r\n\r\n\tfor (let i = 0; i < cookies.length; i++) {\r\n\t\tlet cookie = cookies[i].trim();\r\n\t\tfor (let j = 0; j < keys.length; j++) {\r\n\t\t\tconst name = `${keys[j]}=`;\r\n\t\t\tif (cookie.startsWith(name)) {\r\n\t\t\t\tvalues[keys[j]] = cookie.substring(name.length, cookie.length);\r\n\t\t\t\tbreak;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\treturn values;\r\n}\r\n\r\n/**\r\n * Set a cookie with the given key, value, and expiration in days.\r\n *\r\n * @param {string} key - Name of the cookie key.\r\n * @param {string} value - Value to be set for the cookie.\r\n * @param {number} expiration - Number of days until the cookie expires.\r\n */\r\nfunction utilSetCookie(key, value, expiration) {\r\n\tlet expirationDate = new Date(Date.now() + expiration * 24 * 60 * 60 * 1000);\r\n\tdocument.cookie = `${key}=${value}; expires=${expirationDate.toUTCString()}; path=/`;\r\n}\r\n\r\n/**\r\n * Update a cookie with the given key name\r\n * @param {string} key - Name of the cookie key\r\n * @param {string} value - Value to be set for the cookie\r\n * @param {number} [expiration=30] - Expiration time for the cookie in days (default: 30)\r\n */\r\nfunction utilUpdateCookie(key, value, expiration = 30) {\r\n\tlet existingValue = utilFetchCookieValue(key);\r\n\tif (existingValue !== value) {\r\n\t\tdocument.cookie = `${key}=${value};expires=${new Date(Date.now() + expiration * 24 * 60 * 60 * 1000)};path=/`;\r\n\t}\r\n}\r\n\r\n/**\r\n * Delete a cookie with the given key name\r\n * @param {string} key - Name of the cookie key\r\n */\r\nfunction utilDeleteCookie(key) {\r\n\tdocument.cookie = `${key}=;expires=${new Date(0)};path=/`;\r\n}\r\n\r\nfunction utilGetLatestClickID() {\r\n\tconst keysToCheck = [\"gclid\", \"fbclid\", \"msclkid\"];\r\n\tlet latestClickID = null;\r\n\tlet platform = null;\r\n\r\n\t// Get all cookies\r\n\tconst cookies = document.cookie.split(\"; \");\r\n\r\n\t// Iterate through cookies\r\n\tcookies.forEach((cookie) => {\r\n\t\tconst [name, value] = cookie.split(\"=\");\r\n\r\n\t\t// Check if the cookie name is one of the keys we're interested in\r\n\t\tif (keysToCheck.includes(name)) {\r\n\t\t\t// Check if it's the latest click ID found so far\r\n\t\t\tif (!latestClickID) {\r\n\t\t\t\tlatestClickID = { name, value };\r\n\t\t\t\tif (name === \"gclid\") {\r\n\t\t\t\t\tplatform = \"google\";\r\n\t\t\t\t} else if (name === \"fbclid\") {\r\n\t\t\t\t\tplatform = \"facebook\";\r\n\t\t\t\t} else if (name === \"msclkid\") {\r\n\t\t\t\t\tplatform = \"bing\";\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\t// Compare the timestamp of the current and latest click IDs if available\r\n\t\t\t\tconst currentValue = decodeURIComponent(value);\r\n\t\t\t\tconst currentTimestamp = parseFloat(currentValue.split(\"_\")[1]);\r\n\t\t\t\tconst latestTimestamp = parseFloat(latestClickID.value.split(\"_\")[1]);\r\n\r\n\t\t\t\tif (!isNaN(currentTimestamp) && !isNaN(latestTimestamp) && currentTimestamp > latestTimestamp) {\r\n\t\t\t\t\tlatestClickID = { name, value };\r\n\t\t\t\t\tif (name === \"gclid\") {\r\n\t\t\t\t\t\tplatform = \"google\";\r\n\t\t\t\t\t} else if (name === \"fbclid\") {\r\n\t\t\t\t\t\tplatform = \"facebook\";\r\n\t\t\t\t\t} else if (name === \"msclkid\") {\r\n\t\t\t\t\t\tplatform = \"bing\";\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t}\r\n\t\t}\r\n\t});\r\n\r\n\t// Check if any click ID was found, if not, return null\r\n\tif (!latestClickID) {\r\n\t\treturn null;\r\n\t}\r\n\r\n\treturn { clickID: latestClickID, platform };\r\n}\r\n\r\n\r\n/**\r\n * Snapshots the current discount code into a dedicated sale cookie,\r\n * so sale pricing keeps working after `discount_code` is overwritten.\r\n * Written once only - an existing snapshot is never replaced.\r\n *\r\n * @param {number} expiration - The number of days until the cookie expires (default: 7).\r\n */\r\nfunction captureSaleDiscountCode(expiration = 7) {\r\n\tconst discountCode = utilFetchCookieValue('discount_code');\r\n\tif (discountCode && !utilFetchCookieValue('sale_discount_code')) {\r\n\t\tutilSetCookie('sale_discount_code', discountCode, expiration);\r\n\t}\r\n}\r\n\r\n// setting the utm params to cookies to later use for lead forms\r\nconst urlParamsCaptureList = [\"utm_campaign\", \"utm_medium\", \"utm_source\", \"utm_term\", \"utm_content\",\"gclid\",\"fbclid\",\"msclkid\"];\r\nsetUTMParamsAsCookies(urlParamsCaptureList, 30);\r\nsetAllURLParamsAsCookies();\r\ncaptureSaleDiscountCode();\r\nif (utilFetchCookieValue('landing_url') === null) {\r\n\tutilSetCookie('landing_url',window.location.href,360);\r\n}"],
  "mappings": "AAAA,IAAI,gBAAkB,YAAY,OAAO,SAAS,IAAI,EAStD,SAAS,sBAAsBA,sBAAsB,WAAa,GAAI,CACrE,MAAM,UAAY,IAAI,gBAAgB,gBAAgB,MAAM,GAAG,EAAE,CAAC,GAAK,EAAE,EACzE,SAAW,CAAC,IAAK,KAAK,IAAK,UAAU,QAAQ,EAC5C,GAAIA,sBAAqB,SAAS,GAAG,EAAG,CACvC,MAAM,oBAAsB,qBAAqB,GAAG,EAChD,QAAU,CAAC,qBAAuB,sBAAwB,SAC7D,SAAS,OAAS,GAAG,GAAG,IAAI,KAAK,YAAY,IAAI,KAAK,KAAK,IAAI,EAAI,WAAa,GAAK,GAAK,GAAK,GAAI,CAAC,UAEtG,CAEF,CAEA,SAAS,yBAAyB,WAAa,GAAI,CAClD,MAAM,UAAY,IAAI,gBAAgB,gBAAgB,MAAM,GAAG,EAAE,CAAC,GAAK,EAAE,EACzE,SAAW,CAAC,IAAK,KAAK,IAAK,UAAU,QAAQ,EACxC,OAAS,qBAAqB,GAAG,GAAK,QACzC,SAAS,OAAS,GAAG,GAAG,IAAI,KAAK,YAAY,IAAI,KAAK,KAAK,IAAI,EAAI,WAAa,GAAK,GAAK,GAAK,GAA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