{"version":3,"file":"utm.js","names":["parseQueryString","parts","location","search","replace","split","utms","save","cfUTMs","getCloudFlare","c","oldCookie","Cookies","get","k","JSON","parse","e","length","i","items","indexOf","domain","host","set","stringify","path","cookies","values","remove"],"sources":["utm.js"],"sourcesContent":["//console.log('UTM Module loaded..');\n\n/*\nThis function does the following:\n- Looks to see if we have a CloudFlare `utm-params` cookie, parses and removes it.\n- Then it looks at the QueryString for parameters that start with `utm`\n and them parses them into a JSON object like:\n {\n utm1: value2,\n utm2: value2\n }\n- Then it merges the three together with any existing `utm-parsed` cookie:\n - `utm-params` Cookie (Cloudflare)\n - `utm-parsed` Cookie (us)\n - then parses the Querystring (the winner for overrides)\n-Then it creates a JSON object and stores that data in the `utm-parsed` Cookie\n*/ \nvar parseQueryString = function() {\n var parts = location.search.replace('?', '').split('&');\n //console.log(location.search, parts);\n var utms = {};\n var save = false;\n //Get Cloudflare cookie\n var cfUTMs = getCloudFlare();\n if (cfUTMs) {\n //console.log('cfUTMs', cfUTMs);\n for (var c in cfUTMs) {\n utms[c] = cfUTMs[c];\n }\n }\n //Parse the existing `utm-parsed` Cookie\n var oldCookie = Cookies.get('utm-parsed');\n if (oldCookie) {\n //console.log('Found old cookie, updating..');\n //console.log('oldCookie1:', oldCookie);\n //try/catch here for JSON.parse errors.\n try {\n oldCookie = JSON.parse(oldCookie);\n //console.log('oldCookie2:', oldCookie);\n for (var k in oldCookie) {\n utms[k] = oldCookie[k];\n }\n } catch (e) {\n //do nothing here..\n }\n }\n if (parts.length) {\n for (var i = 0; i < parts.length; i++) {\n var items = parts[i].split('=');\n if (items.length && items[0].indexOf('utm') > -1) {\n save = true;\n utms[items[0]] = items[1];\n }\n }\n }\n if (save) {\n //console.log('utms:', utms);\n //console.log('Saving UTM Cookie', JSON.stringify(utms));\n //try/catch here for JSON.stringify errors.\n try {\n var domain = '';\n if (location.host.indexOf('medicalert.org') > -1) {\n domain = '.medicalert.org';\n }\n Cookies.set('utm-parsed', JSON.stringify(utms), { path: '', domain: domain });\n } catch (e) {\n //do nothing here..\n }\n } else {\n //console.log('Skipping cookie save.');\n }\n};\n/*\nThis function parses the `utm-params` cookie that is set in CloudFlare\nif the user visited the old site and their querystring contained a utm\nparameter. We want to clean this up here by parsing the cookie, formatting\nit into the params that we want and then setting the new `utm-parsed` cookie\nwith those values. It should remove the CloudFlare cookie once the parse is\ncompleted.\n*/ \nvar getCloudFlare = function() {\n var utms = {};\n var cookies = Cookies.get('utm-params');\n var values = false;\n if (cookies) {\n cookies = cookies.split(';')[0];\n if (cookies) {\n var parts = cookies.split('&');\n for (var i = 0; i < parts.length; i++) {\n var items = parts[i].split('=');\n if (items && items[0] && items[0].indexOf('utm') > -1) {\n values = true;\n utms[items[0]] = items[1];\n }\n }\n }\n //Remove the CF Cookie\n Cookies.remove('utm-params');\n }\n return values ? utms : null;\n};\n\n//Start things off..\nparseQueryString();\n"],"mappings":"AAiBA,IAAIA,iBAAmB,WACnB,IAAIC,EAAQC,SAASC,OAAOC,QAAQ,IAAK,IAAIC,MAAM,KAE/CC,EAAO,CAAC,EACRC,GAAO,EAEPC,EAASC,gBACb,GAAID,EAEA,IAAK,IAAIE,KAAKF,EACVF,EAAKI,GAAKF,EAAOE,GAIzB,IAAIC,EAAYC,QAAQC,IAAI,cAC5B,GAAIF,EAIA,IAGI,IAAK,IAAIG,KAFTH,EAAYI,KAAKC,MAAML,GAGnBL,EAAKQ,GAAKH,EAAUG,EAE5B,CAAE,MAAOG,GAET,CAEJ,GAAIhB,EAAMiB,OACN,IAAK,IAAIC,EAAI,EAAGA,EAAIlB,EAAMiB,OAAQC,IAAK,CACnC,IAAIC,EAAQnB,EAAMkB,GAAGd,MAAM,KACvBe,EAAMF,QAAUE,EAAM,GAAGC,QAAQ,QAAU,IAC3Cd,GAAO,EACPD,EAAKc,EAAM,IAAMA,EAAM,GAE/B,CAEJ,GAAIb,EAIA,IACI,IAAIe,EAAS,GACTpB,SAASqB,KAAKF,QAAQ,mBAAqB,IAC3CC,EAAS,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