From 850d634b84eeac01160a984e6551fc0533354cc1 Mon Sep 17 00:00:00 2001 From: Daniel Jih Date: Wed, 13 Sep 2017 17:42:34 -0700 Subject: [PATCH] add setSessionId method --- CHANGELOG.md | 2 ++ amplitude-segment-snippet.min.js | 2 +- amplitude-snippet.min.js | 10 ++++----- amplitude.js | 13 +++++++++++ amplitude.min.js | 2 +- src/amplitude-client.js | 13 +++++++++++ src/amplitude-snippet.js | 2 +- test/amplitude-client.js | 38 ++++++++++++++++++++++++++++++++ 8 files changed, 74 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 773adfc7..92c70598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Unreleased +* Add `setSessionId(sesionId)` method. Note this is not recommended unless you know what are you doing. + ### 3.6.0 (September 13, 2017) * Supports clean NPM module loading eg: `const amplitude = require('amplitude');` or `import 'amplitude' from 'amplitude-js';` diff --git a/amplitude-segment-snippet.min.js b/amplitude-segment-snippet.min.js index 1f555960..1197609b 100644 --- a/amplitude-segment-snippet.min.js +++ b/amplitude-segment-snippet.min.js @@ -7,7 +7,7 @@ var i=function(){this._q=[];return this} ;return this} ;var u=["setProductId","setQuantity","setPrice","setRevenueType","setEventProperties"] ;for(var c=0;cr.MAX_STRING_LENGTH?t.substring(0,r.MAX_STRING_LENGTH):t},f=function(t,e,n){return o(t)===n||(i("Invalid "+e+" input type. Expected "+n+" but received "+o(t)),!1)},p=function(t){var e=o(t);if("object"!==e)return i("Error: invalid properties format. Expecting Javascript object, received "+e+", ignoring"),{};if(Object.keys(t).length>r.MAX_PROPERTY_KEYS)return i("Error: too many properties (more than 1000), ignoring"),{};var n={};for(var s in t)if(t.hasOwnProperty(s)){var a=s,u=o(a);"string"!==u&&(a=String(a),i("WARNING: Non-string property key, received type "+u+', coercing to string "'+a+'"'));var c=h(a,t[s]);null!==c&&(n[a]=c)}return n},l=["null","nan","undefined","function","arguments","regexp","element"],h=function t(e,n){var r=o(n);if(-1!==l.indexOf(r))i('WARNING: Property key "'+e+'" with invalid value type '+r+", ignoring"),n=null;else if("error"===r)n=String(n),i('WARNING: Property key "'+e+'" with value type error, coercing to '+n);else if("array"===r){for(var s=[],a=0;a0?(this.userPropertiesOperations.hasOwnProperty("$clearAll")||o.log("Need to send $clearAll on its own Identify object without any other operations, skipping $clearAll"),this):(this.userPropertiesOperations.$clearAll="-",this)},i.prototype.prepend=function(t,e){return this._addOperation("$prepend",t,e),this},i.prototype.set=function(t,e){return this._addOperation("$set",t,e),this},i.prototype.setOnce=function(t,e){return this._addOperation("$setOnce",t,e),this},i.prototype.unset=function(t){return this._addOperation("$unset",t,"-"),this},i.prototype._addOperation=function(t,e,n){return this.userPropertiesOperations.hasOwnProperty("$clearAll")?void o.log("This identify already contains a $clearAll operation, skipping operation "+t):-1!==this.properties.indexOf(e)?void o.log('User property "'+e+'" already used in this identify, skipping operation '+t):(this.userPropertiesOperations.hasOwnProperty(t)||(this.userPropertiesOperations[t]={}),this.userPropertiesOperations[t][e]=n,void this.properties.push(e))},t.exports=i},function(t,e,n){var r=n(14),o=n(57),i=n(58),s=n(8),a=n(24),u=n(67),c=Object.prototype,f=c.hasOwnProperty,p=i(function(t,e){if(a(e)||s(e))return void o(e,u(e),t);for(var n in e)f.call(e,n)&&r(t,n,e[n])});t.exports=p},function(t,e,n){function r(t,e,n){var r=t[e];a.call(t,e)&&i(r,n)&&(void 0!==n||e in t)||o(t,e,n)}var o=n(15),i=n(20),s=Object.prototype,a=s.hasOwnProperty;t.exports=r},function(t,e,n){function r(t,e,n){"__proto__"==e&&o?o(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}var o=n(16);t.exports=r},function(t,e,n){var r=n(49),o=function(){try{var t=r(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=o},function(t,e,n){function r(t){if(!i(t))return!1;var e=o(t);return e==a||e==u||e==s||e==c}var o=n(5),i=n(7),s="[object AsyncFunction]",a="[object Function]",u="[object GeneratorFunction]",c="[object Proxy]";t.exports=r},function(t,e,n){var r=n(6),o=r.Symbol;t.exports=o},function(t,e,n){(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.exports=n}).call(e,n(4))},function(t,e){function n(t,e){return t===e||t!==t&&e!==e}t.exports=n},function(t,e){function n(t){return t}t.exports=n},function(t,e){function n(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=r}var r=9007199254740991;t.exports=n},function(t,e){function n(t,e){return!!(e=null==e?r:e)&&("number"==typeof t||o.test(t))&&t>-1&&t%1==0&&t1)))/4)-b((t-1901+e)/100)+b((t-1601+e)/400)};if((d=y.hasOwnProperty)||(d=function(t){var e,n={};return(n.__proto__=null,n.__proto__={toString:1},n).toString!=m?d=function(t){var e=this.__proto__,n=t in(this.__proto__=null,this);return this.__proto__=e,n}:(e=n.constructor,d=function(t){var n=(this.constructor||e).prototype;return t in this&&!(t in n&&this[t]===n[t])}),n=null,d.call(this,t)}),g=function(t,e){var n,r,o,i=0;(n=function(){this.valueOf=0}).prototype.valueOf=0,r=new n;for(o in r)d.call(r,o)&&i++;return n=r=null,i?g=2==i?function(t,e){var n,r={},o="[object Function]"==m.call(t);for(n in t)o&&"prototype"==n||d.call(r,n)||!(r[n]=1)||!d.call(t,n)||e(n)}:function(t,e){var n,r,o="[object Function]"==m.call(t);for(n in t)o&&"prototype"==n||!d.call(t,n)||(r="constructor"===n)||e(n);(r||d.call(t,n="constructor"))&&e(n)}:(r=["valueOf","toString","toLocaleString","propertyIsEnumerable","isPrototypeOf","hasOwnProperty","constructor"],g=function(t,e){var n,o,i="[object Function]"==m.call(t),s=!i&&"function"!=typeof t.constructor&&a[typeof t.hasOwnProperty]&&t.hasOwnProperty||d;for(n in t)i&&"prototype"==n||!s.call(t,n)||e(n);for(o=r.length;n=r[--o];s.call(t,n)&&e(n));}),g(t,e)},!n("json-stringify")){var S={92:"\\\\",34:'\\"',8:"\\b",12:"\\f",10:"\\n",13:"\\r",9:"\\t"},A=function(t,e){return("000000"+(e||0)).slice(-t)},C=function(t){for(var e='"',n=0,r=t.length,o=!_||r>10,i=o&&(_?t.split(""):t);n-1/0&&a<1/0){if(I){for(l=b(a/864e5),c=b(l/365.2425)+1970-1;I(c+1,0)<=l;c++);for(f=b((l-I(c,0))/30.42);I(c,f+1)<=l;f++);l=1+l-I(c,f),h=(a%864e5+864e5)%864e5,y=b(h/36e5)%24,w=b(h/6e4)%60,_=b(h/1e3)%60,E=h%1e3}else c=a.getUTCFullYear(),f=a.getUTCMonth(),l=a.getUTCDate(),y=a.getUTCHours(),w=a.getUTCMinutes(),_=a.getUTCSeconds(),E=a.getUTCMilliseconds();a=(c<=0||c>=1e4?(c<0?"-":"+")+A(6,c<0?-c:c):A(4,c))+"-"+A(2,f+1)+"-"+A(2,l)+"T"+A(2,y)+":"+A(2,w)+":"+A(2,_)+"."+A(3,E)+"Z"}else a=null;if(n&&(a=n.call(e,t,a)),null===a)return"null";if("[object Boolean]"==(u=m.call(a)))return""+a;if("[object Number]"==u)return a>-1/0&&a<1/0?""+a:"null";if("[object String]"==u)return C(""+a);if("object"==typeof a){for(N=s.length;N--;)if(s[N]===a)throw p();if(s.push(a),S=[],R=i,i+=o,"[object Array]"==u){for(O=0,N=a.length;O0)for(r="",n>10&&(n=10);r.length=48&&o<=57||o>=97&&o<=102||o>=65&&o<=70||P();t+=N("0x"+i.slice(e,T));break;default:P()}else{if(34==o)break;for(o=i.charCodeAt(T),e=T;o>=32&&92!=o&&34!=o;)o=i.charCodeAt(++T);t+=i.slice(e,T)}if(34==i.charCodeAt(T))return T++,t;P();default:if(e=T,45==o&&(r=!0,o=i.charCodeAt(++T)),o>=48&&o<=57){for(48==o&&(o=i.charCodeAt(T+1))>=48&&o<=57&&P(),r=!1;T=48&&o<=57;T++);if(46==i.charCodeAt(T)){for(n=++T;n=48&&o<=57;n++);n==T&&P(),T=n}if(101==(o=i.charCodeAt(T))||69==o){for(o=i.charCodeAt(++T),43!=o&&45!=o||T++,n=T;n=48&&o<=57;n++);n==T&&P(),T=n}return+i.slice(e,T)}if(r&&P(),"true"==i.slice(T,T+4))return T+=4,!0;if("false"==i.slice(T,T+5))return T+=5,!1;if("null"==i.slice(T,T+4))return T+=4,null;P()}return"$"},U=function(t){var e,n;if("$"==t&&P(),"string"==typeof t){if("@"==(_?t.charAt(0):t[0]))return t.slice(1);if("["==t){for(e=[];"]"!=(t=j());n||(n=!0))n&&(","==t?"]"==(t=j())&&P():P()),","==t&&P(),e.push(U(t));return e}if("{"==t){for(e={};"}"!=(t=j());n||(n=!0))n&&(","==t?"}"==(t=j())&&P():P()),","!=t&&"string"==typeof t&&"@"==(_?t.charAt(0):t[0])&&":"==j()||P(),e[t.slice(1)]=U(j());return e}P()}return t},k=function(t,e,n){var r=F(t,e,n);r===v?delete t[e]:t[e]=r},F=function(t,e,n){var r,o=t[e];if("object"==typeof o&&o)if("[object Array]"==m.call(o))for(r=o.length;r--;)k(o,r,n);else g(o,function(t){k(o,t,n)});return n.call(t,e,o)};e.parse=function(t,e){var n,r;return T=0,O=""+t,n=U(j()),"$"!=j()&&P(),T=O=null,e&&"[object Function]"==m.call(e)?F((r={},r[""]=n,r),"",e):n}}}return e.runInContext=i,e}var s=n(10),a={function:!0,object:!0},u=a[typeof e]&&e&&!e.nodeType&&e,c=a[typeof window]&&window||this,f=u&&a[typeof t]&&t&&!t.nodeType&&"object"==typeof r&&r;if(!f||f.global!==f&&f.window!==f&&f.self!==f||(c=f),u&&!s)i(c,u);else{var p=c.JSON,l=c.JSON3,h=!1,d=i(c,c.JSON3={noConflict:function(){return h||(h=!0,c.JSON=p,c.JSON3=l,p=l=null),d}});c.JSON={parse:d.parse,stringify:d.stringify}}s&&void 0!==(o=function(){return d}.call(e,n,e,t))&&(t.exports=o)}).call(this)}).call(e,n(3)(t),n(4))},function(t,e,n){"use strict";var r=n(31),o=n(1),i=n(12),s=n(13),a=n(25),u=n(2),c=n(0),f=n(26),p=n(27),l=function(){this.options=s({},p),this._q=[],this._instances={}};l.prototype.Identify=i,l.prototype.Revenue=a,l.prototype.getInstance=function(t){t=c.isEmptyString(t)?o.DEFAULT_INSTANCE:t.toLowerCase();var e=this._instances[t];return void 0===e&&(e=new r(t),this._instances[t]=e),e},l.prototype.init=function(t,e,n,r){this.getInstance().init(t,e,n,function(t){this.options=t.options,"function"===u(r)&&r(t)}.bind(this))},l.prototype.runQueuedFunctions=function(){for(var t=0;tthis.options.sessionTimeout)&&(this._newSession=!0,this._sessionId=p,this.options.saveParamsReferrerOncePerSession&&this._trackParamsAndReferrer()),this.options.saveParamsReferrerOncePerSession||this._trackParamsAndReferrer(),this._lastEventTime=p,E(this),this._sendEventsIfReady()}catch(t){d.log(t)}finally{"function"===l(o)&&o(this)}},m.prototype._trackParamsAndReferrer=function(){this.options.includeUtm&&this._initUtmData(),this.options.includeReferrer&&this._saveReferrer(this._getReferrer()),this.options.includeGclid&&this._saveGclid(this._getUrlParams())};var w=function(t,e){if("object"===l(e)){for(var n in e)e.hasOwnProperty(n)&&function(n){if(y.hasOwnProperty(n)){var r=e[n],o=l(y[n]);d.validateInput(r,n+" option",o)&&("boolean"===o?t[n]=!!r:("string"===o&&!d.isEmptyString(r)||"number"===o&&r>0)&&(t[n]=r))}}(n)}};m.prototype.runQueuedFunctions=function(){for(var t=0;t=this.options.eventUploadThreshold?(this.sendEvents(t),!0):(this._updateScheduled||(this._updateScheduled=!0,setTimeout(function(){this._updateScheduled=!1,this.sendEvents()}.bind(this),this.options.eventUploadPeriodMillis)),!1):(this.sendEvents(t),!0))},m.prototype._getFromStorage=function(t,e){return t.getItem(e+this._storageSuffix)},m.prototype._setInStorage=function(t,e,n){t.setItem(e+this._storageSuffix,n)};var _=function(t){var e=t.cookieStorage.get(t.options.cookieName);if(!("object"===l(e)&&e.deviceId&&e.sessionId&&e.lastEventTime)){var n=function(t){var e=a.getItem(t);return a.removeItem(t),e},o="string"===l(t.options.apiKey)&&"_"+t.options.apiKey.slice(0,6)||"",i=n(r.DEVICE_ID+o),s=n(r.USER_ID+o),u=n(r.OPT_OUT+o);null!==u&&void 0!==u&&(u="true"===String(u));var c=parseInt(n(r.SESSION_ID)),f=parseInt(n(r.LAST_EVENT_TIME)),p=parseInt(n(r.LAST_EVENT_ID)),h=parseInt(n(r.LAST_IDENTIFY_ID)),d=parseInt(n(r.LAST_SEQUENCE_NUMBER)),g=function(t){return"object"===l(e)&&e[t]};t.options.deviceId=g("deviceId")||i,t.options.userId=g("userId")||s,t._sessionId=g("sessionId")||c||t._sessionId,t._lastEventTime=g("lastEventTime")||f||t._lastEventTime,t._eventId=g("eventId")||p||t._eventId,t._identifyId=g("identifyId")||h||t._identifyId,t._sequenceNumber=g("sequenceNumber")||d||t._sequenceNumber,t.options.optOut=u||!1,e&&void 0!==e.optOut&&null!==e.optOut&&(t.options.optOut="true"===String(e.optOut)),E(t)}},b=function(t){var e=t.cookieStorage.get(t.options.cookieName+t._storageSuffix);"object"===l(e)&&(e.deviceId&&(t.options.deviceId=e.deviceId),e.userId&&(t.options.userId=e.userId),null!==e.optOut&&void 0!==e.optOut&&(t.options.optOut=e.optOut),e.sessionId&&(t._sessionId=parseInt(e.sessionId)),e.lastEventTime&&(t._lastEventTime=parseInt(e.lastEventTime)),e.eventId&&(t._eventId=parseInt(e.eventId)),e.identifyId&&(t._identifyId=parseInt(e.identifyId)),e.sequenceNumber&&(t._sequenceNumber=parseInt(e.sequenceNumber)))},E=function(t){t.cookieStorage.set(t.options.cookieName+t._storageSuffix,{deviceId:t.options.deviceId,userId:t.options.userId,optOut:t.options.optOut,sessionId:t._sessionId,lastEventTime:t._lastEventTime,eventId:t._eventId,identifyId:t._identifyId,sequenceNumber:t._sequenceNumber})};m.prototype._initUtmData=function(t,e){t=t||this._getUrlParams(),e=e||this.cookieStorage.get("__utmz");var n=i(e,t);I(this,n)};var I=function(t,e){if("object"===l(e)&&0!==Object.keys(e).length){var n=new s;for(var r in e)e.hasOwnProperty(r)&&(n.setOnce("initial_"+r,e[r]),n.set(r,e[r]));t.identify(n)}};m.prototype._getReferrer=function(){return document.referrer},m.prototype._getUrlParams=function(){return location.search},m.prototype._saveGclid=function(t){var e=d.getQueryParam("gclid",t);if(!d.isEmptyString(e)){I(this,{gclid:e})}},m.prototype._getDeviceIdFromUrlParam=function(t){return d.getQueryParam(r.AMP_DEVICE_ID_PARAM,t)},m.prototype._getReferringDomain=function(t){if(d.isEmptyString(t))return null;var e=t.split("/");return e.length>=3?e[2]:null},m.prototype._saveReferrer=function(t){if(!d.isEmptyString(t)){var e={referrer:t,referring_domain:this._getReferringDomain(t)};I(this,e)}},m.prototype.saveEvents=function(){try{this._setInStorage(a,this.options.unsentKey,JSON.stringify(this._unsentEvents))}catch(t){}try{this._setInStorage(a,this.options.unsentIdentifyKey,JSON.stringify(this._unsentIdentifys))}catch(t){}},m.prototype.setDomain=function(t){if(d.validateInput(t,"domain","string"))try{this.cookieStorage.options({domain:t}),this.options.domain=this.cookieStorage.options().domain,b(this),E(this)}catch(t){d.log(t)}},m.prototype.setUserId=function(t){try{this.options.userId=void 0!==t&&null!==t&&""+t||null,E(this)}catch(t){d.log(t)}},m.prototype.setGroup=function(t,e){if(this._apiKeySet("setGroup()")&&d.validateInput(t,"groupType","string")&&!d.isEmptyString(t)){var n={};n[t]=e;var o=(new s).set(t,e);this._logEvent(r.IDENTIFY_EVENT,null,null,o.userPropertiesOperations,n,null,null)}},m.prototype.setOptOut=function(t){if(d.validateInput(t,"enable","boolean"))try{this.options.optOut=t,E(this)}catch(t){d.log(t)}},m.prototype.regenerateDeviceId=function(){this.setDeviceId(g()+"R")},m.prototype.setDeviceId=function(t){if(d.validateInput(t,"deviceId","string"))try{d.isEmptyString(t)||(this.options.deviceId=""+t,E(this))}catch(t){d.log(t)}},m.prototype.setUserProperties=function(t){if(this._apiKeySet("setUserProperties()")&&d.validateInput(t,"userProperties","object")){var e=d.truncate(d.validateProperties(t));if(0!==Object.keys(e).length){var n=new s;for(var r in e)e.hasOwnProperty(r)&&n.set(r,e[r]);this.identify(n)}}},m.prototype.clearUserProperties=function(){if(this._apiKeySet("clearUserProperties()")){var t=new s;t.clearAll(),this.identify(t)}};var S=function(t,e){for(var n=0;n0)return this._logEvent(r.IDENTIFY_EVENT,null,null,t.userPropertiesOperations,null,null,e)}else d.log("Invalid identify input type. Expected Identify object but saw "+l(t));"function"===l(e)&&e(0,"No request sent")},m.prototype.setVersionName=function(t){d.validateInput(t,"versionName","string")&&(this.options.versionName=t)},m.prototype._logEvent=function(t,e,n,o,i,s,a){if(b(this),!t||this.options.optOut)return void("function"===l(a)&&a(0,"No request sent"));try{var u;u=t===r.IDENTIFY_EVENT?this.nextIdentifyId():this.nextEventId();var c=this.nextSequenceNumber(),f="number"===l(s)?s:(new Date).getTime();(!this._sessionId||!this._lastEventTime||f-this._lastEventTime>this.options.sessionTimeout)&&(this._sessionId=f),this._lastEventTime=f,E(this),o=o||{},n=n||{},e=e||{},i=i||{};var p={device_id:this.options.deviceId,user_id:this.options.userId,timestamp:f,event_id:u,session_id:this._sessionId||-1,event_type:t,version_name:this.options.versionName||null,platform:this.options.platform,os_name:this._ua.browser.name||null,os_version:this._ua.browser.major||null,device_model:this._ua.os.name||null,language:this.options.language,api_properties:n,event_properties:d.truncate(d.validateProperties(e)),user_properties:d.truncate(d.validateProperties(o)),uuid:g(),library:{name:"amplitude-js",version:v},sequence_number:c,groups:d.truncate(d.validateGroups(i)),user_agent:this._userAgent};return t===r.IDENTIFY_EVENT?(this._unsentIdentifys.push(p),this._limitEventsQueued(this._unsentIdentifys)):(this._unsentEvents.push(p),this._limitEventsQueued(this._unsentEvents)),this.options.saveEvents&&this.saveEvents(),this._sendEventsIfReady(a)||"function"!==l(a)||a(0,"No request sent"),u}catch(t){d.log(t)}},m.prototype._limitEventsQueued=function(t){t.length>this.options.savedMaxCount&&t.splice(0,t.length-this.options.savedMaxCount)},m.prototype.logEvent=function(t,e,n){return this.logEventWithTimestamp(t,e,null,n)},m.prototype.logEventWithTimestamp=function(t,e,n,r){return this._apiKeySet("logEvent()")&&d.validateInput(t,"eventType","string")&&!d.isEmptyString(t)?this._logEvent(t,e,null,null,null,n,r):("function"===l(r)&&r(0,"No request sent"),-1)},m.prototype.logEventWithGroups=function(t,e,n,r){return this._apiKeySet("logEventWithGroup()")&&d.validateInput(t,"eventType","string")?this._logEvent(t,e,null,null,n,null,r):("function"===l(r)&&r(0,"No request sent"),-1)};var A=function(t){return!isNaN(parseFloat(t))&&isFinite(t)};m.prototype.logRevenueV2=function(t){if(this._apiKeySet("logRevenueV2()"))if("object"===l(t)&&t.hasOwnProperty("_q")&&(t=S(new p,t)),t instanceof p){if(t&&t._isValidRevenue())return this.logEvent(r.REVENUE_EVENT,t._toJSONObject())}else d.log("Invalid revenue input type. Expected Revenue object but saw "+l(t))},m.prototype.logRevenue=function(t,e,n){return this._apiKeySet("logRevenue()")&&A(t)&&(void 0===e||A(e))?this._logEvent(r.REVENUE_EVENT,{},{productId:n,special:"revenue_amount",quantity:e||1,price:t},null,null,null,null):-1},m.prototype.removeEvents=function(t,e){C(this,"_unsentEvents",t),C(this,"_unsentIdentifys",e)};var C=function(t,e,n){if(!(n<0)){for(var r=[],o=0;on&&r.push(t[e][o]);t[e]=r}};m.prototype.sendEvents=function(t){if(!this._apiKeySet("sendEvents()")||this._sending||this.options.optOut||0===this._unsentCount())return void("function"===l(t)&&t(0,"No request sent"));this._sending=!0;var e=this.options.forceHttps?"https":"https:"===window.location.protocol?"https":"http",n=e+"://"+this.options.apiEndpoint+"/",o=Math.min(this._unsentCount(),this.options.uploadBatchSize),i=this._mergeEventsAndIdentifys(o),s=i.maxEventId,a=i.maxIdentifyId,c=JSON.stringify(i.eventsToSend),p=(new Date).getTime(),h={client:this.options.apiKey,e:c,v:r.API_VERSION,upload_time:p,checksum:u(r.API_VERSION+this.options.apiKey+c+p)},d=this;new f(n,h).send(function(e,n){d._sending=!1;try{200===e&&"success"===n?(d.removeEvents(s,a),d.options.saveEvents&&d.saveEvents(),d._sendEventsIfReady(t)||"function"!==l(t)||t(e,n)):413===e?(1===d.options.uploadBatchSize&&d.removeEvents(s,a),d.options.uploadBatchSize=Math.ceil(o/2),d.sendEvents(t)):"function"===l(t)&&t(e,n)}catch(t){}})},m.prototype._mergeEventsAndIdentifys=function(t){for(var e=[],n=0,r=-1,o=0,i=-1;e.length=this._unsentIdentifys.length,u=n>=this._unsentEvents.length;if(u&&a){d.log("Merging Events and Identifys, less events and identifys than expected");break}a?(s=this._unsentEvents[n++],r=s.event_id):u?(s=this._unsentIdentifys[o++],i=s.event_id):!("sequence_number"in this._unsentEvents[n])||this._unsentEvents[n].sequence_number>2,a=(3&e)<<4|n>>4,u=(15&n)<<2|i>>6,c=63&i,isNaN(n)?u=c=64:isNaN(i)&&(c=64),f=f+o._keyStr.charAt(s)+o._keyStr.charAt(a)+o._keyStr.charAt(u)+o._keyStr.charAt(c);return f},decode:function(t){try{if(window.btoa&&window.atob)return decodeURIComponent(escape(window.atob(t)))}catch(t){}return o._decode(t)},_decode:function(t){var e,n,i,s,a,u,c,f="",p=0;for(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");p>4,n=(15&a)<<4|u>>2,i=(3&u)<<6|c,f+=String.fromCharCode(e),64!==u&&(f+=String.fromCharCode(n)),64!==c&&(f+=String.fromCharCode(i));return f=r.decode(f)}};t.exports=o},function(t,e,n){"use strict";var r={encode:function(t){for(var e="",n=0;n127&&r<2048?(e+=String.fromCharCode(r>>6|192),e+=String.fromCharCode(63&r|128)):(e+=String.fromCharCode(r>>12|224),e+=String.fromCharCode(r>>6&63|128),e+=String.fromCharCode(63&r|128))}return e},decode:function(t){for(var e="",n=0,r=0,o=0,i=0;n191&&r<224?(o=t.charCodeAt(n+1),e+=String.fromCharCode((31&r)<<6|63&o),n+=2):(o=t.charCodeAt(n+1),i=t.charCodeAt(n+2),e+=String.fromCharCode((15&r)<<12|(63&o)<<6|63&i),n+=3);return e}};t.exports=r},function(t,e,n){"use strict";function r(t){for(var n=e.cookie,r=e.levels(t),o=0;o=0;--s)i.push(n.slice(s).join("."));return i},r.cookie=i,e=t.exports=r},function(t,e){function n(t){switch(t){case"http:":return 80;case"https:":return 443;default:return location.port}}e.parse=function(t){var e=document.createElement("a");return e.href=t,{href:e.href,host:e.host||location.host,port:"0"===e.port||""===e.port?n(e.protocol):e.port,hash:e.hash,hostname:e.hostname||location.hostname,pathname:"/"!=e.pathname.charAt(0)?"/"+e.pathname:e.pathname,protocol:e.protocol&&":"!=e.protocol?e.protocol:location.protocol,search:e.search,query:e.search.slice(1)}},e.isAbsolute=function(t){return 0==t.indexOf("//")||!!~t.indexOf("://")},e.isRelative=function(t){return!e.isAbsolute(t)},e.isCrossDomain=function(t){t=e.parse(t);var n=e.parse(window.location.href);return t.hostname!==n.hostname||t.port!==n.port||t.protocol!==n.protocol}},function(t,e,n){function r(t,e,n){n=n||{};var r=a(t)+"="+a(e);null==e&&(n.maxage=-1),n.maxage&&(n.expires=new Date(+new Date+n.maxage)),n.path&&(r+="; path="+n.path),n.domain&&(r+="; domain="+n.domain),n.expires&&(r+="; expires="+n.expires.toUTCString()),n.secure&&(r+="; secure"),document.cookie=r}function o(){var t;try{t=document.cookie}catch(t){return"undefined"!=typeof console&&"function"==typeof console.error&&console.error(t.stack||t),{}}return s(t)}function i(t){return o()[t]}function s(t){var e,n={},r=t.split(/ *; */);if(""==r[0])return n;for(var o=0;o=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function i(t){var n=this.useColors;if(t[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+t[0]+(n?"%c ":" ")+"+"+e.humanize(this.diff),n){var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var o=0,i=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&(o++,"%c"===t&&(i=o))}),t.splice(i,0,r)}}function s(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function a(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(t){}}function u(){var t;try{t=e.storage.debug}catch(t){}return!t&&void 0!==r&&"env"in r&&(t=r.env.DEBUG),t}e=t.exports=n(41),e.log=s,e.formatArgs=i,e.save=a,e.load=u,e.useColors=o,e.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(t){}}(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},e.enable(u())}).call(e,n(40))},function(t,e){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function o(t){if(f===setTimeout)return setTimeout(t,0);if((f===n||!f)&&setTimeout)return f=setTimeout,setTimeout(t,0);try{return f(t,0)}catch(e){try{return f.call(null,t,0)}catch(e){return f.call(this,t,0)}}}function i(t){if(p===clearTimeout)return clearTimeout(t);if((p===r||!p)&&clearTimeout)return p=clearTimeout,clearTimeout(t);try{return p(t)}catch(e){try{return p.call(null,t)}catch(e){return p.call(this,t)}}}function s(){g&&h&&(g=!1,h.length?d=h.concat(d):v=-1,d.length&&a())}function a(){if(!g){var t=o(s);g=!0;for(var e=d.length;e;){for(h=d,d=[];++v1)for(var n=1;n100)){var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(e){var n=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*f;case"days":case"day":case"d":return n*c;case"hours":case"hour":case"hrs":case"hr":case"h":return n*u;case"minutes":case"minute":case"mins":case"min":case"m":return n*a;case"seconds":case"second":case"secs":case"sec":case"s":return n*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function r(t){return t>=c?Math.round(t/c)+"d":t>=u?Math.round(t/u)+"h":t>=a?Math.round(t/a)+"m":t>=s?Math.round(t/s)+"s":t+"ms"}function o(t){return i(t,c,"day")||i(t,u,"hour")||i(t,a,"minute")||i(t,s,"second")||t+" ms"}function i(t,e,n){if(!(t0)return n(t);if("number"===i&&!1===isNaN(t))return e.long?o(t):r(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},function(t,e,n){"use strict";(function(t){function r(){return i.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(r()=r())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r().toString(16)+" bytes");return 0|t}function g(t){return+t!=t&&(t=0),i.alloc(+t)}function v(t,e){if(i.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return z(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return J(t).length;default:if(r)return z(t).length;e=(""+e).toLowerCase(),r=!0}}function y(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,e>>>=0,n<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,n);case"utf8":case"utf-8":return T(this,e,n);case"ascii":return N(this,e,n);case"latin1":case"binary":return R(this,e,n);case"base64":return x(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function m(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function w(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=i.from(e,r)),i.isBuffer(e))return 0===e.length?-1:_(t,e,n,r,o);if("number"==typeof e)return e&=255,i.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):_(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function _(t,e,n,r,o){function i(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,u=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,n/=2}var c;if(o){var f=-1;for(c=n;ca&&(n=a-u),c=n;c>=0;c--){for(var p=!0,l=0;lo&&(r=o):r=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s239?4:i>223?3:i>191?2:1;if(o+a<=n){var u,c,f,p;switch(a){case 1:i<128&&(s=i);break;case 2:u=t[o+1],128==(192&u)&&(p=(31&i)<<6|63&u)>127&&(s=p);break;case 3:u=t[o+1],c=t[o+2],128==(192&u)&&128==(192&c)&&(p=(15&i)<<12|(63&u)<<6|63&c)>2047&&(p<55296||p>57343)&&(s=p);break;case 4:u=t[o+1],c=t[o+2],f=t[o+3],128==(192&u)&&128==(192&c)&&128==(192&f)&&(p=(15&i)<<18|(63&u)<<12|(63&c)<<6|63&f)>65535&&p<1114112&&(s=p)}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),o+=a}return O(r)}function O(t){var e=t.length;if(e<=Z)return String.fromCharCode.apply(String,t);for(var n="",r=0;rr)&&(n=r);for(var o="",i=e;in)throw new RangeError("Trying to access beyond buffer length")}function k(t,e,n,r,o,s){if(!i.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||et.length)throw new RangeError("Index out of range")}function F(t,e,n,r){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);o>>8*(r?o:1-o)}function D(t,e,n,r){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);o>>8*(r?o:3-o)&255}function M(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function B(t,e,n,r,o){return o||M(t,e,n,4,3.4028234663852886e38,-3.4028234663852886e38),Q.write(t,e,n,r,23,4),n+4}function L(t,e,n,r,o){return o||M(t,e,n,8,1.7976931348623157e308,-1.7976931348623157e308),Q.write(t,e,n,r,52,8),n+8}function q(t){if(t=Y(t).replace(tt,""),t.length<2)return"";for(;t.length%4!=0;)t+="=";return t}function Y(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function V(t){return t<16?"0"+t.toString(16):t.toString(16)}function z(t,e){e=e||1/0;for(var n,r=t.length,o=null,i=[],s=0;s55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function G(t){for(var e=[],n=0;n>8,o=n%256,i.push(o),i.push(r);return i}function J(t){return X.toByteArray(q(t))}function $(t,e,n,r){for(var o=0;o=e.length||o>=t.length);++o)e[o+n]=t[o];return o}function W(t){return t!==t}var X=n(44),Q=n(45),H=n(46);e.Buffer=i,e.SlowBuffer=g,e.INSPECT_MAX_BYTES=50,i.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=r(),i.poolSize=8192,i._augment=function(t){return t.__proto__=i.prototype,t},i.from=function(t,e,n){return s(null,t,e,n)},i.TYPED_ARRAY_SUPPORT&&(i.prototype.__proto__=Uint8Array.prototype,i.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&i[Symbol.species]===i&&Object.defineProperty(i,Symbol.species,{value:null,configurable:!0})),i.alloc=function(t,e,n){return u(null,t,e,n)},i.allocUnsafe=function(t){return c(null,t)},i.allocUnsafeSlow=function(t){return c(null,t)},i.isBuffer=function(t){return!(null==t||!t._isBuffer)},i.compare=function(t,e){if(!i.isBuffer(t)||!i.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,s=Math.min(n,r);o0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),""},i.prototype.compare=function(t,e,n,r,o){if(!i.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,o>>>=0,this===t)return 0;for(var s=o-r,a=n-e,u=Math.min(s,a),c=this.slice(r,o),f=t.slice(e,n),p=0;po)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return b(this,t,e,n);case"utf8":case"utf-8":return E(this,t,e,n);case"ascii":return I(this,t,e,n);case"latin1":case"binary":return S(this,t,e,n);case"base64":return A(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Z=4096;i.prototype.slice=function(t,e){var n=this.length;t=~~t,e=void 0===e?n:~~e,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),e<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(o*=256);)r+=this[t+--e]*o;return r},i.prototype.readUInt8=function(t,e){return e||U(t,1,this.length),this[t]},i.prototype.readUInt16LE=function(t,e){return e||U(t,2,this.length),this[t]|this[t+1]<<8},i.prototype.readUInt16BE=function(t,e){return e||U(t,2,this.length),this[t]<<8|this[t+1]},i.prototype.readUInt32LE=function(t,e){return e||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},i.prototype.readUInt32BE=function(t,e){return e||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},i.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||U(t,e,this.length);for(var r=this[t],o=1,i=0;++i=o&&(r-=Math.pow(2,8*e)),r},i.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||U(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i},i.prototype.readInt8=function(t,e){return e||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},i.prototype.readInt16LE=function(t,e){e||U(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},i.prototype.readInt16BE=function(t,e){e||U(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},i.prototype.readInt32LE=function(t,e){return e||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},i.prototype.readInt32BE=function(t,e){return e||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},i.prototype.readFloatLE=function(t,e){return e||U(t,4,this.length),Q.read(this,t,!0,23,4)},i.prototype.readFloatBE=function(t,e){return e||U(t,4,this.length),Q.read(this,t,!1,23,4)},i.prototype.readDoubleLE=function(t,e){return e||U(t,8,this.length),Q.read(this,t,!0,52,8)},i.prototype.readDoubleBE=function(t,e){return e||U(t,8,this.length),Q.read(this,t,!1,52,8)},i.prototype.writeUIntLE=function(t,e,n,r){if(t=+t,e|=0,n|=0,!r){k(this,t,e,n,Math.pow(2,8*n)-1,0)}var o=1,i=0;for(this[e]=255&t;++i=0&&(i*=256);)this[e+o]=t/i&255;return e+n},i.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,1,255,0),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},i.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):F(this,t,e,!0),e+2},i.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):F(this,t,e,!1),e+2},i.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):D(this,t,e,!0),e+4},i.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):D(this,t,e,!1),e+4},i.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);k(this,t,e,n,o-1,-o)}var i=0,s=1,a=0;for(this[e]=255&t;++i>0)-a&255;return e+n},i.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);k(this,t,e,n,o-1,-o)}var i=n-1,s=1,a=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},i.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,1,127,-128),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},i.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):F(this,t,e,!0),e+2},i.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):F(this,t,e,!1),e+2},i.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,4,2147483647,-2147483648),i.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):D(this,t,e,!0),e+4},i.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):D(this,t,e,!1),e+4},i.prototype.writeFloatLE=function(t,e,n){return B(this,t,e,!0,n)},i.prototype.writeFloatBE=function(t,e,n){return B(this,t,e,!1,n)},i.prototype.writeDoubleLE=function(t,e,n){return L(this,t,e,!0,n)},i.prototype.writeDoubleBE=function(t,e,n){return L(this,t,e,!1,n)},i.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e=0;--o)t[o+e]=this[o+n];else if(s<1e3||!i.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,n=void 0===n?this.length:n>>>0,t||(t=0);var s;if("number"==typeof t)for(s=e;s0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function o(t){return 3*t.length/4-r(t)}function i(t){var e,n,o,i,s,a=t.length;i=r(t),s=new p(3*a/4-i),n=i>0?a-4:a;var u=0;for(e=0;e>16&255,s[u++]=o>>8&255,s[u++]=255&o;return 2===i?(o=f[t.charCodeAt(e)]<<2|f[t.charCodeAt(e+1)]>>4,s[u++]=255&o):1===i&&(o=f[t.charCodeAt(e)]<<10|f[t.charCodeAt(e+1)]<<4|f[t.charCodeAt(e+2)]>>2,s[u++]=o>>8&255,s[u++]=255&o),s}function s(t){return c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[63&t]}function a(t,e,n){for(var r,o=[],i=e;iu?u:s+16383));return 1===r?(e=t[n-1],o+=c[e>>2],o+=c[e<<4&63],o+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],o+=c[e>>10],o+=c[e>>4&63],o+=c[e<<2&63],o+="="),i.push(o),i.join("")}e.byteLength=o,e.toByteArray=i,e.fromByteArray=u;for(var c=[],f=[],p="undefined"!=typeof Uint8Array?Uint8Array:Array,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,d=l.length;h>1,f=-7,p=n?o-1:0,l=n?-1:1,h=t[e+p];for(p+=l,i=h&(1<<-f)-1,h>>=-f,f+=a;f>0;i=256*i+t[e+p],p+=l,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=r;f>0;s=256*s+t[e+p],p+=l,f-=8);if(0===i)i=1-c;else{if(i===u)return s?NaN:1/0*(h?-1:1);s+=Math.pow(2,r),i-=c}return(h?-1:1)*s*Math.pow(2,i-r)},e.write=function(t,e,n,r,o,i){var s,a,u,c=8*i-o-1,f=(1<>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:i-1,d=r?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),e+=s+p>=1?l/u:l*Math.pow(2,1-p),e*u>=2&&(s++,u/=2),s+p>=f?(a=0,s=f):s+p>=1?(a=(e*u-1)*Math.pow(2,o),s+=p):(a=e*Math.pow(2,p-1)*Math.pow(2,o),s=0));o>=8;t[n+h]=255&a,h+=d,a/=256,o-=8);for(s=s<0;t[n+h]=255&s,h+=d,s/=256,c-=8);t[n+h-d]|=128*g}},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e,n){"use strict";var r=n(0),o=function(t,e){var n=t?"?"+t.split(".").slice(-1)[0].replace(/\|/g,"&"):"",o=function(t,e,n,o){return r.getQueryParam(t,e)||r.getQueryParam(n,o)},i=o("utm_source",e,"utmcsr",n),s=o("utm_medium",e,"utmcmd",n),a=o("utm_campaign",e,"utmccn",n),u=o("utm_term",e,"utmctr",n),c=o("utm_content",e,"utmcct",n),f={},p=function(t,e){r.isEmptyString(e)||(f[t]=e)};return p("utm_source",i),p("utm_medium",s),p("utm_campaign",a),p("utm_term",u),p("utm_content",c),f};t.exports=o},function(t,e,n){var r;!function(o){"use strict";function i(t,e){var n=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(n>>16)<<16|65535&n}function s(t,e){return t<>>32-e}function a(t,e,n,r,o,a){return i(s(i(i(e,t),i(r,a)),o),n)}function u(t,e,n,r,o,i,s){return a(e&n|~e&r,t,e,o,i,s)}function c(t,e,n,r,o,i,s){return a(e&r|n&~r,t,e,o,i,s)}function f(t,e,n,r,o,i,s){return a(e^n^r,t,e,o,i,s)}function p(t,e,n,r,o,i,s){return a(n^(e|~r),t,e,o,i,s)}function l(t,e){t[e>>5]|=128<>>9<<4)]=e;var n,r,o,s,a,l=1732584193,h=-271733879,d=-1732584194,g=271733878;for(n=0;n>5]>>>e%32&255);return n}function d(t){var e,n=[];for(n[(t.length>>2)-1]=void 0,e=0;e>5]|=(255&t.charCodeAt(e/8))<16&&(o=l(o,8*t.length)),n=0;n<16;n+=1)i[n]=909522486^o[n],s[n]=1549556828^o[n];return r=l(i.concat(d(e)),512+8*e.length),h(l(s.concat(r),640))}function y(t){var e,n,r="0123456789abcdef",o="";for(n=0;n>>4&15)+r.charAt(15&e);return o}function m(t){return unescape(encodeURIComponent(t))}function w(t){return g(m(t))}function _(t){return y(w(t))}function b(t,e){return v(m(t),m(e))}function E(t,e){return y(b(t,e))}function I(t,e,n){return e?n?b(e,t):E(e,t):n?w(t):_(t)}void 0!==(r=function(){return I}.call(e,n,e,t))&&(t.exports=r)}()},function(t,e,n){function r(t,e){var n=i(t,e);return o(n)?n:void 0}var o=n(50),i=n(56);t.exports=r},function(t,e,n){function r(t){return!(!s(t)||i(t))&&(o(t)?d:c).test(a(t))}var o=n(17),i=n(53),s=n(7),a=n(55),u=/[\\^$.*+?()[\]{}|]/g,c=/^\[object .+?Constructor\]$/,f=Function.prototype,p=Object.prototype,l=f.toString,h=p.hasOwnProperty,d=RegExp("^"+l.call(h).replace(u,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=r},function(t,e,n){function r(t){var e=s.call(t,u),n=t[u];try{t[u]=void 0;var r=!0}catch(t){}var o=a.call(t);return r&&(e?t[u]=n:delete t[u]),o}var o=n(18),i=Object.prototype,s=i.hasOwnProperty,a=i.toString,u=o?o.toStringTag:void 0;t.exports=r},function(t,e){function n(t){return o.call(t)}var r=Object.prototype,o=r.toString;t.exports=n},function(t,e,n){function r(t){return!!i&&i in t}var o=n(54),i=function(){var t=/[^.]+$/.exec(o&&o.keys&&o.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();t.exports=r},function(t,e,n){var r=n(6),o=r["__core-js_shared__"];t.exports=o},function(t,e){function n(t){if(null!=t){try{return o.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var r=Function.prototype,o=r.toString;t.exports=n},function(t,e){function n(t,e){return null==t?void 0:t[e]}t.exports=n},function(t,e,n){function r(t,e,n,r){var s=!n;n||(n={});for(var a=-1,u=e.length;++a1?n[o-1]:void 0,a=o>2?n[2]:void 0;for(s=t.length>3&&"function"==typeof s?(o--,s):void 0,a&&i(n[0],n[1],a)&&(s=o<3?void 0:s,o=1),e=Object(e);++r0){if(++e>=r)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}var r=800,o=16,i=Date.now;t.exports=n},function(t,e,n){function r(t,e,n){if(!a(n))return!1;var r=typeof e;return!!("number"==r?i(n)&&s(e,n.length):"string"==r&&e in n)&&o(n[e],t)}var o=n(20),i=n(8),s=n(23),a=n(7);t.exports=r},function(t,e,n){function r(t){return s(t)?o(t):i(t)}var o=n(68),i=n(79),s=n(8);t.exports=r},function(t,e,n){function r(t,e){var n=s(t),r=!n&&i(t),f=!n&&!r&&a(t),l=!n&&!r&&!f&&c(t),h=n||r||f||l,d=h?o(t.length,String):[],g=d.length;for(var v in t)!e&&!p.call(t,v)||h&&("length"==v||f&&("offset"==v||"parent"==v)||l&&("buffer"==v||"byteLength"==v||"byteOffset"==v)||u(v,g))||d.push(v);return d}var o=n(69),i=n(70),s=n(72),a=n(73),u=n(23),c=n(75),f=Object.prototype,p=f.hasOwnProperty;t.exports=r},function(t,e){function n(t,e){for(var n=-1,r=Array(t);++n0&&c>u&&(c=u);for(var f=0;f=0?(p=g.substr(0,v),l=g.substr(v+1)):(p=g,l=""),h=decodeURIComponent(p),d=decodeURIComponent(l),r(s,h)?o(s[h])?s[h].push(d):s[h]=[s[h],d]:s[h]=d}return s};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},function(t,e,n){"use strict";function r(t,e){if(t.map)return t.map(e);for(var n=[],r=0;r0?2==o.length?"function"==typeof o[1]?t[o[0]]=o[1].call(this,s):t[o[0]]=o[1]:3==o.length?"function"!=typeof o[1]||o[1].exec&&o[1].test?t[o[0]]=s?s.replace(o[1],o[2]):void 0:t[o[0]]=s?o[1].call(this,s,o[2]):void 0:4==o.length&&(t[o[0]]=s?o[3].call(this,s.replace(o[1],o[2])):void 0):t[o]=s||void 0;a+=2}return t},str:function(t,e){for(var n in e)if("object"==typeof e[n]&&e[n].length>0){for(var r=0;r>e/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,t)};t.exports=r},function(t,e,n){"use strict";t.exports={language:function(){return navigator&&(navigator.languages&&navigator.languages[0]||navigator.language||navigator.userLanguage)||void 0}()}}])}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.amplitude=e():t.amplitude=e()}(this,function(){return function(t){function e(r){if(n[r])return n[r].exports;var o=n[r]={i:r,l:!1,exports:{}};return t[r].call(o.exports,o,o.exports,e),o.l=!0,o.exports}var n={};return e.m=t,e.c=n,e.d=function(t,n,r){e.o(t,n)||Object.defineProperty(t,n,{configurable:!1,enumerable:!0,get:r})},e.n=function(t){var n=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(n,"a",n),n},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=28)}([function(t,e,n){"use strict";var r=n(1),o=n(2),i=function(t){try{console.log("[Amplitude] "+t)}catch(t){}},s=function(t){return!t||0===t.length},a=function(){try{if(window.sessionStorage)return!0}catch(t){}return!1},u=function t(e){if("array"===o(e))for(var n=0;nr.MAX_STRING_LENGTH?t.substring(0,r.MAX_STRING_LENGTH):t},f=function(t,e,n){return o(t)===n||(i("Invalid "+e+" input type. Expected "+n+" but received "+o(t)),!1)},p=function(t){var e=o(t);if("object"!==e)return i("Error: invalid properties format. Expecting Javascript object, received "+e+", ignoring"),{};if(Object.keys(t).length>r.MAX_PROPERTY_KEYS)return i("Error: too many properties (more than 1000), ignoring"),{};var n={};for(var s in t)if(t.hasOwnProperty(s)){var a=s,u=o(a);"string"!==u&&(a=String(a),i("WARNING: Non-string property key, received type "+u+', coercing to string "'+a+'"'));var c=h(a,t[s]);null!==c&&(n[a]=c)}return n},l=["null","nan","undefined","function","arguments","regexp","element"],h=function t(e,n){var r=o(n);if(-1!==l.indexOf(r))i('WARNING: Property key "'+e+'" with invalid value type '+r+", ignoring"),n=null;else if("error"===r)n=String(n),i('WARNING: Property key "'+e+'" with value type error, coercing to '+n);else if("array"===r){for(var s=[],a=0;a0?(this.userPropertiesOperations.hasOwnProperty("$clearAll")||o.log("Need to send $clearAll on its own Identify object without any other operations, skipping $clearAll"),this):(this.userPropertiesOperations.$clearAll="-",this)},i.prototype.prepend=function(t,e){return this._addOperation("$prepend",t,e),this},i.prototype.set=function(t,e){return this._addOperation("$set",t,e),this},i.prototype.setOnce=function(t,e){return this._addOperation("$setOnce",t,e),this},i.prototype.unset=function(t){return this._addOperation("$unset",t,"-"),this},i.prototype._addOperation=function(t,e,n){return this.userPropertiesOperations.hasOwnProperty("$clearAll")?void o.log("This identify already contains a $clearAll operation, skipping operation "+t):-1!==this.properties.indexOf(e)?void o.log('User property "'+e+'" already used in this identify, skipping operation '+t):(this.userPropertiesOperations.hasOwnProperty(t)||(this.userPropertiesOperations[t]={}),this.userPropertiesOperations[t][e]=n,void this.properties.push(e))},t.exports=i},function(t,e,n){var r=n(14),o=n(57),i=n(58),s=n(8),a=n(24),u=n(67),c=Object.prototype,f=c.hasOwnProperty,p=i(function(t,e){if(a(e)||s(e))return void o(e,u(e),t);for(var n in e)f.call(e,n)&&r(t,n,e[n])});t.exports=p},function(t,e,n){function r(t,e,n){var r=t[e];a.call(t,e)&&i(r,n)&&(void 0!==n||e in t)||o(t,e,n)}var o=n(15),i=n(20),s=Object.prototype,a=s.hasOwnProperty;t.exports=r},function(t,e,n){function r(t,e,n){"__proto__"==e&&o?o(t,e,{configurable:!0,enumerable:!0,value:n,writable:!0}):t[e]=n}var o=n(16);t.exports=r},function(t,e,n){var r=n(49),o=function(){try{var t=r(Object,"defineProperty");return t({},"",{}),t}catch(t){}}();t.exports=o},function(t,e,n){function r(t){if(!i(t))return!1;var e=o(t);return e==a||e==u||e==s||e==c}var o=n(5),i=n(7),s="[object AsyncFunction]",a="[object Function]",u="[object GeneratorFunction]",c="[object Proxy]";t.exports=r},function(t,e,n){var r=n(6),o=r.Symbol;t.exports=o},function(t,e,n){(function(e){var n="object"==typeof e&&e&&e.Object===Object&&e;t.exports=n}).call(e,n(4))},function(t,e){function n(t,e){return t===e||t!==t&&e!==e}t.exports=n},function(t,e){function n(t){return t}t.exports=n},function(t,e){function n(t){return"number"==typeof t&&t>-1&&t%1==0&&t<=r}var r=9007199254740991;t.exports=n},function(t,e){function n(t,e){return!!(e=null==e?r:e)&&("number"==typeof t||o.test(t))&&t>-1&&t%1==0&&t1)))/4)-b((t-1901+e)/100)+b((t-1601+e)/400)};if((d=y.hasOwnProperty)||(d=function(t){var e,n={};return(n.__proto__=null,n.__proto__={toString:1},n).toString!=m?d=function(t){var e=this.__proto__,n=t in(this.__proto__=null,this);return this.__proto__=e,n}:(e=n.constructor,d=function(t){var n=(this.constructor||e).prototype;return t in this&&!(t in n&&this[t]===n[t])}),n=null,d.call(this,t)}),g=function(t,e){var n,r,o,i=0;(n=function(){this.valueOf=0}).prototype.valueOf=0,r=new n;for(o in r)d.call(r,o)&&i++;return n=r=null,i?g=2==i?function(t,e){var n,r={},o="[object Function]"==m.call(t);for(n in t)o&&"prototype"==n||d.call(r,n)||!(r[n]=1)||!d.call(t,n)||e(n)}:function(t,e){var n,r,o="[object Function]"==m.call(t);for(n in t)o&&"prototype"==n||!d.call(t,n)||(r="constructor"===n)||e(n);(r||d.call(t,n="constructor"))&&e(n)}:(r=["valueOf","toString","toLocaleString","propertyIsEnumerable","isPrototypeOf","hasOwnProperty","constructor"],g=function(t,e){var n,o,i="[object Function]"==m.call(t),s=!i&&"function"!=typeof t.constructor&&a[typeof t.hasOwnProperty]&&t.hasOwnProperty||d;for(n in t)i&&"prototype"==n||!s.call(t,n)||e(n);for(o=r.length;n=r[--o];s.call(t,n)&&e(n));}),g(t,e)},!n("json-stringify")){var S={92:"\\\\",34:'\\"',8:"\\b",12:"\\f",10:"\\n",13:"\\r",9:"\\t"},A=function(t,e){return("000000"+(e||0)).slice(-t)},C=function(t){for(var e='"',n=0,r=t.length,o=!_||r>10,i=o&&(_?t.split(""):t);n-1/0&&a<1/0){if(I){for(l=b(a/864e5),c=b(l/365.2425)+1970-1;I(c+1,0)<=l;c++);for(f=b((l-I(c,0))/30.42);I(c,f+1)<=l;f++);l=1+l-I(c,f),h=(a%864e5+864e5)%864e5,y=b(h/36e5)%24,w=b(h/6e4)%60,_=b(h/1e3)%60,E=h%1e3}else c=a.getUTCFullYear(),f=a.getUTCMonth(),l=a.getUTCDate(),y=a.getUTCHours(),w=a.getUTCMinutes(),_=a.getUTCSeconds(),E=a.getUTCMilliseconds();a=(c<=0||c>=1e4?(c<0?"-":"+")+A(6,c<0?-c:c):A(4,c))+"-"+A(2,f+1)+"-"+A(2,l)+"T"+A(2,y)+":"+A(2,w)+":"+A(2,_)+"."+A(3,E)+"Z"}else a=null;if(n&&(a=n.call(e,t,a)),null===a)return"null";if("[object Boolean]"==(u=m.call(a)))return""+a;if("[object Number]"==u)return a>-1/0&&a<1/0?""+a:"null";if("[object String]"==u)return C(""+a);if("object"==typeof a){for(N=s.length;N--;)if(s[N]===a)throw p();if(s.push(a),S=[],R=i,i+=o,"[object Array]"==u){for(O=0,N=a.length;O0)for(r="",n>10&&(n=10);r.length=48&&o<=57||o>=97&&o<=102||o>=65&&o<=70||P();t+=N("0x"+i.slice(e,T));break;default:P()}else{if(34==o)break;for(o=i.charCodeAt(T),e=T;o>=32&&92!=o&&34!=o;)o=i.charCodeAt(++T);t+=i.slice(e,T)}if(34==i.charCodeAt(T))return T++,t;P();default:if(e=T,45==o&&(r=!0,o=i.charCodeAt(++T)),o>=48&&o<=57){for(48==o&&(o=i.charCodeAt(T+1))>=48&&o<=57&&P(),r=!1;T=48&&o<=57;T++);if(46==i.charCodeAt(T)){for(n=++T;n=48&&o<=57;n++);n==T&&P(),T=n}if(101==(o=i.charCodeAt(T))||69==o){for(o=i.charCodeAt(++T),43!=o&&45!=o||T++,n=T;n=48&&o<=57;n++);n==T&&P(),T=n}return+i.slice(e,T)}if(r&&P(),"true"==i.slice(T,T+4))return T+=4,!0;if("false"==i.slice(T,T+5))return T+=5,!1;if("null"==i.slice(T,T+4))return T+=4,null;P()}return"$"},U=function(t){var e,n;if("$"==t&&P(),"string"==typeof t){if("@"==(_?t.charAt(0):t[0]))return t.slice(1);if("["==t){for(e=[];"]"!=(t=j());n||(n=!0))n&&(","==t?"]"==(t=j())&&P():P()),","==t&&P(),e.push(U(t));return e}if("{"==t){for(e={};"}"!=(t=j());n||(n=!0))n&&(","==t?"}"==(t=j())&&P():P()),","!=t&&"string"==typeof t&&"@"==(_?t.charAt(0):t[0])&&":"==j()||P(),e[t.slice(1)]=U(j());return e}P()}return t},k=function(t,e,n){var r=F(t,e,n);r===v?delete t[e]:t[e]=r},F=function(t,e,n){var r,o=t[e];if("object"==typeof o&&o)if("[object Array]"==m.call(o))for(r=o.length;r--;)k(o,r,n);else g(o,function(t){k(o,t,n)});return n.call(t,e,o)};e.parse=function(t,e){var n,r;return T=0,O=""+t,n=U(j()),"$"!=j()&&P(),T=O=null,e&&"[object Function]"==m.call(e)?F((r={},r[""]=n,r),"",e):n}}}return e.runInContext=i,e}var s=n(10),a={function:!0,object:!0},u=a[typeof e]&&e&&!e.nodeType&&e,c=a[typeof window]&&window||this,f=u&&a[typeof t]&&t&&!t.nodeType&&"object"==typeof r&&r;if(!f||f.global!==f&&f.window!==f&&f.self!==f||(c=f),u&&!s)i(c,u);else{var p=c.JSON,l=c.JSON3,h=!1,d=i(c,c.JSON3={noConflict:function(){return h||(h=!0,c.JSON=p,c.JSON3=l,p=l=null),d}});c.JSON={parse:d.parse,stringify:d.stringify}}s&&void 0!==(o=function(){return d}.call(e,n,e,t))&&(t.exports=o)}).call(this)}).call(e,n(3)(t),n(4))},function(t,e,n){"use strict";var r=n(31),o=n(1),i=n(12),s=n(13),a=n(25),u=n(2),c=n(0),f=n(26),p=n(27),l=function(){this.options=s({},p),this._q=[],this._instances={}};l.prototype.Identify=i,l.prototype.Revenue=a,l.prototype.getInstance=function(t){t=c.isEmptyString(t)?o.DEFAULT_INSTANCE:t.toLowerCase();var e=this._instances[t];return void 0===e&&(e=new r(t),this._instances[t]=e),e},l.prototype.init=function(t,e,n,r){this.getInstance().init(t,e,n,function(t){this.options=t.options,"function"===u(r)&&r(t)}.bind(this))},l.prototype.runQueuedFunctions=function(){for(var t=0;tthis.options.sessionTimeout)&&(this._newSession=!0,this._sessionId=p,this.options.saveParamsReferrerOncePerSession&&this._trackParamsAndReferrer()),this.options.saveParamsReferrerOncePerSession||this._trackParamsAndReferrer(),this._lastEventTime=p,E(this),this._sendEventsIfReady()}catch(t){d.log(t)}finally{"function"===l(o)&&o(this)}},m.prototype._trackParamsAndReferrer=function(){this.options.includeUtm&&this._initUtmData(),this.options.includeReferrer&&this._saveReferrer(this._getReferrer()),this.options.includeGclid&&this._saveGclid(this._getUrlParams())};var w=function(t,e){if("object"===l(e)){for(var n in e)e.hasOwnProperty(n)&&function(n){if(y.hasOwnProperty(n)){var r=e[n],o=l(y[n]);d.validateInput(r,n+" option",o)&&("boolean"===o?t[n]=!!r:("string"===o&&!d.isEmptyString(r)||"number"===o&&r>0)&&(t[n]=r))}}(n)}};m.prototype.runQueuedFunctions=function(){for(var t=0;t=this.options.eventUploadThreshold?(this.sendEvents(t),!0):(this._updateScheduled||(this._updateScheduled=!0,setTimeout(function(){this._updateScheduled=!1,this.sendEvents()}.bind(this),this.options.eventUploadPeriodMillis)),!1):(this.sendEvents(t),!0))},m.prototype._getFromStorage=function(t,e){return t.getItem(e+this._storageSuffix)},m.prototype._setInStorage=function(t,e,n){t.setItem(e+this._storageSuffix,n)};var _=function(t){var e=t.cookieStorage.get(t.options.cookieName);if(!("object"===l(e)&&e.deviceId&&e.sessionId&&e.lastEventTime)){var n=function(t){var e=a.getItem(t);return a.removeItem(t),e},o="string"===l(t.options.apiKey)&&"_"+t.options.apiKey.slice(0,6)||"",i=n(r.DEVICE_ID+o),s=n(r.USER_ID+o),u=n(r.OPT_OUT+o);null!==u&&void 0!==u&&(u="true"===String(u));var c=parseInt(n(r.SESSION_ID)),f=parseInt(n(r.LAST_EVENT_TIME)),p=parseInt(n(r.LAST_EVENT_ID)),h=parseInt(n(r.LAST_IDENTIFY_ID)),d=parseInt(n(r.LAST_SEQUENCE_NUMBER)),g=function(t){return"object"===l(e)&&e[t]};t.options.deviceId=g("deviceId")||i,t.options.userId=g("userId")||s,t._sessionId=g("sessionId")||c||t._sessionId,t._lastEventTime=g("lastEventTime")||f||t._lastEventTime,t._eventId=g("eventId")||p||t._eventId,t._identifyId=g("identifyId")||h||t._identifyId,t._sequenceNumber=g("sequenceNumber")||d||t._sequenceNumber,t.options.optOut=u||!1,e&&void 0!==e.optOut&&null!==e.optOut&&(t.options.optOut="true"===String(e.optOut)),E(t)}},b=function(t){var e=t.cookieStorage.get(t.options.cookieName+t._storageSuffix);"object"===l(e)&&(e.deviceId&&(t.options.deviceId=e.deviceId),e.userId&&(t.options.userId=e.userId),null!==e.optOut&&void 0!==e.optOut&&(t.options.optOut=e.optOut),e.sessionId&&(t._sessionId=parseInt(e.sessionId)),e.lastEventTime&&(t._lastEventTime=parseInt(e.lastEventTime)),e.eventId&&(t._eventId=parseInt(e.eventId)),e.identifyId&&(t._identifyId=parseInt(e.identifyId)),e.sequenceNumber&&(t._sequenceNumber=parseInt(e.sequenceNumber)))},E=function(t){t.cookieStorage.set(t.options.cookieName+t._storageSuffix,{deviceId:t.options.deviceId,userId:t.options.userId,optOut:t.options.optOut,sessionId:t._sessionId,lastEventTime:t._lastEventTime,eventId:t._eventId,identifyId:t._identifyId,sequenceNumber:t._sequenceNumber})};m.prototype._initUtmData=function(t,e){t=t||this._getUrlParams(),e=e||this.cookieStorage.get("__utmz");var n=i(e,t);I(this,n)};var I=function(t,e){if("object"===l(e)&&0!==Object.keys(e).length){var n=new s;for(var r in e)e.hasOwnProperty(r)&&(n.setOnce("initial_"+r,e[r]),n.set(r,e[r]));t.identify(n)}};m.prototype._getReferrer=function(){return document.referrer},m.prototype._getUrlParams=function(){return location.search},m.prototype._saveGclid=function(t){var e=d.getQueryParam("gclid",t);if(!d.isEmptyString(e)){I(this,{gclid:e})}},m.prototype._getDeviceIdFromUrlParam=function(t){return d.getQueryParam(r.AMP_DEVICE_ID_PARAM,t)},m.prototype._getReferringDomain=function(t){if(d.isEmptyString(t))return null;var e=t.split("/");return e.length>=3?e[2]:null},m.prototype._saveReferrer=function(t){if(!d.isEmptyString(t)){var e={referrer:t,referring_domain:this._getReferringDomain(t)};I(this,e)}},m.prototype.saveEvents=function(){try{this._setInStorage(a,this.options.unsentKey,JSON.stringify(this._unsentEvents))}catch(t){}try{this._setInStorage(a,this.options.unsentIdentifyKey,JSON.stringify(this._unsentIdentifys))}catch(t){}},m.prototype.setDomain=function(t){if(d.validateInput(t,"domain","string"))try{this.cookieStorage.options({domain:t}),this.options.domain=this.cookieStorage.options().domain,b(this),E(this)}catch(t){d.log(t)}},m.prototype.setUserId=function(t){try{this.options.userId=void 0!==t&&null!==t&&""+t||null,E(this)}catch(t){d.log(t)}},m.prototype.setGroup=function(t,e){if(this._apiKeySet("setGroup()")&&d.validateInput(t,"groupType","string")&&!d.isEmptyString(t)){var n={};n[t]=e;var o=(new s).set(t,e);this._logEvent(r.IDENTIFY_EVENT,null,null,o.userPropertiesOperations,n,null,null)}},m.prototype.setOptOut=function(t){if(d.validateInput(t,"enable","boolean"))try{this.options.optOut=t,E(this)}catch(t){d.log(t)}},m.prototype.setSessionId=function(t){if(d.validateInput(t,"sessionId","number"))try{this._sessionId=t,E(this)}catch(t){d.log(t)}},m.prototype.regenerateDeviceId=function(){this.setDeviceId(g()+"R")},m.prototype.setDeviceId=function(t){if(d.validateInput(t,"deviceId","string"))try{d.isEmptyString(t)||(this.options.deviceId=""+t,E(this))}catch(t){d.log(t)}},m.prototype.setUserProperties=function(t){if(this._apiKeySet("setUserProperties()")&&d.validateInput(t,"userProperties","object")){var e=d.truncate(d.validateProperties(t));if(0!==Object.keys(e).length){var n=new s;for(var r in e)e.hasOwnProperty(r)&&n.set(r,e[r]);this.identify(n)}}},m.prototype.clearUserProperties=function(){if(this._apiKeySet("clearUserProperties()")){var t=new s;t.clearAll(),this.identify(t)}};var S=function(t,e){for(var n=0;n0)return this._logEvent(r.IDENTIFY_EVENT,null,null,t.userPropertiesOperations,null,null,e)}else d.log("Invalid identify input type. Expected Identify object but saw "+l(t));"function"===l(e)&&e(0,"No request sent")},m.prototype.setVersionName=function(t){d.validateInput(t,"versionName","string")&&(this.options.versionName=t)},m.prototype._logEvent=function(t,e,n,o,i,s,a){if(b(this),!t||this.options.optOut)return void("function"===l(a)&&a(0,"No request sent"));try{var u;u=t===r.IDENTIFY_EVENT?this.nextIdentifyId():this.nextEventId();var c=this.nextSequenceNumber(),f="number"===l(s)?s:(new Date).getTime();(!this._sessionId||!this._lastEventTime||f-this._lastEventTime>this.options.sessionTimeout)&&(this._sessionId=f),this._lastEventTime=f,E(this),o=o||{},n=n||{},e=e||{},i=i||{};var p={device_id:this.options.deviceId,user_id:this.options.userId,timestamp:f,event_id:u,session_id:this._sessionId||-1,event_type:t,version_name:this.options.versionName||null,platform:this.options.platform,os_name:this._ua.browser.name||null,os_version:this._ua.browser.major||null,device_model:this._ua.os.name||null,language:this.options.language,api_properties:n,event_properties:d.truncate(d.validateProperties(e)),user_properties:d.truncate(d.validateProperties(o)),uuid:g(),library:{name:"amplitude-js",version:v},sequence_number:c,groups:d.truncate(d.validateGroups(i)),user_agent:this._userAgent};return t===r.IDENTIFY_EVENT?(this._unsentIdentifys.push(p),this._limitEventsQueued(this._unsentIdentifys)):(this._unsentEvents.push(p),this._limitEventsQueued(this._unsentEvents)),this.options.saveEvents&&this.saveEvents(),this._sendEventsIfReady(a)||"function"!==l(a)||a(0,"No request sent"),u}catch(t){d.log(t)}},m.prototype._limitEventsQueued=function(t){t.length>this.options.savedMaxCount&&t.splice(0,t.length-this.options.savedMaxCount)},m.prototype.logEvent=function(t,e,n){return this.logEventWithTimestamp(t,e,null,n)},m.prototype.logEventWithTimestamp=function(t,e,n,r){return this._apiKeySet("logEvent()")&&d.validateInput(t,"eventType","string")&&!d.isEmptyString(t)?this._logEvent(t,e,null,null,null,n,r):("function"===l(r)&&r(0,"No request sent"),-1)},m.prototype.logEventWithGroups=function(t,e,n,r){return this._apiKeySet("logEventWithGroup()")&&d.validateInput(t,"eventType","string")?this._logEvent(t,e,null,null,n,null,r):("function"===l(r)&&r(0,"No request sent"),-1)};var A=function(t){return!isNaN(parseFloat(t))&&isFinite(t)};m.prototype.logRevenueV2=function(t){if(this._apiKeySet("logRevenueV2()"))if("object"===l(t)&&t.hasOwnProperty("_q")&&(t=S(new p,t)),t instanceof p){if(t&&t._isValidRevenue())return this.logEvent(r.REVENUE_EVENT,t._toJSONObject())}else d.log("Invalid revenue input type. Expected Revenue object but saw "+l(t))},m.prototype.logRevenue=function(t,e,n){return this._apiKeySet("logRevenue()")&&A(t)&&(void 0===e||A(e))?this._logEvent(r.REVENUE_EVENT,{},{productId:n,special:"revenue_amount",quantity:e||1,price:t},null,null,null,null):-1},m.prototype.removeEvents=function(t,e){C(this,"_unsentEvents",t),C(this,"_unsentIdentifys",e)};var C=function(t,e,n){if(!(n<0)){for(var r=[],o=0;on&&r.push(t[e][o]);t[e]=r}};m.prototype.sendEvents=function(t){if(!this._apiKeySet("sendEvents()")||this._sending||this.options.optOut||0===this._unsentCount())return void("function"===l(t)&&t(0,"No request sent"));this._sending=!0;var e=this.options.forceHttps?"https":"https:"===window.location.protocol?"https":"http",n=e+"://"+this.options.apiEndpoint+"/",o=Math.min(this._unsentCount(),this.options.uploadBatchSize),i=this._mergeEventsAndIdentifys(o),s=i.maxEventId,a=i.maxIdentifyId,c=JSON.stringify(i.eventsToSend),p=(new Date).getTime(),h={client:this.options.apiKey,e:c,v:r.API_VERSION,upload_time:p,checksum:u(r.API_VERSION+this.options.apiKey+c+p)},d=this;new f(n,h).send(function(e,n){d._sending=!1;try{200===e&&"success"===n?(d.removeEvents(s,a),d.options.saveEvents&&d.saveEvents(),d._sendEventsIfReady(t)||"function"!==l(t)||t(e,n)):413===e?(1===d.options.uploadBatchSize&&d.removeEvents(s,a),d.options.uploadBatchSize=Math.ceil(o/2),d.sendEvents(t)):"function"===l(t)&&t(e,n)}catch(t){}})},m.prototype._mergeEventsAndIdentifys=function(t){for(var e=[],n=0,r=-1,o=0,i=-1;e.length=this._unsentIdentifys.length,u=n>=this._unsentEvents.length;if(u&&a){d.log("Merging Events and Identifys, less events and identifys than expected");break}a?(s=this._unsentEvents[n++],r=s.event_id):u?(s=this._unsentIdentifys[o++],i=s.event_id):!("sequence_number"in this._unsentEvents[n])||this._unsentEvents[n].sequence_number>2,a=(3&e)<<4|n>>4,u=(15&n)<<2|i>>6,c=63&i,isNaN(n)?u=c=64:isNaN(i)&&(c=64),f=f+o._keyStr.charAt(s)+o._keyStr.charAt(a)+o._keyStr.charAt(u)+o._keyStr.charAt(c);return f},decode:function(t){try{if(window.btoa&&window.atob)return decodeURIComponent(escape(window.atob(t)))}catch(t){}return o._decode(t)},_decode:function(t){var e,n,i,s,a,u,c,f="",p=0;for(t=t.replace(/[^A-Za-z0-9\+\/\=]/g,"");p>4,n=(15&a)<<4|u>>2,i=(3&u)<<6|c,f+=String.fromCharCode(e),64!==u&&(f+=String.fromCharCode(n)),64!==c&&(f+=String.fromCharCode(i));return f=r.decode(f)}};t.exports=o},function(t,e,n){"use strict";var r={encode:function(t){for(var e="",n=0;n127&&r<2048?(e+=String.fromCharCode(r>>6|192),e+=String.fromCharCode(63&r|128)):(e+=String.fromCharCode(r>>12|224),e+=String.fromCharCode(r>>6&63|128),e+=String.fromCharCode(63&r|128))}return e},decode:function(t){for(var e="",n=0,r=0,o=0,i=0;n191&&r<224?(o=t.charCodeAt(n+1),e+=String.fromCharCode((31&r)<<6|63&o),n+=2):(o=t.charCodeAt(n+1),i=t.charCodeAt(n+2),e+=String.fromCharCode((15&r)<<12|(63&o)<<6|63&i),n+=3);return e}};t.exports=r},function(t,e,n){"use strict";function r(t){for(var n=e.cookie,r=e.levels(t),o=0;o=0;--s)i.push(n.slice(s).join("."));return i},r.cookie=i,e=t.exports=r},function(t,e){function n(t){switch(t){case"http:":return 80;case"https:":return 443;default:return location.port}}e.parse=function(t){var e=document.createElement("a");return e.href=t,{href:e.href,host:e.host||location.host,port:"0"===e.port||""===e.port?n(e.protocol):e.port,hash:e.hash,hostname:e.hostname||location.hostname,pathname:"/"!=e.pathname.charAt(0)?"/"+e.pathname:e.pathname,protocol:e.protocol&&":"!=e.protocol?e.protocol:location.protocol,search:e.search,query:e.search.slice(1)}},e.isAbsolute=function(t){return 0==t.indexOf("//")||!!~t.indexOf("://")},e.isRelative=function(t){return!e.isAbsolute(t)},e.isCrossDomain=function(t){t=e.parse(t);var n=e.parse(window.location.href);return t.hostname!==n.hostname||t.port!==n.port||t.protocol!==n.protocol}},function(t,e,n){function r(t,e,n){n=n||{};var r=a(t)+"="+a(e);null==e&&(n.maxage=-1),n.maxage&&(n.expires=new Date(+new Date+n.maxage)),n.path&&(r+="; path="+n.path),n.domain&&(r+="; domain="+n.domain),n.expires&&(r+="; expires="+n.expires.toUTCString()),n.secure&&(r+="; secure"),document.cookie=r}function o(){var t;try{t=document.cookie}catch(t){return"undefined"!=typeof console&&"function"==typeof console.error&&console.error(t.stack||t),{}}return s(t)}function i(t){return o()[t]}function s(t){var e,n={},r=t.split(/ *; */);if(""==r[0])return n;for(var o=0;o=31||"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/))}function i(t){var n=this.useColors;if(t[0]=(n?"%c":"")+this.namespace+(n?" %c":" ")+t[0]+(n?"%c ":" ")+"+"+e.humanize(this.diff),n){var r="color: "+this.color;t.splice(1,0,r,"color: inherit");var o=0,i=0;t[0].replace(/%[a-zA-Z%]/g,function(t){"%%"!==t&&(o++,"%c"===t&&(i=o))}),t.splice(i,0,r)}}function s(){return"object"==typeof console&&console.log&&Function.prototype.apply.call(console.log,console,arguments)}function a(t){try{null==t?e.storage.removeItem("debug"):e.storage.debug=t}catch(t){}}function u(){var t;try{t=e.storage.debug}catch(t){}return!t&&void 0!==r&&"env"in r&&(t=r.env.DEBUG),t}e=t.exports=n(41),e.log=s,e.formatArgs=i,e.save=a,e.load=u,e.useColors=o,e.storage="undefined"!=typeof chrome&&void 0!==chrome.storage?chrome.storage.local:function(){try{return window.localStorage}catch(t){}}(),e.colors=["#0000CC","#0000FF","#0033CC","#0033FF","#0066CC","#0066FF","#0099CC","#0099FF","#00CC00","#00CC33","#00CC66","#00CC99","#00CCCC","#00CCFF","#3300CC","#3300FF","#3333CC","#3333FF","#3366CC","#3366FF","#3399CC","#3399FF","#33CC00","#33CC33","#33CC66","#33CC99","#33CCCC","#33CCFF","#6600CC","#6600FF","#6633CC","#6633FF","#66CC00","#66CC33","#9900CC","#9900FF","#9933CC","#9933FF","#99CC00","#99CC33","#CC0000","#CC0033","#CC0066","#CC0099","#CC00CC","#CC00FF","#CC3300","#CC3333","#CC3366","#CC3399","#CC33CC","#CC33FF","#CC6600","#CC6633","#CC9900","#CC9933","#CCCC00","#CCCC33","#FF0000","#FF0033","#FF0066","#FF0099","#FF00CC","#FF00FF","#FF3300","#FF3333","#FF3366","#FF3399","#FF33CC","#FF33FF","#FF6600","#FF6633","#FF9900","#FF9933","#FFCC00","#FFCC33"],e.formatters.j=function(t){try{return JSON.stringify(t)}catch(t){return"[UnexpectedJSONParseError]: "+t.message}},e.enable(u())}).call(e,n(40))},function(t,e){function n(){throw new Error("setTimeout has not been defined")}function r(){throw new Error("clearTimeout has not been defined")}function o(t){if(f===setTimeout)return setTimeout(t,0);if((f===n||!f)&&setTimeout)return f=setTimeout,setTimeout(t,0);try{return f(t,0)}catch(e){try{return f.call(null,t,0)}catch(e){return f.call(this,t,0)}}}function i(t){if(p===clearTimeout)return clearTimeout(t);if((p===r||!p)&&clearTimeout)return p=clearTimeout,clearTimeout(t);try{return p(t)}catch(e){try{return p.call(null,t)}catch(e){return p.call(this,t)}}}function s(){g&&h&&(g=!1,h.length?d=h.concat(d):v=-1,d.length&&a())}function a(){if(!g){var t=o(s);g=!0;for(var e=d.length;e;){for(h=d,d=[];++v1)for(var n=1;n100)){var e=/^((?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|years?|yrs?|y)?$/i.exec(t);if(e){var n=parseFloat(e[1]);switch((e[2]||"ms").toLowerCase()){case"years":case"year":case"yrs":case"yr":case"y":return n*f;case"days":case"day":case"d":return n*c;case"hours":case"hour":case"hrs":case"hr":case"h":return n*u;case"minutes":case"minute":case"mins":case"min":case"m":return n*a;case"seconds":case"second":case"secs":case"sec":case"s":return n*s;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return n;default:return}}}}function r(t){return t>=c?Math.round(t/c)+"d":t>=u?Math.round(t/u)+"h":t>=a?Math.round(t/a)+"m":t>=s?Math.round(t/s)+"s":t+"ms"}function o(t){return i(t,c,"day")||i(t,u,"hour")||i(t,a,"minute")||i(t,s,"second")||t+" ms"}function i(t,e,n){if(!(t0)return n(t);if("number"===i&&!1===isNaN(t))return e.long?o(t):r(t);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(t))}},function(t,e,n){"use strict";(function(t){function r(){return i.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function o(t,e){if(r()=r())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+r().toString(16)+" bytes");return 0|t}function g(t){return+t!=t&&(t=0),i.alloc(+t)}function v(t,e){if(i.isBuffer(t))return t.length;if("undefined"!=typeof ArrayBuffer&&"function"==typeof ArrayBuffer.isView&&(ArrayBuffer.isView(t)||t instanceof ArrayBuffer))return t.byteLength;"string"!=typeof t&&(t=""+t);var n=t.length;if(0===n)return 0;for(var r=!1;;)switch(e){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return z(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*n;case"hex":return n>>>1;case"base64":return J(t).length;default:if(r)return z(t).length;e=(""+e).toLowerCase(),r=!0}}function y(t,e,n){var r=!1;if((void 0===e||e<0)&&(e=0),e>this.length)return"";if((void 0===n||n>this.length)&&(n=this.length),n<=0)return"";if(n>>>=0,e>>>=0,n<=e)return"";for(t||(t="utf8");;)switch(t){case"hex":return P(this,e,n);case"utf8":case"utf-8":return T(this,e,n);case"ascii":return N(this,e,n);case"latin1":case"binary":return R(this,e,n);case"base64":return x(this,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return j(this,e,n);default:if(r)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),r=!0}}function m(t,e,n){var r=t[e];t[e]=t[n],t[n]=r}function w(t,e,n,r,o){if(0===t.length)return-1;if("string"==typeof n?(r=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:t.length-1),n<0&&(n=t.length+n),n>=t.length){if(o)return-1;n=t.length-1}else if(n<0){if(!o)return-1;n=0}if("string"==typeof e&&(e=i.from(e,r)),i.isBuffer(e))return 0===e.length?-1:_(t,e,n,r,o);if("number"==typeof e)return e&=255,i.TYPED_ARRAY_SUPPORT&&"function"==typeof Uint8Array.prototype.indexOf?o?Uint8Array.prototype.indexOf.call(t,e,n):Uint8Array.prototype.lastIndexOf.call(t,e,n):_(t,[e],n,r,o);throw new TypeError("val must be string, number or Buffer")}function _(t,e,n,r,o){function i(t,e){return 1===s?t[e]:t.readUInt16BE(e*s)}var s=1,a=t.length,u=e.length;if(void 0!==r&&("ucs2"===(r=String(r).toLowerCase())||"ucs-2"===r||"utf16le"===r||"utf-16le"===r)){if(t.length<2||e.length<2)return-1;s=2,a/=2,u/=2,n/=2}var c;if(o){var f=-1;for(c=n;ca&&(n=a-u),c=n;c>=0;c--){for(var p=!0,l=0;lo&&(r=o):r=o;var i=e.length;if(i%2!=0)throw new TypeError("Invalid hex string");r>i/2&&(r=i/2);for(var s=0;s239?4:i>223?3:i>191?2:1;if(o+a<=n){var u,c,f,p;switch(a){case 1:i<128&&(s=i);break;case 2:u=t[o+1],128==(192&u)&&(p=(31&i)<<6|63&u)>127&&(s=p);break;case 3:u=t[o+1],c=t[o+2],128==(192&u)&&128==(192&c)&&(p=(15&i)<<12|(63&u)<<6|63&c)>2047&&(p<55296||p>57343)&&(s=p);break;case 4:u=t[o+1],c=t[o+2],f=t[o+3],128==(192&u)&&128==(192&c)&&128==(192&f)&&(p=(15&i)<<18|(63&u)<<12|(63&c)<<6|63&f)>65535&&p<1114112&&(s=p)}}null===s?(s=65533,a=1):s>65535&&(s-=65536,r.push(s>>>10&1023|55296),s=56320|1023&s),r.push(s),o+=a}return O(r)}function O(t){var e=t.length;if(e<=Z)return String.fromCharCode.apply(String,t);for(var n="",r=0;rr)&&(n=r);for(var o="",i=e;in)throw new RangeError("Trying to access beyond buffer length")}function k(t,e,n,r,o,s){if(!i.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(e>o||et.length)throw new RangeError("Index out of range")}function F(t,e,n,r){e<0&&(e=65535+e+1);for(var o=0,i=Math.min(t.length-n,2);o>>8*(r?o:1-o)}function D(t,e,n,r){e<0&&(e=4294967295+e+1);for(var o=0,i=Math.min(t.length-n,4);o>>8*(r?o:3-o)&255}function M(t,e,n,r,o,i){if(n+r>t.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function B(t,e,n,r,o){return o||M(t,e,n,4,3.4028234663852886e38,-3.4028234663852886e38),Q.write(t,e,n,r,23,4),n+4}function L(t,e,n,r,o){return o||M(t,e,n,8,1.7976931348623157e308,-1.7976931348623157e308),Q.write(t,e,n,r,52,8),n+8}function q(t){if(t=Y(t).replace(tt,""),t.length<2)return"";for(;t.length%4!=0;)t+="=";return t}function Y(t){return t.trim?t.trim():t.replace(/^\s+|\s+$/g,"")}function V(t){return t<16?"0"+t.toString(16):t.toString(16)}function z(t,e){e=e||1/0;for(var n,r=t.length,o=null,i=[],s=0;s55295&&n<57344){if(!o){if(n>56319){(e-=3)>-1&&i.push(239,191,189);continue}if(s+1===r){(e-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(e-=3)>-1&&i.push(239,191,189),o=n;continue}n=65536+(o-55296<<10|n-56320)}else o&&(e-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((e-=1)<0)break;i.push(n)}else if(n<2048){if((e-=2)<0)break;i.push(n>>6|192,63&n|128)}else if(n<65536){if((e-=3)<0)break;i.push(n>>12|224,n>>6&63|128,63&n|128)}else{if(!(n<1114112))throw new Error("Invalid code point");if((e-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,63&n|128)}}return i}function G(t){for(var e=[],n=0;n>8,o=n%256,i.push(o),i.push(r);return i}function J(t){return X.toByteArray(q(t))}function $(t,e,n,r){for(var o=0;o=e.length||o>=t.length);++o)e[o+n]=t[o];return o}function W(t){return t!==t}var X=n(44),Q=n(45),H=n(46);e.Buffer=i,e.SlowBuffer=g,e.INSPECT_MAX_BYTES=50,i.TYPED_ARRAY_SUPPORT=void 0!==t.TYPED_ARRAY_SUPPORT?t.TYPED_ARRAY_SUPPORT:function(){try{var t=new Uint8Array(1);return t.__proto__={__proto__:Uint8Array.prototype,foo:function(){return 42}},42===t.foo()&&"function"==typeof t.subarray&&0===t.subarray(1,1).byteLength}catch(t){return!1}}(),e.kMaxLength=r(),i.poolSize=8192,i._augment=function(t){return t.__proto__=i.prototype,t},i.from=function(t,e,n){return s(null,t,e,n)},i.TYPED_ARRAY_SUPPORT&&(i.prototype.__proto__=Uint8Array.prototype,i.__proto__=Uint8Array,"undefined"!=typeof Symbol&&Symbol.species&&i[Symbol.species]===i&&Object.defineProperty(i,Symbol.species,{value:null,configurable:!0})),i.alloc=function(t,e,n){return u(null,t,e,n)},i.allocUnsafe=function(t){return c(null,t)},i.allocUnsafeSlow=function(t){return c(null,t)},i.isBuffer=function(t){return!(null==t||!t._isBuffer)},i.compare=function(t,e){if(!i.isBuffer(t)||!i.isBuffer(e))throw new TypeError("Arguments must be Buffers");if(t===e)return 0;for(var n=t.length,r=e.length,o=0,s=Math.min(n,r);o0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),""},i.prototype.compare=function(t,e,n,r,o){if(!i.isBuffer(t))throw new TypeError("Argument must be a Buffer");if(void 0===e&&(e=0),void 0===n&&(n=t?t.length:0),void 0===r&&(r=0),void 0===o&&(o=this.length),e<0||n>t.length||r<0||o>this.length)throw new RangeError("out of range index");if(r>=o&&e>=n)return 0;if(r>=o)return-1;if(e>=n)return 1;if(e>>>=0,n>>>=0,r>>>=0,o>>>=0,this===t)return 0;for(var s=o-r,a=n-e,u=Math.min(s,a),c=this.slice(r,o),f=t.slice(e,n),p=0;po)&&(n=o),t.length>0&&(n<0||e<0)||e>this.length)throw new RangeError("Attempt to write outside buffer bounds");r||(r="utf8");for(var i=!1;;)switch(r){case"hex":return b(this,t,e,n);case"utf8":case"utf-8":return E(this,t,e,n);case"ascii":return I(this,t,e,n);case"latin1":case"binary":return S(this,t,e,n);case"base64":return A(this,t,e,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return C(this,t,e,n);default:if(i)throw new TypeError("Unknown encoding: "+r);r=(""+r).toLowerCase(),i=!0}},i.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};var Z=4096;i.prototype.slice=function(t,e){var n=this.length;t=~~t,e=void 0===e?n:~~e,t<0?(t+=n)<0&&(t=0):t>n&&(t=n),e<0?(e+=n)<0&&(e=0):e>n&&(e=n),e0&&(o*=256);)r+=this[t+--e]*o;return r},i.prototype.readUInt8=function(t,e){return e||U(t,1,this.length),this[t]},i.prototype.readUInt16LE=function(t,e){return e||U(t,2,this.length),this[t]|this[t+1]<<8},i.prototype.readUInt16BE=function(t,e){return e||U(t,2,this.length),this[t]<<8|this[t+1]},i.prototype.readUInt32LE=function(t,e){return e||U(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},i.prototype.readUInt32BE=function(t,e){return e||U(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},i.prototype.readIntLE=function(t,e,n){t|=0,e|=0,n||U(t,e,this.length);for(var r=this[t],o=1,i=0;++i=o&&(r-=Math.pow(2,8*e)),r},i.prototype.readIntBE=function(t,e,n){t|=0,e|=0,n||U(t,e,this.length);for(var r=e,o=1,i=this[t+--r];r>0&&(o*=256);)i+=this[t+--r]*o;return o*=128,i>=o&&(i-=Math.pow(2,8*e)),i},i.prototype.readInt8=function(t,e){return e||U(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},i.prototype.readInt16LE=function(t,e){e||U(t,2,this.length);var n=this[t]|this[t+1]<<8;return 32768&n?4294901760|n:n},i.prototype.readInt16BE=function(t,e){e||U(t,2,this.length);var n=this[t+1]|this[t]<<8;return 32768&n?4294901760|n:n},i.prototype.readInt32LE=function(t,e){return e||U(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},i.prototype.readInt32BE=function(t,e){return e||U(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},i.prototype.readFloatLE=function(t,e){return e||U(t,4,this.length),Q.read(this,t,!0,23,4)},i.prototype.readFloatBE=function(t,e){return e||U(t,4,this.length),Q.read(this,t,!1,23,4)},i.prototype.readDoubleLE=function(t,e){return e||U(t,8,this.length),Q.read(this,t,!0,52,8)},i.prototype.readDoubleBE=function(t,e){return e||U(t,8,this.length),Q.read(this,t,!1,52,8)},i.prototype.writeUIntLE=function(t,e,n,r){if(t=+t,e|=0,n|=0,!r){k(this,t,e,n,Math.pow(2,8*n)-1,0)}var o=1,i=0;for(this[e]=255&t;++i=0&&(i*=256);)this[e+o]=t/i&255;return e+n},i.prototype.writeUInt8=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,1,255,0),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[e]=255&t,e+1},i.prototype.writeUInt16LE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):F(this,t,e,!0),e+2},i.prototype.writeUInt16BE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,2,65535,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):F(this,t,e,!1),e+2},i.prototype.writeUInt32LE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e+3]=t>>>24,this[e+2]=t>>>16,this[e+1]=t>>>8,this[e]=255&t):D(this,t,e,!0),e+4},i.prototype.writeUInt32BE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,4,4294967295,0),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):D(this,t,e,!1),e+4},i.prototype.writeIntLE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);k(this,t,e,n,o-1,-o)}var i=0,s=1,a=0;for(this[e]=255&t;++i>0)-a&255;return e+n},i.prototype.writeIntBE=function(t,e,n,r){if(t=+t,e|=0,!r){var o=Math.pow(2,8*n-1);k(this,t,e,n,o-1,-o)}var i=n-1,s=1,a=0;for(this[e+i]=255&t;--i>=0&&(s*=256);)t<0&&0===a&&0!==this[e+i+1]&&(a=1),this[e+i]=(t/s>>0)-a&255;return e+n},i.prototype.writeInt8=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,1,127,-128),i.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[e]=255&t,e+1},i.prototype.writeInt16LE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8):F(this,t,e,!0),e+2},i.prototype.writeInt16BE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,2,32767,-32768),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>8,this[e+1]=255&t):F(this,t,e,!1),e+2},i.prototype.writeInt32LE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,4,2147483647,-2147483648),i.TYPED_ARRAY_SUPPORT?(this[e]=255&t,this[e+1]=t>>>8,this[e+2]=t>>>16,this[e+3]=t>>>24):D(this,t,e,!0),e+4},i.prototype.writeInt32BE=function(t,e,n){return t=+t,e|=0,n||k(this,t,e,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),i.TYPED_ARRAY_SUPPORT?(this[e]=t>>>24,this[e+1]=t>>>16,this[e+2]=t>>>8,this[e+3]=255&t):D(this,t,e,!1),e+4},i.prototype.writeFloatLE=function(t,e,n){return B(this,t,e,!0,n)},i.prototype.writeFloatBE=function(t,e,n){return B(this,t,e,!1,n)},i.prototype.writeDoubleLE=function(t,e,n){return L(this,t,e,!0,n)},i.prototype.writeDoubleBE=function(t,e,n){return L(this,t,e,!1,n)},i.prototype.copy=function(t,e,n,r){if(n||(n=0),r||0===r||(r=this.length),e>=t.length&&(e=t.length),e||(e=0),r>0&&r=this.length)throw new RangeError("sourceStart out of bounds");if(r<0)throw new RangeError("sourceEnd out of bounds");r>this.length&&(r=this.length),t.length-e=0;--o)t[o+e]=this[o+n];else if(s<1e3||!i.TYPED_ARRAY_SUPPORT)for(o=0;o>>=0,n=void 0===n?this.length:n>>>0,t||(t=0);var s;if("number"==typeof t)for(s=e;s0)throw new Error("Invalid string. Length must be a multiple of 4");return"="===t[e-2]?2:"="===t[e-1]?1:0}function o(t){return 3*t.length/4-r(t)}function i(t){var e,n,o,i,s,a=t.length;i=r(t),s=new p(3*a/4-i),n=i>0?a-4:a;var u=0;for(e=0;e>16&255,s[u++]=o>>8&255,s[u++]=255&o;return 2===i?(o=f[t.charCodeAt(e)]<<2|f[t.charCodeAt(e+1)]>>4,s[u++]=255&o):1===i&&(o=f[t.charCodeAt(e)]<<10|f[t.charCodeAt(e+1)]<<4|f[t.charCodeAt(e+2)]>>2,s[u++]=o>>8&255,s[u++]=255&o),s}function s(t){return c[t>>18&63]+c[t>>12&63]+c[t>>6&63]+c[63&t]}function a(t,e,n){for(var r,o=[],i=e;iu?u:s+16383));return 1===r?(e=t[n-1],o+=c[e>>2],o+=c[e<<4&63],o+="=="):2===r&&(e=(t[n-2]<<8)+t[n-1],o+=c[e>>10],o+=c[e>>4&63],o+=c[e<<2&63],o+="="),i.push(o),i.join("")}e.byteLength=o,e.toByteArray=i,e.fromByteArray=u;for(var c=[],f=[],p="undefined"!=typeof Uint8Array?Uint8Array:Array,l="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",h=0,d=l.length;h>1,f=-7,p=n?o-1:0,l=n?-1:1,h=t[e+p];for(p+=l,i=h&(1<<-f)-1,h>>=-f,f+=a;f>0;i=256*i+t[e+p],p+=l,f-=8);for(s=i&(1<<-f)-1,i>>=-f,f+=r;f>0;s=256*s+t[e+p],p+=l,f-=8);if(0===i)i=1-c;else{if(i===u)return s?NaN:1/0*(h?-1:1);s+=Math.pow(2,r),i-=c}return(h?-1:1)*s*Math.pow(2,i-r)},e.write=function(t,e,n,r,o,i){var s,a,u,c=8*i-o-1,f=(1<>1,l=23===o?Math.pow(2,-24)-Math.pow(2,-77):0,h=r?0:i-1,d=r?1:-1,g=e<0||0===e&&1/e<0?1:0;for(e=Math.abs(e),isNaN(e)||e===1/0?(a=isNaN(e)?1:0,s=f):(s=Math.floor(Math.log(e)/Math.LN2),e*(u=Math.pow(2,-s))<1&&(s--,u*=2),e+=s+p>=1?l/u:l*Math.pow(2,1-p),e*u>=2&&(s++,u/=2),s+p>=f?(a=0,s=f):s+p>=1?(a=(e*u-1)*Math.pow(2,o),s+=p):(a=e*Math.pow(2,p-1)*Math.pow(2,o),s=0));o>=8;t[n+h]=255&a,h+=d,a/=256,o-=8);for(s=s<0;t[n+h]=255&s,h+=d,s/=256,c-=8);t[n+h-d]|=128*g}},function(t,e){var n={}.toString;t.exports=Array.isArray||function(t){return"[object Array]"==n.call(t)}},function(t,e,n){"use strict";var r=n(0),o=function(t,e){var n=t?"?"+t.split(".").slice(-1)[0].replace(/\|/g,"&"):"",o=function(t,e,n,o){return r.getQueryParam(t,e)||r.getQueryParam(n,o)},i=o("utm_source",e,"utmcsr",n),s=o("utm_medium",e,"utmcmd",n),a=o("utm_campaign",e,"utmccn",n),u=o("utm_term",e,"utmctr",n),c=o("utm_content",e,"utmcct",n),f={},p=function(t,e){r.isEmptyString(e)||(f[t]=e)};return p("utm_source",i),p("utm_medium",s),p("utm_campaign",a),p("utm_term",u),p("utm_content",c),f};t.exports=o},function(t,e,n){var r;!function(o){"use strict";function i(t,e){var n=(65535&t)+(65535&e);return(t>>16)+(e>>16)+(n>>16)<<16|65535&n}function s(t,e){return t<>>32-e}function a(t,e,n,r,o,a){return i(s(i(i(e,t),i(r,a)),o),n)}function u(t,e,n,r,o,i,s){return a(e&n|~e&r,t,e,o,i,s)}function c(t,e,n,r,o,i,s){return a(e&r|n&~r,t,e,o,i,s)}function f(t,e,n,r,o,i,s){return a(e^n^r,t,e,o,i,s)}function p(t,e,n,r,o,i,s){return a(n^(e|~r),t,e,o,i,s)}function l(t,e){t[e>>5]|=128<>>9<<4)]=e;var n,r,o,s,a,l=1732584193,h=-271733879,d=-1732584194,g=271733878;for(n=0;n>5]>>>e%32&255);return n}function d(t){var e,n=[];for(n[(t.length>>2)-1]=void 0,e=0;e>5]|=(255&t.charCodeAt(e/8))<16&&(o=l(o,8*t.length)),n=0;n<16;n+=1)i[n]=909522486^o[n],s[n]=1549556828^o[n];return r=l(i.concat(d(e)),512+8*e.length),h(l(s.concat(r),640))}function y(t){var e,n,r="0123456789abcdef",o="";for(n=0;n>>4&15)+r.charAt(15&e);return o}function m(t){return unescape(encodeURIComponent(t))}function w(t){return g(m(t))}function _(t){return y(w(t))}function b(t,e){return v(m(t),m(e))}function E(t,e){return y(b(t,e))}function I(t,e,n){return e?n?b(e,t):E(e,t):n?w(t):_(t)}void 0!==(r=function(){return I}.call(e,n,e,t))&&(t.exports=r)}()},function(t,e,n){function r(t,e){var n=i(t,e);return o(n)?n:void 0}var o=n(50),i=n(56);t.exports=r},function(t,e,n){function r(t){return!(!s(t)||i(t))&&(o(t)?d:c).test(a(t))}var o=n(17),i=n(53),s=n(7),a=n(55),u=/[\\^$.*+?()[\]{}|]/g,c=/^\[object .+?Constructor\]$/,f=Function.prototype,p=Object.prototype,l=f.toString,h=p.hasOwnProperty,d=RegExp("^"+l.call(h).replace(u,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$");t.exports=r},function(t,e,n){function r(t){var e=s.call(t,u),n=t[u];try{t[u]=void 0;var r=!0}catch(t){}var o=a.call(t);return r&&(e?t[u]=n:delete t[u]),o}var o=n(18),i=Object.prototype,s=i.hasOwnProperty,a=i.toString,u=o?o.toStringTag:void 0;t.exports=r},function(t,e){function n(t){return o.call(t)}var r=Object.prototype,o=r.toString;t.exports=n},function(t,e,n){function r(t){return!!i&&i in t}var o=n(54),i=function(){var t=/[^.]+$/.exec(o&&o.keys&&o.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}();t.exports=r},function(t,e,n){var r=n(6),o=r["__core-js_shared__"];t.exports=o},function(t,e){function n(t){if(null!=t){try{return o.call(t)}catch(t){}try{return t+""}catch(t){}}return""}var r=Function.prototype,o=r.toString;t.exports=n},function(t,e){function n(t,e){return null==t?void 0:t[e]}t.exports=n},function(t,e,n){function r(t,e,n,r){var s=!n;n||(n={});for(var a=-1,u=e.length;++a1?n[o-1]:void 0,a=o>2?n[2]:void 0;for(s=t.length>3&&"function"==typeof s?(o--,s):void 0,a&&i(n[0],n[1],a)&&(s=o<3?void 0:s,o=1),e=Object(e);++r0){if(++e>=r)return arguments[0]}else e=0;return t.apply(void 0,arguments)}}var r=800,o=16,i=Date.now;t.exports=n},function(t,e,n){function r(t,e,n){if(!a(n))return!1;var r=typeof e;return!!("number"==r?i(n)&&s(e,n.length):"string"==r&&e in n)&&o(n[e],t)}var o=n(20),i=n(8),s=n(23),a=n(7);t.exports=r},function(t,e,n){function r(t){return s(t)?o(t):i(t)}var o=n(68),i=n(79),s=n(8);t.exports=r},function(t,e,n){function r(t,e){var n=s(t),r=!n&&i(t),f=!n&&!r&&a(t),l=!n&&!r&&!f&&c(t),h=n||r||f||l,d=h?o(t.length,String):[],g=d.length;for(var v in t)!e&&!p.call(t,v)||h&&("length"==v||f&&("offset"==v||"parent"==v)||l&&("buffer"==v||"byteLength"==v||"byteOffset"==v)||u(v,g))||d.push(v);return d}var o=n(69),i=n(70),s=n(72),a=n(73),u=n(23),c=n(75),f=Object.prototype,p=f.hasOwnProperty;t.exports=r},function(t,e){function n(t,e){for(var n=-1,r=Array(t);++n0&&c>u&&(c=u);for(var f=0;f=0?(p=g.substr(0,v),l=g.substr(v+1)):(p=g,l=""),h=decodeURIComponent(p),d=decodeURIComponent(l),r(s,h)?o(s[h])?s[h].push(d):s[h]=[s[h],d]:s[h]=d}return s};var o=Array.isArray||function(t){return"[object Array]"===Object.prototype.toString.call(t)}},function(t,e,n){"use strict";function r(t,e){if(t.map)return t.map(e);for(var n=[],r=0;r0?2==o.length?"function"==typeof o[1]?t[o[0]]=o[1].call(this,s):t[o[0]]=o[1]:3==o.length?"function"!=typeof o[1]||o[1].exec&&o[1].test?t[o[0]]=s?s.replace(o[1],o[2]):void 0:t[o[0]]=s?o[1].call(this,s,o[2]):void 0:4==o.length&&(t[o[0]]=s?o[3].call(this,s.replace(o[1],o[2])):void 0):t[o]=s||void 0;a+=2}return t},str:function(t,e){for(var n in e)if("object"==typeof e[n]&&e[n].length>0){for(var r=0;r>e/4).toString(16):([1e7]+-1e3+-4e3+-8e3+-1e11).replace(/[018]/g,t)};t.exports=r},function(t,e,n){"use strict";t.exports={language:function(){return navigator&&(navigator.languages&&navigator.languages[0]||navigator.language||navigator.userLanguage)||void 0}()}}])}); \ No newline at end of file diff --git a/src/amplitude-client.js b/src/amplitude-client.js index f0f086af..7bd2c909 100644 --- a/src/amplitude-client.js +++ b/src/amplitude-client.js @@ -642,6 +642,19 @@ AmplitudeClient.prototype.setOptOut = function setOptOut(enable) { } }; +AmplitudeClient.prototype.setSessionId = function setSessionId(sessionId) { + if (!utils.validateInput(sessionId, 'sessionId', 'number')) { + return; + } + + try { + this._sessionId = sessionId; + _saveCookieData(this); + } catch (e) { + utils.log(e); + } +}; + /** * Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you * are doing. This can be used in conjunction with `setUserId(null)` to anonymize users after they log out. diff --git a/src/amplitude-snippet.js b/src/amplitude-snippet.js index 235a2829..5a545ce4 100644 --- a/src/amplitude-snippet.js +++ b/src/amplitude-snippet.js @@ -24,7 +24,7 @@ 'setOptOut', 'setVersionName', 'setDomain', 'setDeviceId', 'setGlobalUserProperties', 'identify', 'clearUserProperties', 'setGroup', 'logRevenueV2', 'regenerateDeviceId', - 'logEventWithTimestamp', 'logEventWithGroups']; + 'logEventWithTimestamp', 'logEventWithGroups', 'setSessionId']; function setUpProxy(instance) { function proxyMain(fn) { instance[fn] = function() { diff --git a/test/amplitude-client.js b/test/amplitude-client.js index 8e899a75..486f76af 100644 --- a/test/amplitude-client.js +++ b/test/amplitude-client.js @@ -2691,6 +2691,7 @@ describe('setVersionName', function() { describe('sessionId', function() { var clock; beforeEach(function() { + reset(); clock = sinon.useFakeTimers(); amplitude.init(apiKey); }); @@ -2721,5 +2722,42 @@ describe('setVersionName', function() { assert.equal(amplitude2.getSessionId(), timestamp); assert.equal(amplitude2.getSessionId(), amplitude2._sessionId); }); + + it('should ignore bad session id values', function() { + var timestamp = 1000; + clock.tick(timestamp); + var amplitude2 = new AmplitudeClient(); + amplitude2.init(apiKey); + assert.equal(amplitude2._sessionId, timestamp); + assert.equal(amplitude2.getSessionId(), timestamp); + assert.equal(amplitude2.getSessionId(), amplitude2._sessionId); + + amplitude2.setSessionId('invalid session id'); + assert.equal(amplitude2._sessionId, timestamp); + assert.equal(amplitude2.getSessionId(), timestamp); + assert.equal(amplitude2.getSessionId(), amplitude2._sessionId); + }); + + it('should let user override sessionId with setSessionId', function() { + var amplitude2 = new AmplitudeClient(); + var cookieStorage = new CookieStorage().getStorage(); + + // set up initial session + var sessionId = 1000; + clock.tick(sessionId); + amplitude2.init(apiKey); + assert.equal(amplitude2._sessionId, sessionId); + assert.equal(amplitude2.getSessionId(), sessionId); + assert.equal(amplitude2.getSessionId(), amplitude2._sessionId); + assert.equal(cookieStorage.get(amplitude2.options.cookieName).sessionId, sessionId); + + // override sessionId with setSessionId + var newSessionId = 10000; + amplitude2.setSessionId(newSessionId); + assert.equal(amplitude2._sessionId, newSessionId); + assert.equal(amplitude2.getSessionId(), newSessionId); + assert.equal(amplitude2.getSessionId(), amplitude2._sessionId); + assert.equal(cookieStorage.get(amplitude2.options.cookieName).sessionId, newSessionId); + }); }); });