!function(e){var t={};function i(n){if(t[n])return t[n].exports;var o=t[n]={i:n,l:!1,exports:{}};return e[n].call(o.exports,o,o.exports,i),o.l=!0,o.exports}i.m=e,i.c=t,i.d=function(e,t,n){i.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},i.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},i.t=function(e,t){if(1&t&&(e=i(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(i.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)i.d(n,o,function(t){return e[t]}.bind(null,o));return n},i.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return i.d(t,"a",t),t},i.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},i.p="",i(i.s=0)}([function(e,t,i){"use strict";function n(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function o(){throw new Error("Missing parameter")}i.r(t);var r=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:sessionStorage;!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this._engine=t}var t,i,r;return t=e,(i=[{key:"getItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o();return this.engine.getItem(e)}},{key:"setItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:o();try{this.engine.setItem(e,t)}catch(e){console.info("Cannot set item")}}},{key:"removeItem",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o();this.engine.removeItem(e)}},{key:"keysWithPrefix",value:function(e){return Object.keys(this.engine).filter(function(t){return t.startsWith(e)})}},{key:"clear",value:function(){this.engine.clear()}},{key:"setQueue",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:o(),i=JSON.stringify(t);return this.engine.setItem(e,i),this.getQueue(e)}},{key:"getQueue",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o(),t=this.engine.getItem(e);return JSON.parse(t)||[]}},{key:"pushToQueue",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o(),t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:o(),i=this.getQueue(e);return i.push(t),this.setQueue(e,i)}},{key:"queueLength",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:o();return this.getQueue(e).length}},{key:"engine",get:function(){return this._engine},set:function(e){throw"Cannot set the engine"}}])&&n(t.prototype,i),r&&n(t,r),e}();function s(e){return(s="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function a(e,t){for(var i=0;i<t.length;i++){var n=t[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}var u=function(){function e(){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,e),this.id=null,this.hasIdentified=!1,this.maxQueueLength=5,this.timeoutDuration=3e4,this.debugMode=!1,this.attributes={},this.apiURL="https://track.lexer.io"}var t,i,n;return t=e,(i=[{key:"initiate",value:function(e,t){var i=this;if(!e||!t)throw this.debugMode&&console.info("LXT","Initiate params are missing:",e,t),"Initiate params are missing: ".concat(e,", ").concat(t);return this.id=e,this.debugMode&&console.info("LXT","Initiated with id",this.id),this.attributes=t,this.debugMode&&console.info("LXT","Set attributes",this.attributes),this.sessionStore=new r(sessionStorage),this.localStore=new r(localStorage),this.shouldStartTimer()&&(this.timerStart=Number(new Date)),this.incrementPageViewCounter(),this.addUTMCodes(),this.addReferer(),this.useCachedEntries(),window.addEventListener("beforeunload",function(){i.onUnload()}),!0}},{key:"isInitiated",value:function(){return null!=this.id}},{key:"reset",value:function(){this.resetQueue(!0),this.clearCachedEntries(),this.hasIdentified=!1}},{key:"identify",value:function(t,i){if(null==t||null==i||""===i||"undefined"===i)throw this.debugMode&&console.info("LXT","Params are missing and must be a value.",t,i),"Params are missing and must be a value: ".concat(t,", ").concat(i);if(!this.isInitiated())throw"Tag is not initiated.";if(-1===Object.keys(this.attributes).indexOf(t))throw"Unknown key provided: ".concat(t);return this.debugMode&&console.info("LXT","Adding identity to queue",t,this.attributes[t],i),this.appendToQueue(this.attributes[t],i,e.KEYS.IDENTIFY_TYPE),this.saveIdentifierToCache(t,i),this.startAutoSubmitTimer(),this.hasIdentified=!0,this.shouldSubmit()&&this.sendPayload(this.generatePayload()),this.hasIdentified}},{key:"track",value:function(t,i){if(null==t||null==i||""===i||"undefined"===i)throw this.debugMode&&console.info("LXT","Params are missing and must be a value.",t,i),"Params are missing and must be a value: ".concat(t,", ").concat(i);if(!this.isInitiated())throw"Tag is not initiated.";if(-1===Object.keys(this.attributes).indexOf(t))throw"Unknown key provided: ".concat(t);return this.debugMode&&console.info("LXT","Adding data to queue",t,this.attributes[t],i),this.appendToQueue(this.attributes[t],i,e.KEYS.TRACK_TYPE),this.startAutoSubmitTimer(),this.shouldSubmit()&&this.sendPayload(this.generatePayload()),!0}},{key:"getQueueLength",value:function(){return this.sessionStore.queueLength(e.KEYS.QUEUE)}},{key:"getQueue",value:function(){return this.sessionStore.getQueue(e.KEYS.QUEUE)}},{key:"appendToQueue",value:function(t,i,n){if("string"==typeof i||i instanceof String||"number"==typeof i||i instanceof Number||"boolean"==typeof i||i instanceof Boolean)return this.sessionStore.getQueue(e.KEYS.QUEUE).filter(function(e){return e.key===t&&e.value===i&&e.type===n}).length>0?this.debugMode&&console.info("LXT","Skipped adding to queue - Is duplicate"):(this.sessionStore.pushToQueue(e.KEYS.QUEUE,{key:t,value:i,type:n}),this.debugMode&&console.info("LXT","Added to queue",t,i,n)),this.getQueueLength();throw"Only a string or a number is accepted. A ".concat(s(i)," was provided.")}},{key:"resetQueue",value:function(){if(arguments.length>0&&void 0!==arguments[0]&&arguments[0])this.debugMode&&console.info("LXT","Full reset of queue"),this.sessionStore.setQueue(e.KEYS.QUEUE,[]);else{this.debugMode&&console.info("LXT","Resetting queue");var t=this.sessionStore.getQueue(e.KEYS.QUEUE).filter(function(t){return t.type===e.KEYS.IDENTIFY_TYPE});this.sessionStore.setQueue(e.KEYS.QUEUE,t)}return!0}},{key:"startAutoSubmitTimer",value:function(){var e=this;clearTimeout(this.timeout),this.timeout=setTimeout(function(){e.debugMode&&console.info("LXT","Timeout has triggered"),e.shouldSubmit(!0)?e.sendPayload(e.generatePayload()):e.startAutoSubmitTimer()},this.timeoutDuration)}},{key:"onUnload",value:function(){if(this.shouldSubmit(!0)){var e=this.generatePayload(),t=JSON.stringify(e);this.debugMode&&console.info("LXT","Sending payload via beacon",e),navigator.sendBeacon("".concat(this.apiURL,"/beacon"),t)}}},{key:"onConversion",value:function(){if(this.shouldSubmit(!0)){var e=Object.assign(this.generatePayload(),this.generateMetadataPayload());this.debugMode&&console.info("LXT","on funnel end payload",e),this.sendPayload(e)}}},{key:"shouldSubmit",value:function(){var e=arguments.length>0&&void 0!==arguments[0]&&arguments[0],t=this.getQueueLength()>=this.maxQueueLength;return this.hasIdentified?e||t?(this.debugMode&&console.info("LXT","Should submit",e,t),!0):(this.debugMode&&console.info("LXT","Shouldn't submit - queue check",e,t),!1):(this.debugMode&&console.info("LXT","Shouldn't submit - identity check",this.hasIdentified),!1)}},{key:"generatePayload",value:function(){var t={formId:this.id,userAgent:navigator.userAgent};return this.sessionStore.getQueue(e.KEYS.QUEUE).forEach(function(e){t[e.key]=t[e.key]||[],t[e.key].push(e.value)}),this.debugMode&&console.info("LXT","Generated payload",t),t}},{key:"generateMetadataPayload",value:function(){var e={};return this.attributes.time_spent_to_convert&&(e[this.attributes.time_spent_to_convert]=[this.timeOnSite()]),this.attributes.pages_viewed_to_convert&&(e[this.attributes.pages_viewed_to_convert]=[this.pagesViewed]),this.attributes.device_used&&(e[this.attributes.device_used]=[this.deviceType()]),e}},{key:"sendPayload",value:function(e){var t=this;if(!e)throw"Error: No payload provided";var i=new XMLHttpRequest;i.open("POST","".concat(this.apiURL,"/tag")),i.setRequestHeader("Content-Type","application/json"),i.onreadystatechange=function(){if(4===i.readyState){if(200!==i.status&&201!==i.status)throw t.debugMode&&console.warn("LXT","Unsuccessful delivery"),"Error";t.debugMode&&console.info("LXT","Successful delivery"),t.resetQueue()}},this.debugMode&&console.info("LXT","Sending payload",e),i.send(JSON.stringify(e))}},{key:"saveIdentifierToCache",value:function(e,t){e=btoa(e);var i=this.hashIdentifierKeyForStorage(e),n=btoa(t);this.debugMode&&console.info("LXT","Storing identifier for future visits",i,t,n),this.localStore.setItem(i,n)}},{key:"getIdentifierFromCache",value:function(e){e=btoa(e);var t=this.hashIdentifierKeyForStorage(e),i=this.localStore.getItem(t);return i?atob(i):i}},{key:"hashIdentifierKeyForStorage",value:function(t){return"".concat(e.KEYS.HASH_KEY_STORE_PREFIX,"_").concat(t)}},{key:"cachedEntries",value:function(){var t=this;return this.localStore.keysWithPrefix(e.KEYS.HASH_KEY_STORE_PREFIX).map(function(i){var n=i.replace("".concat(e.KEYS.HASH_KEY_STORE_PREFIX,"_"),"");return[atob(n),atob(t.localStore.getItem(i))]})}},{key:"clearCachedEntries",value:function(){var t=this;return this.localStore.keysWithPrefix(e.KEYS.HASH_KEY_STORE_PREFIX).forEach(function(e){t.localStore.removeItem(e)})}},{key:"useCachedEntries",value:function(){var e=this;this.cachedEntries().forEach(function(t){var i=t[0],n=t[1];e.debugMode&&console.info("LXT","Adding cached entry to queue",i,n),e.identify(i,n)})}},{key:"incrementPageViewCounter",value:function(){var t=this.pagesViewed+1;this.debugMode&&console.info("LXT","Incrementing page view counter to",t),this.sessionStore.setItem(e.KEYS.PAGE_VIEWS,t)}},{key:"deviceType",value:function(e){var t;return t=null!=(e=e||navigator.userAgent).match(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino/i)?"mobile":null!=e.match(/android|ipad|playbook|silk/i)?"tablet":"desktop",this.debugMode&&console.info("LXT","Determined device type",t),t}},{key:"utmCodes",value:function(){var e={};return window.location.search.substring(1).split("&").forEach(function(t){var i=t.split("=");"utm_"===i[0].substr(0,4)&&(e[i[0]]=decodeURIComponent(i[1]))}),this.debugMode&&console.info("LXT","Collected UTM codes",e),e}},{key:"addUTMCodes",value:function(){var e=this,t=this.utmCodes();Object.keys(t).forEach(function(i){e.attributes[i]&&e.track(i,t[i])})}},{key:"referer",value:function(){return!(!navigator||!navigator.referer)&&navigator.referer}},{key:"addReferer",value:function(){this.sessionStore.getItem(e.KEYS.HAS_TRACKED_REFERER)||this.attributes.referrer_url&&this.referer()&&(this.track("referrer_url",this.referer()),this.sessionStore.setItem(e.KEYS.HAS_TRACKED_REFERER,"true"))}},{key:"shouldStartTimer",value:function(){return!this.sessionStore.getItem(e.KEYS.SESSION_TIMER)}},{key:"timeOnSite",value:function(){return Math.round((Number(new Date)-this.timerStart)/1e3)}},{key:"pagesViewed",get:function(){return Number(this.sessionStore.getItem(e.KEYS.PAGE_VIEWS))}},{key:"timerStart",set:function(t){return this.debugMode&&console.info("LXT","Setting session start timer",t),this.sessionStore.setItem(e.KEYS.SESSION_TIMER,t),t},get:function(){return Number(this.sessionStore.getItem(e.KEYS.SESSION_TIMER))}}])&&a(t.prototype,i),n&&a(t,n),e}();function d(){window.___lexer_tag=window.___lexer_tag||new u;var e=window.___lexer_tag;if(arguments.length){var t=arguments[0];switch(t){case"initiate":e.initiate(arguments[1],arguments[2]);break;case"apiURL":e.apiURL=arguments[1];break;case"debug":e.debugMode=arguments[1];break;case"identify":e.identify(arguments[1],arguments[2]);break;case"track":e.track(arguments[1],arguments[2]);break;case"converted":e.onConversion();break;case"reset":e.reset();break;default:console.error("LXT","Unknown action",t,arguments)}}return e}function c(){var e=window.__lxt_cache||[];d().debugMode&&console.info("LXT","Processing cache"),e.forEach(function(e){d().debugMode&&console.info("LXT","Processing cache entry",e),window.lxt.apply(null,e)})}u.KEYS={QUEUE:"___lxt_queue",HAS_TRACKED_REFERER:"___lxt_has_referer",IDENTIFY_TYPE:"___lxt_identify_type",TRACK_TYPE:"___lxt_track_type",SESSION_TIMER:"___lxt_session_timer",PAGE_VIEWS:"___lxt_page_views",IDENTITY_STORE:"___lxt_identifiers",HASH_KEY_STORE_PREFIX:"___lxt_link"},i.d(t,"default",function(){return d}),i.d(t,"processLXTCache",function(){return c}),window.lxt=d,window.processLXTCache=c,window.processLXTCache()}]);