@amplitude/plugin-web-attribution-browser 2.1.82 → 2.1.84

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).amplitude={})}(this,(function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},t.apply(this,arguments)};function r(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function n(e,t,r,n){return new(r||(r=Promise))((function(i,o){function s(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,a)}u((n=n.apply(e,t||[])).next())}))}function i(e,t){var r,n,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function o(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}"function"==typeof SuppressedError&&SuppressedError;var s,a,u=function(){var e,t,r=(t="ampIntegrationContext","undefined"!=typeof globalThis&&void 0!==globalThis[t]?globalThis[t]:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0);return(null===(e=null==r?void 0:r.location)||void 0===e?void 0:e.search)?r.location.search.substring(1).split("&").filter(Boolean).reduce((function(e,t){var r=t.split("=",2),n=c(r[0]),i=c(r[1]);return i?(e[n]=i,e):e}),{}):{}},c=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},f="dclid",l="fbclid",p="gbraid",d="gclid",h="ko_click_id",v="li_fat_id",g="msclkid",m="rdt_cid",y="ttclid",b="twclid",E="wbraid",_={utm_campaign:void 0,utm_content:void 0,utm_id:void 0,utm_medium:void 0,utm_source:void 0,utm_term:void 0,referrer:void 0,referring_domain:void 0,dclid:void 0,gbraid:void 0,gclid:void 0,fbclid:void 0,ko_click_id:void 0,li_fat_id:void 0,msclkid:void 0,rdt_cid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},S=function(){function e(){}return e.prototype.parse=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){return[2,t(t(t(t({},_),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=u();return{utm_campaign:e.utm_campaign,utm_content:e.utm_content,utm_id:e.utm_id,utm_medium:e.utm_medium,utm_source:e.utm_source,utm_term:e.utm_term}},e.prototype.getReferrer=function(){var e,t,r={referrer:void 0,referring_domain:void 0};try{r.referrer=document.referrer||void 0,r.referring_domain=null!==(t=null===(e=r.referrer)||void 0===e?void 0:e.split("/")[2])&&void 0!==t?t:void 0}catch(e){}return r},e.prototype.getClickIds=function(){var e,t=u();return(e={})[f]=t[f],e[l]=t[l],e[p]=t[p],e[d]=t[d],e[h]=t[h],e[v]=t[v],e[g]=t[g],e[m]=t[m],e[y]=t[y],e[b]=t[b],e[E]=t[E],e},e}();!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(s||(s={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(a||(a={}));var T,w="AMP",P=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!O(t,r))return!1}return!0},O=function(e,t){var r,n;if("string"!=typeof e)return!1;if(Array.isArray(t)){var i=!0;try{for(var o=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),s=o.next();!s.done;s=o.next()){var a=s.value;if(Array.isArray(a))return!1;if("object"==typeof a)i=i&&P(a);else if(!["number","string"].includes(typeof a))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return P(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},N=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return t({},this._properties)},e.prototype.set=function(e,t){return this._safeSet(T.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(T.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(T.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(T.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(T.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(T.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(T.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(T.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(T.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[T.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,r){if(this._validate(e,t,r)){var n=this._properties[e];return void 0===n&&(n={},this._properties[e]=n),n[t]=r,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,t,r){return void 0===this._properties[T.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===T.ADD?"number"==typeof r:e===T.UNSET||e===T.REMOVE||O(t,r)))},e}();!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(T||(T={})),T.CLEAR_ALL,T.UNSET,T.SET,T.SET_ONCE,T.ADD,T.APPEND,T.PREPEND,T.PREINSERT,T.POSTINSERT,T.REMOVE;var C=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},R=function(e,t,n,i,o){void 0===o&&(o=!0),e.referrer;var s=e.referring_domain,a=r(e,["referrer","referring_domain"]),u=t||{};u.referrer;var c=u.referring_domain,f=r(u,["referrer","referring_domain"]);if(I(n.excludeReferrers,e.referring_domain))return i.debug("This is not a new campaign because ".concat(e.referring_domain," is in the exclude referrer list.")),!1;if(!o&&function(e){return Object.values(e).every((function(e){return!e}))}(e)&&t)return i.debug("This is not a new campaign because this is a direct traffic in the same session."),!1;var l=JSON.stringify(a)!==JSON.stringify(f),p=C(s||"")!==C(c||""),d=!t||l||p;return d?i.debug("This is a new campaign. An $identify event will be sent."):i.debug("This is not a new campaign because it's the same as the previous one."),d},I=function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=""),e.some((function(e){return e instanceof RegExp?e.test(t):e===t}))},A=function(e,r){var n,i,s=t(t({},_),e),u=Object.entries(s).reduce((function(e,t){var n,i=o(t,2),s=i[0],a=i[1];return e.setOnce("initial_".concat(s),null!==(n=null!=a?a:r.initialEmptyValue)&&void 0!==n?n:"EMPTY"),a?e.set(s,a):e.unset(s)}),new N);return n=u,t(t({},i),{event_type:a.IDENTIFY,user_properties:n.getUserProperties()})},D=function(e,t){return void 0===t&&(t=Date.now()),Date.now()-t>e},$=function(){function e(e,r){var n,i,o,s,a,u;this.shouldTrackNewCampaign=!1,this.options=t({initialEmptyValue:"EMPTY",resetSessionOnNewCampaign:!1,excludeReferrers:(i=null===(n=r.cookieOptions)||void 0===n?void 0:n.domain,o=i,o?(o.startsWith(".")&&(o=o.substring(1)),[new RegExp("".concat(o.replace(".","\\."),"$"))]):[])},e),this.storage=r.cookieStorage,this.storageKey=(s=r.apiKey,void 0===(a="MKTG")&&(a=""),void 0===u&&(u=10),[w,a,s.substring(0,u)].filter(Boolean).join("_")),this.currentCampaign=_,this.sessionTimeout=r.sessionTimeout,this.lastEventTime=r.lastEventTime,this.logger=r.loggerProvider,r.loggerProvider.log("Installing web attribution tracking.")}return e.prototype.init=function(){return n(this,void 0,void 0,(function(){var e,t;return i(this,(function(r){switch(r.label){case 0:return[4,this.fetchCampaign()];case 1:return t=o.apply(void 0,[r.sent(),2]),this.currentCampaign=t[0],this.previousCampaign=t[1],e=!this.lastEventTime||D(this.sessionTimeout,this.lastEventTime),R(this.currentCampaign,this.previousCampaign,this.options,this.logger,e)?(this.shouldTrackNewCampaign=!0,[4,this.storage.set(this.storageKey,this.currentCampaign)]):[3,3];case 2:r.sent(),r.label=3;case 3:return[2]}}))}))},e.prototype.fetchCampaign=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){switch(e.label){case 0:return[4,Promise.all([(new S).parse(),this.storage.get(this.storageKey)])];case 1:return[2,e.sent()]}}))}))},e.prototype.generateCampaignEvent=function(e){this.shouldTrackNewCampaign=!1;var t=A(this.currentCampaign,this.options);return e&&(t.event_id=e),t},e.prototype.shouldSetSessionIdOnNewCampaign=function(){return this.shouldTrackNewCampaign&&!!this.options.resetSessionOnNewCampaign},e}(),k=function(e){var t=this;return void 0===e&&(e={}),{name:"@amplitude/plugin-web-attribution-browser",type:"before",setup:function(t,r){return n(this,void 0,void 0,(function(){var n,o,s,a,u,c;return i(this,(function(i){switch(i.label){case 0:return[4,(n=new $(e,t)).init()];case 1:return i.sent(),o=n.options,s=n.currentCampaign,a=n.previousCampaign,u=D(t.sessionTimeout,t.lastEventTime),R(s,a,o,t.loggerProvider,u)&&(o.resetSessionOnNewCampaign&&(r.setSessionId(Date.now()),t.loggerProvider.log("Created a new session for new campaign.")),t.loggerProvider.log("Tracking attribution."),c=n.generateCampaignEvent(),r.track(c)),[2]}}))}))},execute:function(e){return n(t,void 0,void 0,(function(){return i(this,(function(t){return[2,e]}))}))}}};e.plugin=k,e.webAttributionPlugin=k,Object.defineProperty(e,"__esModule",{value:!0})}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).amplitude={})}(this,function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},t.apply(this,arguments)};function r(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function n(e,t,r,n){return new(r||(r=Promise))(function(i,o){function s(e){try{u(n.next(e))}catch(e){o(e)}}function a(e){try{u(n.throw(e))}catch(e){o(e)}}function u(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r(function(e){e(t)})).then(s,a)}u((n=n.apply(e,t||[])).next())})}function i(e,t){var r,n,i,o={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]},s=Object.create(("function"==typeof Iterator?Iterator:Object).prototype);return s.next=a(0),s.throw=a(1),s.return=a(2),"function"==typeof Symbol&&(s[Symbol.iterator]=function(){return this}),s;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;s&&(s=0,a[0]&&(o=0)),o;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return o.label++,{value:a[1],done:!1};case 5:o.label++,n=a[1],a=[0];continue;case 7:a=o.ops.pop(),o.trys.pop();continue;default:if(!(i=o.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){o=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){o.label=a[1];break}if(6===a[0]&&o.label<i[1]){o.label=i[1],i=a;break}if(i&&o.label<i[2]){o.label=i[2],o.ops.push(a);break}i[2]&&o.ops.pop(),o.trys.pop();continue}a=t.call(e,o)}catch(e){a=[6,e],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,u])}}}function o(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),s=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)s.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return s}"function"==typeof SuppressedError&&SuppressedError;var s,a,u=function(){var e,t,r=(t="ampIntegrationContext","undefined"!=typeof globalThis&&void 0!==globalThis[t]?globalThis[t]:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0);return(null===(e=null==r?void 0:r.location)||void 0===e?void 0:e.search)?r.location.search.substring(1).split("&").filter(Boolean).reduce(function(e,t){var r=t.split("=",2),n=c(r[0]),i=c(r[1]);return i?(e[n]=i,e):e},{}):{}},c=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},f="dclid",l="fbclid",p="gbraid",d="gclid",h="ko_click_id",v="li_fat_id",g="msclkid",m="rdt_cid",y="ttclid",b="twclid",E="wbraid",_={utm_campaign:void 0,utm_content:void 0,utm_id:void 0,utm_medium:void 0,utm_source:void 0,utm_term:void 0,referrer:void 0,referring_domain:void 0,dclid:void 0,gbraid:void 0,gclid:void 0,fbclid:void 0,ko_click_id:void 0,li_fat_id:void 0,msclkid:void 0,rdt_cid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},S=function(){function e(){}return e.prototype.parse=function(){return n(this,void 0,void 0,function(){return i(this,function(e){return[2,t(t(t(t({},_),this.getUtmParam()),this.getReferrer()),this.getClickIds())]})})},e.prototype.getUtmParam=function(){var e=u();return{utm_campaign:e.utm_campaign,utm_content:e.utm_content,utm_id:e.utm_id,utm_medium:e.utm_medium,utm_source:e.utm_source,utm_term:e.utm_term}},e.prototype.getReferrer=function(){var e,t,r={referrer:void 0,referring_domain:void 0};try{r.referrer=document.referrer||void 0,r.referring_domain=null!==(t=null===(e=r.referrer)||void 0===e?void 0:e.split("/")[2])&&void 0!==t?t:void 0}catch(e){}return r},e.prototype.getClickIds=function(){var e,t=u();return(e={})[f]=t[f],e[l]=t[l],e[p]=t[p],e[d]=t[d],e[h]=t[h],e[v]=t[v],e[g]=t[g],e[m]=t[m],e[y]=t[y],e[b]=t[b],e[E]=t[E],e},e}();!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(s||(s={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(a||(a={}));var T,w="AMP",P=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!O(t,r))return!1}return!0},O=function(e,t){var r,n;if("string"!=typeof e)return!1;if(Array.isArray(t)){var i=!0;try{for(var o=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),s=o.next();!s.done;s=o.next()){var a=s.value;if(Array.isArray(a))return!1;if("object"==typeof a)i=i&&P(a);else if(!["number","string"].includes(typeof a))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{s&&!s.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return P(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},N=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return t({},this._properties)},e.prototype.set=function(e,t){return this._safeSet(T.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(T.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(T.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(T.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(T.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(T.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(T.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(T.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(T.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[T.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,r){if(this._validate(e,t,r)){var n=this._properties[e];return void 0===n&&(n={},this._properties[e]=n),n[t]=r,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,t,r){return void 0===this._properties[T.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===T.ADD?"number"==typeof r:e===T.UNSET||e===T.REMOVE||O(t,r)))},e}();!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(T||(T={})),T.CLEAR_ALL,T.UNSET,T.SET,T.SET_ONCE,T.ADD,T.APPEND,T.PREPEND,T.PREINSERT,T.POSTINSERT,T.REMOVE;var C=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},R=function(e,t,n,i,o){void 0===o&&(o=!0),e.referrer;var s=e.referring_domain,a=r(e,["referrer","referring_domain"]),u=t||{};u.referrer;var c=u.referring_domain,f=r(u,["referrer","referring_domain"]);if(I(n.excludeReferrers,e.referring_domain))return i.debug("This is not a new campaign because ".concat(e.referring_domain," is in the exclude referrer list.")),!1;if(!o&&function(e){return Object.values(e).every(function(e){return!e})}(e)&&t)return i.debug("This is not a new campaign because this is a direct traffic in the same session."),!1;var l=JSON.stringify(a)!==JSON.stringify(f),p=C(s||"")!==C(c||""),d=!t||l||p;return d?i.debug("This is a new campaign. An $identify event will be sent."):i.debug("This is not a new campaign because it's the same as the previous one."),d},I=function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=""),e.some(function(e){return e instanceof RegExp?e.test(t):e===t})},A=function(e,r){var n,i,s=t(t({},_),e),u=Object.entries(s).reduce(function(e,t){var n,i=o(t,2),s=i[0],a=i[1];return e.setOnce("initial_".concat(s),null!==(n=null!=a?a:r.initialEmptyValue)&&void 0!==n?n:"EMPTY"),a?e.set(s,a):e.unset(s)},new N);return n=u,t(t({},i),{event_type:a.IDENTIFY,user_properties:n.getUserProperties()})},D=function(e,t){return void 0===t&&(t=Date.now()),Date.now()-t>e},$=function(){function e(e,r){var n,i,o,s,a,u;this.shouldTrackNewCampaign=!1,this.options=t({initialEmptyValue:"EMPTY",resetSessionOnNewCampaign:!1,excludeReferrers:(i=null===(n=r.cookieOptions)||void 0===n?void 0:n.domain,o=i,o?(o.startsWith(".")&&(o=o.substring(1)),[new RegExp("".concat(o.replace(".","\\."),"$"))]):[])},e),this.storage=r.cookieStorage,this.storageKey=(s=r.apiKey,void 0===(a="MKTG")&&(a=""),void 0===u&&(u=10),[w,a,s.substring(0,u)].filter(Boolean).join("_")),this.currentCampaign=_,this.sessionTimeout=r.sessionTimeout,this.lastEventTime=r.lastEventTime,this.logger=r.loggerProvider,r.loggerProvider.log("Installing web attribution tracking.")}return e.prototype.init=function(){return n(this,void 0,void 0,function(){var e,t;return i(this,function(r){switch(r.label){case 0:return[4,this.fetchCampaign()];case 1:return t=o.apply(void 0,[r.sent(),2]),this.currentCampaign=t[0],this.previousCampaign=t[1],e=!this.lastEventTime||D(this.sessionTimeout,this.lastEventTime),R(this.currentCampaign,this.previousCampaign,this.options,this.logger,e)?(this.shouldTrackNewCampaign=!0,[4,this.storage.set(this.storageKey,this.currentCampaign)]):[3,3];case 2:r.sent(),r.label=3;case 3:return[2]}})})},e.prototype.fetchCampaign=function(){return n(this,void 0,void 0,function(){return i(this,function(e){switch(e.label){case 0:return[4,Promise.all([(new S).parse(),this.storage.get(this.storageKey)])];case 1:return[2,e.sent()]}})})},e.prototype.generateCampaignEvent=function(e){this.shouldTrackNewCampaign=!1;var t=A(this.currentCampaign,this.options);return e&&(t.event_id=e),t},e.prototype.shouldSetSessionIdOnNewCampaign=function(){return this.shouldTrackNewCampaign&&!!this.options.resetSessionOnNewCampaign},e}(),k=function(e){var t=this;return void 0===e&&(e={}),{name:"@amplitude/plugin-web-attribution-browser",type:"before",setup:function(t,r){return n(this,void 0,void 0,function(){var n,o,s,a,u,c;return i(this,function(i){switch(i.label){case 0:return[4,(n=new $(e,t)).init()];case 1:return i.sent(),o=n.options,s=n.currentCampaign,a=n.previousCampaign,u=D(t.sessionTimeout,t.lastEventTime),R(s,a,o,t.loggerProvider,u)&&(o.resetSessionOnNewCampaign&&(r.setSessionId(Date.now()),t.loggerProvider.log("Created a new session for new campaign.")),t.loggerProvider.log("Tracking attribution."),c=n.generateCampaignEvent(),r.track(c)),[2]}})})},execute:function(e){return n(t,void 0,void 0,function(){return i(this,function(t){return[2,e]})})}}};e.plugin=k,e.webAttributionPlugin=k,Object.defineProperty(e,"__esModule",{value:!0})});
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/plugin-web-attribution-browser",
3
- "version": "2.1.82",
3
+ "version": "2.1.84",
4
4
  "description": "",
5
5
  "author": "Amplitude Inc",
6
6
  "homepage": "https://github.com/amplitude/Amplitude-TypeScript",
@@ -37,13 +37,13 @@
37
37
  "url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
38
38
  },
39
39
  "dependencies": {
40
- "@amplitude/analytics-client-common": "^2.4.3",
40
+ "@amplitude/analytics-client-common": "^2.4.4",
41
41
  "@amplitude/analytics-core": "^2.26.2",
42
42
  "@amplitude/analytics-types": "^2.10.0",
43
43
  "tslib": "^2.4.1"
44
44
  },
45
45
  "devDependencies": {
46
- "@amplitude/analytics-browser": "^2.25.2",
46
+ "@amplitude/analytics-browser": "^2.25.4",
47
47
  "@rollup/plugin-commonjs": "^23.0.4",
48
48
  "@rollup/plugin-node-resolve": "^15.0.1",
49
49
  "@rollup/plugin-typescript": "^10.0.1",
@@ -55,5 +55,5 @@
55
55
  "files": [
56
56
  "lib"
57
57
  ],
58
- "gitHead": "3fb30ef85184a6b55503171f99be5648fc00651c"
58
+ "gitHead": "859b13ab478941c1544e90da196aa9323f96680e"
59
59
  }