!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.Trackerizr=t():e.Trackerizr=t()}(this,function(){return function(e){function t(r){if(n[r])return n[r].exports;var o=n[r]={exports:{},id:r,loaded:!1};return e[r].call(o.exports,o,o.exports,t),o.loaded=!0,o.exports}var n={};return t.m=e,t.c=n,t.p="",t(0)}([function(e,t,n){e.exports=n(25)},function(e,t,n){"use strict";function r(e){return"[object Array]"===E.call(e)}function o(e){return"[object ArrayBuffer]"===E.call(e)}function i(e){return"undefined"!=typeof FormData&&e instanceof FormData}function a(e){var t;return t="undefined"!=typeof ArrayBuffer&&ArrayBuffer.isView?ArrayBuffer.isView(e):e&&e.buffer&&e.buffer instanceof ArrayBuffer}function u(e){return"string"==typeof e}function s(e){return"number"==typeof e}function c(e){return"undefined"==typeof e}function f(e){return null!==e&&"object"==typeof e}function l(e){return"[object Date]"===E.call(e)}function p(e){return"[object File]"===E.call(e)}function d(e){return"[object Blob]"===E.call(e)}function h(e){return"[object Function]"===E.call(e)}function v(e){return f(e)&&h(e.pipe)}function m(e){return"undefined"!=typeof URLSearchParams&&e instanceof URLSearchParams}function y(e){return e.replace(/^\s*/,"").replace(/\s*$/,"")}function g(){return"undefined"!=typeof window&&"undefined"!=typeof document&&"function"==typeof document.createElement}function w(e,t){if(null!==e&&"undefined"!=typeof e)if("object"==typeof e||r(e)||(e=[e]),r(e))for(var n=0,o=e.length;n=200&&e<300}}},function(e,t){"use strict";function n(){this.message="String contains an invalid character"}function r(e){for(var t,r,i=String(e),a="",u=0,s=o;i.charAt(0|u)||(s="=",u%1);a+=s.charAt(63&t>>8-u%1*8)){if(r=i.charCodeAt(u+=.75),r>255)throw new n;t=t<<8|r}return a}var o="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";n.prototype=new Error,n.prototype.code=5,n.prototype.name="InvalidCharacterError",e.exports=r},function(e,t,n){"use strict";function r(e){return encodeURIComponent(e).replace(/%40/gi,"@").replace(/%3A/gi,":").replace(/%24/g,"$").replace(/%2C/gi,",").replace(/%20/g,"+").replace(/%5B/gi,"[").replace(/%5D/gi,"]")}var o=n(1);e.exports=function(e,t,n){if(!t)return e;var i;if(n)i=n(t);else if(o.isURLSearchParams(t))i=t.toString();else{var a=[];o.forEach(t,function(e,t){null!==e&&"undefined"!=typeof e&&(o.isArray(e)&&(t+="[]"),o.isArray(e)||(e=[e]),o.forEach(e,function(e){o.isDate(e)?e=e.toISOString():o.isObject(e)&&(e=JSON.stringify(e)),a.push(r(t)+"="+r(e))}))}),i=a.join("&")}return i&&(e+=(e.indexOf("?")===-1?"?":"&")+i),e}},function(e,t){"use strict";e.exports=function(e,t){return e.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,"")}},function(e,t,n){"use strict";var r=n(1);e.exports=r.isStandardBrowserEnv()?function(){return{write:function(e,t,n,o,i,a){var u=[];u.push(e+"="+encodeURIComponent(t)),r.isNumber(n)&&u.push("expires="+new Date(n).toGMTString()),r.isString(o)&&u.push("path="+o),r.isString(i)&&u.push("domain="+i),a===!0&&u.push("secure"),document.cookie=u.join("; ")},read:function(e){var t=document.cookie.match(new RegExp("(^|;\\s*)("+e+")=([^;]*)"));return t?decodeURIComponent(t[3]):null},remove:function(e){this.write(e,"",Date.now()-864e5)}}}():function(){return{write:function(){},read:function(){return null},remove:function(){}}}()},function(e,t){"use strict";e.exports=function(e){return/^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(e)}},function(e,t,n){"use strict";var r=n(1);e.exports=r.isStandardBrowserEnv()?function(){function e(e){var t=e;return n&&(o.setAttribute("href",t),t=o.href),o.setAttribute("href",t),{href:o.href,protocol:o.protocol?o.protocol.replace(/:$/,""):"",host:o.host,search:o.search?o.search.replace(/^\?/,""):"",hash:o.hash?o.hash.replace(/^#/,""):"",hostname:o.hostname,port:o.port,pathname:"/"===o.pathname.charAt(0)?o.pathname:"/"+o.pathname}}var t,n=/(msie|trident)/i.test(navigator.userAgent),o=document.createElement("a");return t=e(window.location.href),function(n){var o=r.isString(n)?e(n):n;return o.protocol===t.protocol&&o.host===t.host}}():function(){return function(){return!0}}()},function(e,t,n){"use strict";var r=n(1);e.exports=function(e,t){r.forEach(e,function(n,r){r!==t&&r.toUpperCase()===t.toUpperCase()&&(e[t]=n,delete e[r])})}},function(e,t,n){"use strict";var r=n(1);e.exports=function(e){var t,n,o,i={};return e?(r.forEach(e.split("\n"),function(e){o=e.indexOf(":"),t=r.trim(e.substr(0,o)).toLowerCase(),n=r.trim(e.substr(o+1)),t&&(i[t]=i[t]?i[t]+", "+n:n)}),i):i}},function(e,t){"use strict";e.exports=function(e){return function(t){return e.apply(null,t)}}},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function i(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function a(e,t){var n="/"!==t[0]?"/"+t:t;return e+n}Object.defineProperty(t,"__esModule",{value:!0});var u=function(){function e(e,t){for(var n=0;n0&&void 0!==arguments[0]?arguments[0]:null,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null,n=arguments.length>2&&void 0!==arguments[2]&&arguments[2];if(this.initialized)throw new Error("Trackerizr has already been initialized");if(!e||!/^[A-Za-z0-9\-_]{43}$/.test(e))throw new Error("Malformed API key (must be a 43 alphanumeric (including hyphen and underscore) characters length string)");this.apiKey=e;var r=b;if(null!==t){if(t.idle){if(t.idleb)throw new Error("Idle duration must be set between "+w+" (inclusive) and "+b+" (inclusive)");r=t.idle}if(t.geolocation&&this.activateGeolocation(),t.offlineBuffering&&this.activateOfflineBuffering(),t.throttleWait){if(!(t.throttleWait>=_))throw new Error("throttleWait configuration cannot be lower than "+_+" ms");this.__throttledSendBatch=(0,d.default)(this.__sendBatch,t.throttleWait,{leading:!0,trailing:!0})}t.__api&&(t.__api.baseUrl&&(this.apiBaseUrl=t.__api.baseUrl),t.__api.endpoint&&(this.apiEndpoint=t.__api.endpoint))}this.userManager=new v.default(r),this.initialized=!0,n&&this.tryFlushOfflineBuffer()}},{key:"__validateNavigatorEnvironment",value:function(){return navigator.cookieEnabled}},{key:"track",value:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:null;if(this.__validateNavigatorEnvironment()){var n=new Date;if(!this.initialized)throw new Error("Trackerizr must be initialized first (use Trackerizr.init())");if(!(Array.isArray(e)&&e.length>=1))throw new Error("Trackerizr.track() first param expects an array with at least 1 element");var r={event:e,timestamp:n.getTime(),timezone_offset:n.getTimezoneOffset()};if(null!==t){if(!t.type||!t.value)throw new Error('Trackerizr.track() second param must be an object with "type" AND "value" attributes');r.param=t}null!==this.geolocation.watcher&&null!==this.geolocation.coords&&(r.location={lat:this.geolocation.coords.latitude,lng:this.geolocation.coords.longitude}),this.batchBuffer.push(r),this.__throttledSendBatch()}}},{key:"__sendBatch",value:function(){var e=this,t=new Date,n=t.getTime(),r=this.batchBuffer.splice(0),i={events:r,from_offline_buffer:!1,user:this.userManager.getUser()},u={headers:o({},g,this.apiKey),timeout:T},s=a(this.apiBaseUrl,this.apiEndpoint);c.default.post(s,i,u).then(function(e){207===e.status&&(console.warn("Your batch has been partially created, some events are in error"),console.error(e.data.data))}).catch(function(t){try{if(("ECONNABORTED"===t.code||"Network Error"===t.message)&&null!==e.offlineBufferTimer&&"undefined"!=typeof localStorage){var r=""+j+n,o=JSON.stringify({timestamp:n,data:i});localStorage.setItem(r,o)}}catch(e){}t.response&&400===t.response.status&&console.error("Your batch has been rejected, event is in error")})}},{key:"tryFlushOfflineBuffer",value:function(){var e=this;if(this.__validateNavigatorEnvironment()){if(!this.initialized)throw new Error("Trackerizr must be initialized first (use Trackerizr.init())");try{if(navigator.onLine&&"undefined"!=typeof localStorage){for(var t=[],n=[],r=0;r0){t.forEach(function(e){localStorage.removeItem(e)});var s={events:[],from_offline_buffer:!0,user:this.userManager.getUser()};n.forEach(function(e){s.events=s.events.concat(e.data.events)});var f={headers:o({},g,this.apiKey),timeout:T},p=a(this.apiBaseUrl,this.apiEndpoint);c.default.post(p,s,f).then(function(e){207===e.status&&(console.warn("Your batch has been partially created, some events are in error"),console.error(e.data.data))}).catch(function(t){"ECONNABORTED"!==t.code&&"Network Error"!==t.message||null===e.offlineBufferTimer||"undefined"==typeof localStorage||n.forEach(function(e){var t=""+j+e.timestamp,n=JSON.stringify(e);localStorage.setItem(t,n)}),t.response&&400===t.response.status&&console.error("Your batch has been rejected, event is in error")})}}}catch(e){}}}},{key:"activateGeolocation",value:function(){var e=this,t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];if(this.__validateNavigatorEnvironment()&&navigator.geolocation)if(t){var n={enableHighAccuracy:!0};this.geolocation.watcher=navigator.geolocation.watchPosition(function(t){e.geolocation.coords=t.coords},function(e){},n)}else null!==this.geolocation.watcher&&(navigator.geolocation.clearWatch(this.geolocation.watcher),this.geolocation.watcher=null)}},{key:"activateOfflineBuffering",value:function(){var e=this,t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];this.__validateNavigatorEnvironment()&&(t?this.offlineBufferTimer=setInterval(function(){e.tryFlushOfflineBuffer()},x):null!==this.offlineBufferTimer&&(clearInterval(this.offlineBufferTimer),this.offlineBufferTimer=null))}}]),e}();t.default=S,e.exports=t.default},function(e,t,n){"use strict";function r(e){return e&&e.__esModule?e:{default:e}}function o(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(t,"__esModule",{value:!0});var i=function(){function e(e,t){for(var n=0;n=t?e:t)),e}function r(e){if("string"==typeof e)return e;if(a(e))return k?k.call(e):"";var t=e+"";return"0"==t&&1/e==-p?"-0":t}function o(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function i(e){return!!e&&"object"==typeof e}function a(e){return"symbol"==typeof e||i(e)&&j.call(e)==v}function u(e){if(!e)return 0===e?e:0;if(e=c(e),e===p||e===-p){var t=e<0?-1:1;return t*d}return e===e?e:0}function s(e){var t=u(e),n=t%1;return t===t?n?t-n:t:0}function c(e){if("number"==typeof e)return e;if(a(e))return h;if(o(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(m,"");var n=g.test(e);return n||w.test(e)?b(e.slice(2),n?2:8):y.test(e)?h:+e}function f(e){return null==e?"":r(e)}function l(e,t,o){return e=f(e),o=n(s(o),0,e.length),t=r(t),e.slice(o,o+t.length)==t}var p=1/0,d=1.7976931348623157e308,h=NaN,v="[object Symbol]",m=/^\s+|\s+$/g,y=/^[-+]0x[0-9a-f]+$/i,g=/^0b[01]+$/i,w=/^0o[0-7]+$/i,b=parseInt,x="object"==typeof t&&t&&t.Object===Object&&t,T="object"==typeof self&&self&&self.Object===Object&&self,E=x||T||Function("return this")(),_=Object.prototype,j=_.toString,S=E.Symbol,O=S?S.prototype:void 0,k=O?O.toString:void 0;e.exports=l}).call(t,function(){return this}())},function(e,t){(function(t){function n(e,t,n){function r(t){var n=v,r=m;return v=m=void 0,_=t,g=e.apply(r,n)}function i(e){return _=e,w=setTimeout(f,t),j?r(e):g}function a(e){var n=e-b,r=e-_,o=t-n;return S?T(o,y-r):o}function c(e){var n=e-b,r=e-_;return void 0===b||n>=t||n<0||S&&r>=y}function f(){var e=E();return c(e)?l(e):void(w=setTimeout(f,a(e)))}function l(e){return w=void 0,O&&v?r(e):(v=m=void 0,g)}function p(){void 0!==w&&clearTimeout(w),_=0,v=b=m=w=void 0}function d(){return void 0===w?g:l(E())}function h(){var e=E(),n=c(e);if(v=arguments,m=this,b=e,n){if(void 0===w)return i(b);if(S)return w=setTimeout(f,t),r(b)}return void 0===w&&(w=setTimeout(f,t)),g}var v,m,y,g,w,b,_=0,j=!1,S=!1,O=!0;if("function"!=typeof e)throw new TypeError(s);return t=u(t)||0,o(n)&&(j=!!n.leading,S="maxWait"in n,y=S?x(u(n.maxWait)||0,t):y,O="trailing"in n?!!n.trailing:O),h.cancel=p,h.flush=d,h}function r(e,t,r){var i=!0,a=!0;if("function"!=typeof e)throw new TypeError(s);return o(r)&&(i="leading"in r?!!r.leading:i,a="trailing"in r?!!r.trailing:a),n(e,t,{leading:i,maxWait:t,trailing:a})}function o(e){var t=typeof e;return!!e&&("object"==t||"function"==t)}function i(e){return!!e&&"object"==typeof e}function a(e){return"symbol"==typeof e||i(e)&&b.call(e)==f}function u(e){if("number"==typeof e)return e;if(a(e))return c;if(o(e)){var t="function"==typeof e.valueOf?e.valueOf():e;e=o(t)?t+"":t}if("string"!=typeof e)return 0===e?e:+e;e=e.replace(l,"");var n=d.test(e);return n||h.test(e)?v(e.slice(2),n?2:8):p.test(e)?c:+e}var s="Expected a function",c=NaN,f="[object Symbol]",l=/^\s+|\s+$/g,p=/^[-+]0x[0-9a-f]+$/i,d=/^0b[01]+$/i,h=/^0o[0-7]+$/i,v=parseInt,m="object"==typeof t&&t&&t.Object===Object&&t,y="object"==typeof self&&self&&self.Object===Object&&self,g=m||y||Function("return this")(),w=Object.prototype,b=w.toString,x=Math.max,T=Math.min,E=function(){return g.Date.now()};e.exports=r}).call(t,function(){return this}())},function(e,t){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function o(e){if(f===setTimeout)return setTimeout(e,0);if((f===n||!f)&&setTimeout)return f=setTimeout,setTimeout(e,0);try{return f(e,0)}catch(t){try{return f.call(null,e,0)}catch(t){return f.call(this,e,0)}}}function i(e){if(l===clearTimeout)return clearTimeout(e);if((l===r||!l)&&clearTimeout)return l=clearTimeout,clearTimeout(e);try{return l(e)}catch(t){try{return l.call(null,e)}catch(t){return l.call(this,e)}}}function a(){v&&d&&(v=!1,d.length?h=d.concat(h):m=-1,h.length&&u())}function u(){if(!v){var e=o(a);v=!0;for(var t=h.length;t;){for(d=h,h=[];++m1)for(var n=1;n