{"version":3,"sources":["assets/src/js/Services/UTM.js"],"names":["jQuery","document","ready","$","UTM","debug","cname","cvalue","exhours","d","Date","Drupal","ToolsHelper","COOKIE_DEFAULT_DURATION","setTime","getTime","expires","toUTCString","cookie","name","decodedCookie","decodeURIComponent","ca","split","let","i","length","c","charAt","substring","indexOf","replace","results","RegExp","exec","location","search","utm_param","utm_val","utmCookie","console","log","getCookie","TrackingConsentManager","canTrackCurrentUser","val","change","setCookie","path","utm","set_utm","getParameterByName"],"mappings":"AAAAA,OAAOC,UAAUC,MAAM,SAAUC,GAE/BC,IAAM,CACJC,OAAO,EAeTD,UAAgB,SAASE,EAAOC,EAAQC,GACtC,MAAMC,EAAI,IAAIC,UACS,IAAZF,IACTA,EAAUG,OAAOC,YAAYC,yBAE/BJ,EAAEK,QAAQL,EAAEM,UAAuB,GAAVP,EAAe,GAAK,KACvCQ,EAAU,WAAaP,EAAEQ,cAC/BhB,SAASiB,OAASZ,EAAQ,IAAMC,EAAS,IAAMS,EAAU,WAY3DZ,UAAgB,SAAUE,GACxB,IAAMa,EAAOb,EAAQ,IACrB,MAAMc,EAAgBC,mBAAmBpB,SAASiB,QAClD,IAAMI,EAAKF,EAAcG,MAAM,KAC/B,IAAKC,IAAIC,EAAI,EAAGA,EAAIH,EAAGI,OAAQD,IAAK,CAClCD,IAAIG,EAAIL,EAAGG,GACX,KAAuB,MAAhBE,EAAEC,OAAO,IACdD,EAAIA,EAAEE,UAAU,GAElB,GAAwB,IAApBF,EAAEG,QAAQX,GACZ,OAAOQ,EAAEE,UAAUV,EAAKO,OAAQC,EAAED,QAGtC,OAAO,MASTtB,mBAAyB,SAAUe,GACjCA,EAAOA,EAAKY,QAAQ,OAAQ,KAAMA,QAAQ,OAAQ,KAE9CC,EADQ,IAAIC,OAAO,OAAUd,EAAO,aACpBe,KAAKC,SAASC,QAClC,OAAmB,OAAZJ,EAAmBX,mBAAmBW,EAAQ,GAAGD,QAAQ,MAAO,MAAQ,IAYjF3B,QAAc,SAAUiC,EAAWC,GAKjC,IAIIC,EARAnC,IAAIC,OACNmC,QAAQC,IAAI,iCAAmCJ,EAAY,iBAAmBC,EAAU,KAG1E,OAAZA,IAKa,QADbC,EAAYnC,IAAIsC,UAAU,OAASL,KACdM,uBAAuBC,uBAC1CxC,IAAIC,OACNmC,QAAQC,IAAI,sBAAwBF,GAEtCpC,EAAE,mBAAqBkC,EAAY,SAASQ,IAAIN,GAAWO,WAGvD1C,IAAIC,OACNmC,QAAQC,IAAI,0CAEE,KAAZH,IACElC,IAAIC,OACNmC,QAAQC,IAAI,wBAEdrC,IAAI2C,UAAU,OAASV,EAAYC,EAAS,CAACU,KAAM,WAMzD,IAAK,IAAIC,IAAO,CAAC,SAAU,SAAU,WAAY,UAAW,QAC1D7C,IAAI8C,QAAQD,EAAK7C,IAAI+C,mBAAmB,OAASF","file":"UTM.js","sourcesContent":["jQuery(document).ready(function ($) {\r\n\r\n UTM = {\r\n debug: true,\r\n };\r\n\r\n /**\r\n * Set given cookie.\r\n *\r\n * @param {string} cname\r\n * Cookie Name.\r\n * @param {string|int} cvalue\r\n * Cookie value.\r\n * @param {int} [exhours]\r\n * Cookie duration (in hours).\r\n *\r\n * @return {undefined}\r\n */\r\n UTM.setCookie = function(cname, cvalue, exhours) {\r\n const d = new Date();\r\n if (typeof exhours === 'undefined') {\r\n exhours = Drupal.ToolsHelper.COOKIE_DEFAULT_DURATION; // Duration in hours\r\n }\r\n d.setTime(d.getTime() + (exhours * 60 * 60 * 1000));\r\n const expires = 'expires=' + d.toUTCString();\r\n document.cookie = cname + '=' + cvalue + ';' + expires + ';path=/';\r\n };\r\n\r\n /**\r\n * Set a cookie value, or null if not defined.\r\n *\r\n * @param {string} cname\r\n * Cookie Name.\r\n *\r\n * @returns {string|null}\r\n * Cookie value of found, otherwise null.\r\n */\r\n UTM.getCookie = function (cname) {\r\n const name = cname + '=';\r\n const decodedCookie = decodeURIComponent(document.cookie);\r\n const ca = decodedCookie.split(';');\r\n for (let i = 0; i < ca.length; i++) {\r\n let c = ca[i];\r\n while (c.charAt(0) === ' ') {\r\n c = c.substring(1);\r\n }\r\n if (c.indexOf(name) === 0) {\r\n return c.substring(name.length, c.length);\r\n }\r\n }\r\n return null;\r\n };\r\n\r\n /**\r\n * Parse the URL to extract parameters.\r\n *\r\n * @param {string} name\r\n * @return {string}\r\n */\r\n UTM.getParameterByName = function (name) {\r\n name = name.replace(/[\\[]/, \"\\[\").replace(/[\\]]/, \"\\]\");\r\n var regex = new RegExp(\"[\\?&]\" + name + \"=([^&#]*)\"),\r\n results = regex.exec(location.search);\r\n return results !== null ? decodeURIComponent(results[1].replace(/\\+/g, \" \")) : '';\r\n };\r\n\r\n /**\r\n * Set UTM function\r\n *\r\n * Assumes all hidden fields follow this format :\r\n * \r\n *\r\n * @param {string} utm_param\r\n * @param {*} utm_val\r\n */\r\n UTM.set_utm = function (utm_param, utm_val) {\r\n if (UTM.debug) {\r\n console.log('UTM - Managing utm logic for \"' + utm_param + '\" with param \"' + utm_val + '\"');\r\n }\r\n\r\n if (utm_val === null) {\r\n return;\r\n }\r\n\r\n var utmCookie = UTM.getCookie('utm_' + utm_param);\r\n if (utmCookie!== null && TrackingConsentManager.canTrackCurrentUser()) {\r\n if (UTM.debug) {\r\n console.log('UTM - Set input to ' + utmCookie);\r\n }\r\n $('input[name=\"utm_' + utm_param + '__c\"]').val(utmCookie).change();\r\n }\r\n else {\r\n if (UTM.debug) {\r\n console.log('UTM - Using current code / no code set');\r\n }\r\n if (utm_val !== '') {\r\n if (UTM.debug) {\r\n console.log('UTM - Set the cookie');\r\n }\r\n UTM.setCookie('utm_' + utm_param , utm_val, {path: '/'});\r\n }\r\n }\r\n };\r\n\r\n // Do the Set UTM function for each UTM.\r\n for (var utm of ['source', 'medium', 'campaign', 'content', 'term']) {\r\n UTM.set_utm(utm, UTM.getParameterByName('utm_' + utm));\r\n }\r\n\r\n});\r\n"]}