@amplitude/plugin-web-attribution-browser 2.1.32 → 2.1.33

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.
package/lib/cjs/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  Object.defineProperty(exports, "__esModule", { value: true });
2
3
  exports.plugin = exports.webAttributionPlugin = void 0;
3
4
  var web_attribution_1 = require("./web-attribution");
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAAA,qDAAyD;AAAhD,uHAAA,oBAAoB,OAAA;AAC7B,qDAAmE;AAA1D,yGAAA,oBAAoB,OAAU","sourcesContent":["export { webAttributionPlugin } from './web-attribution';\nexport { webAttributionPlugin as plugin } from './web-attribution';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAyD;AAAhD,uHAAA,oBAAoB,OAAA;AAC7B,qDAAmE;AAA1D,yGAAA,oBAAoB,OAAU","sourcesContent":["export { webAttributionPlugin } from './web-attribution';\nexport { webAttributionPlugin as plugin } from './web-attribution';\n"]}
@@ -1,2 +1,3 @@
1
+ "use strict";
1
2
  Object.defineProperty(exports, "__esModule", { value: true });
2
3
  //# sourceMappingURL=web-attribution.js.map
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  Object.defineProperty(exports, "__esModule", { value: true });
2
3
  exports.webAttributionPlugin = void 0;
3
4
  var tslib_1 = require("tslib");
@@ -1 +1 @@
1
- {"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;AAEpE,8EAAmE;AAEnE,8EAAkE;AAElE;;;;;GAKG;AACI,IAAM,oBAAoB,GAA+B,UAAU,OAAqB;IAA/B,iBA8B/D;IA9ByE,wBAAA,EAAA,YAAqB;IAC7F,IAAM,MAAM,GAAiB;QAC3B,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,QAAQ;QAEd,KAAK,EAAE,UAAgB,MAAqB,EAAE,SAAwB;;;;;;4BAC9D,cAAc,GAAG,IAAI,wCAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;4BAC3D,qBAAM,cAAc,CAAC,IAAI,EAAE,EAAA;;4BAA3B,SAA2B,CAAC;4BAEtB,YAAY,GAAG,cAAc,CAAC,OAAO,CAAC;4BACtC,eAAe,GAAG,cAAc,CAAC,eAAe,CAAC;4BACjD,gBAAgB,GAAG,cAAc,CAAC,gBAAgB,CAAC;4BAEnD,mBAAmB,GAAG,IAAA,sCAAY,EAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;4BAEtF,IAAI,IAAA,uCAAa,EAAC,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,CAAC,cAAc,EAAE,mBAAmB,CAAC,EAAE;gCAC9G,IAAI,YAAY,CAAC,yBAAyB,EAAE;oCAC1C,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;oCACnC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;iCACtE;gCACD,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;gCAC7C,aAAa,GAAG,cAAc,CAAC,qBAAqB,EAAE,CAAC;gCAC7D,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;6BAChC;;;;;SACF;QAED,OAAO,EAAE,UAAO,KAAY;YAAK,sBAAA,KAAK,EAAA;iBAAA;KACvC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA9BW,QAAA,oBAAoB,wBA8B/B","sourcesContent":["import { WebAttribution } from '@amplitude/analytics-client-common';\nimport { BeforePlugin, BrowserClient, BrowserConfig, Event } from '@amplitude/analytics-types';\nimport { isNewCampaign } from '@amplitude/analytics-client-common';\nimport { CreateWebAttributionPlugin, Options } from './typings/web-attribution';\nimport { isNewSession } from '@amplitude/analytics-client-common';\n\n/**\n * @deprecated\n * This plugin is not used by @amplitude/analytics-browser and\n * is replaced by WebAttribution in @amplitude/analytics-client-common to\n * be able to send identify events before session start.\n */\nexport const webAttributionPlugin: CreateWebAttributionPlugin = function (options: Options = {}) {\n const plugin: BeforePlugin = {\n name: '@amplitude/plugin-web-attribution-browser',\n type: 'before',\n\n setup: async function (config: BrowserConfig, amplitude: BrowserClient) {\n const webAttribution = new WebAttribution(options, config);\n await webAttribution.init();\n\n const pluginConfig = webAttribution.options;\n const currentCampaign = webAttribution.currentCampaign;\n const previousCampaign = webAttribution.previousCampaign;\n\n const isEventInNewSession = isNewSession(config.sessionTimeout, config.lastEventTime);\n\n if (isNewCampaign(currentCampaign, previousCampaign, pluginConfig, config.loggerProvider, isEventInNewSession)) {\n if (pluginConfig.resetSessionOnNewCampaign) {\n amplitude.setSessionId(Date.now());\n config.loggerProvider.log('Created a new session for new campaign.');\n }\n config.loggerProvider.log('Tracking attribution.');\n const campaignEvent = webAttribution.generateCampaignEvent();\n amplitude.track(campaignEvent);\n }\n },\n\n execute: async (event: Event) => event,\n };\n\n return plugin;\n};\n"]}
1
+ {"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";;;;AAAA,8EAAoE;AAEpE,8EAAmE;AAEnE,8EAAkE;AAElE;;;;;GAKG;AACI,IAAM,oBAAoB,GAA+B,UAAU,OAAqB;IAA/B,iBA8B/D;IA9ByE,wBAAA,EAAA,YAAqB;IAC7F,IAAM,MAAM,GAAiB;QAC3B,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,QAAQ;QAEd,KAAK,EAAE,UAAgB,MAAqB,EAAE,SAAwB;;;;;;4BAC9D,cAAc,GAAG,IAAI,wCAAc,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;4BAC3D,qBAAM,cAAc,CAAC,IAAI,EAAE,EAAA;;4BAA3B,SAA2B,CAAC;4BAEtB,YAAY,GAAG,cAAc,CAAC,OAAO,CAAC;4BACtC,eAAe,GAAG,cAAc,CAAC,eAAe,CAAC;4BACjD,gBAAgB,GAAG,cAAc,CAAC,gBAAgB,CAAC;4BAEnD,mBAAmB,GAAG,IAAA,sCAAY,EAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;4BAEtF,IAAI,IAAA,uCAAa,EAAC,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,MAAM,CAAC,cAAc,EAAE,mBAAmB,CAAC,EAAE;gCAC9G,IAAI,YAAY,CAAC,yBAAyB,EAAE;oCAC1C,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;oCACnC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;iCACtE;gCACD,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;gCAC7C,aAAa,GAAG,cAAc,CAAC,qBAAqB,EAAE,CAAC;gCAC7D,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;6BAChC;;;;;SACF;QAED,OAAO,EAAE,UAAO,KAAY;YAAK,sBAAA,KAAK,EAAA;iBAAA;KACvC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AA9BW,QAAA,oBAAoB,wBA8B/B","sourcesContent":["import { WebAttribution } from '@amplitude/analytics-client-common';\nimport { BeforePlugin, BrowserClient, BrowserConfig, Event } from '@amplitude/analytics-types';\nimport { isNewCampaign } from '@amplitude/analytics-client-common';\nimport { CreateWebAttributionPlugin, Options } from './typings/web-attribution';\nimport { isNewSession } from '@amplitude/analytics-client-common';\n\n/**\n * @deprecated\n * This plugin is not used by @amplitude/analytics-browser and\n * is replaced by WebAttribution in @amplitude/analytics-client-common to\n * be able to send identify events before session start.\n */\nexport const webAttributionPlugin: CreateWebAttributionPlugin = function (options: Options = {}) {\n const plugin: BeforePlugin = {\n name: '@amplitude/plugin-web-attribution-browser',\n type: 'before',\n\n setup: async function (config: BrowserConfig, amplitude: BrowserClient) {\n const webAttribution = new WebAttribution(options, config);\n await webAttribution.init();\n\n const pluginConfig = webAttribution.options;\n const currentCampaign = webAttribution.currentCampaign;\n const previousCampaign = webAttribution.previousCampaign;\n\n const isEventInNewSession = isNewSession(config.sessionTimeout, config.lastEventTime);\n\n if (isNewCampaign(currentCampaign, previousCampaign, pluginConfig, config.loggerProvider, isEventInNewSession)) {\n if (pluginConfig.resetSessionOnNewCampaign) {\n amplitude.setSessionId(Date.now());\n config.loggerProvider.log('Created a new session for new campaign.');\n }\n config.loggerProvider.log('Tracking attribution.');\n const campaignEvent = webAttribution.generateCampaignEvent();\n amplitude.track(campaignEvent);\n }\n },\n\n execute: async (event: Event) => event,\n };\n\n return plugin;\n};\n"]}
@@ -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,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(u){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(s=0)),s;)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 s.label++,{value:a[1],done:!1};case 5:s.label++,n=a[1],a=[0];continue;case 7:a=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){s=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){s.label=a[1];break}if(6===a[0]&&s.label<i[1]){s.label=i[1],i=a;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(a);break}i[2]&&s.ops.pop(),s.trys.pop();continue}a=t.call(e,s)}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}var s,a,u,c=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=l(r[0]),i=l(r[1]);return i?(e[n]=i,e):e}),{}):{}},l=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},f="dclid",p="fbclid",d="gbraid",h="gclid",v="ko_click_id",g="li_fat_id",m="msclkid",y="rtd_cid",b="ttclid",_="twclid",E="wbraid",w={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,rtd_cid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},T=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({},w),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=c();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=c();return(e={})[f]=t[f],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[_]=t[_],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.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(a||(a={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(u||(u={}));var S="AMP",O=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!P(t,r))return!1}return!0},P=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&&O(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 O(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},C=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(s.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(s.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(s.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(s.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(s.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(s.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(s.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(s.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(s.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[s.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[s.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===s.ADD?"number"==typeof r:e===s.UNSET||e===s.REMOVE||P(t,r)))},e}(),N=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,l=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 f=JSON.stringify(a)!==JSON.stringify(l),p=N(s||"")!==N(c||""),d=!t||f||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}))},k=function(e,r){var n,i,s=t(t({},w),e),a=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 C);return n=a,t(t({},i),{event_type:u.IDENTIFY,user_properties:n.getUserProperties()})},x=function(e,t){return void 0===t&&(t=Date.now()),Date.now()-t>e},A=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),[S,a,s.substring(0,u)].filter(Boolean).join("_")),this.currentCampaign=w,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||x(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 T).parse(),this.storage.get(this.storageKey)])];case 1:return[2,e.sent()]}}))}))},e.prototype.generateCampaignEvent=function(e){this.shouldTrackNewCampaign=!1;var t=k(this.currentCampaign,this.options);return e&&(t.event_id=e),t},e.prototype.shouldSetSessionIdOnNewCampaign=function(){return this.shouldTrackNewCampaign&&!!this.options.resetSessionOnNewCampaign},e}(),$=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 A(e,t)).init()];case 1:return i.sent(),o=n.options,s=n.currentCampaign,a=n.previousCampaign,u=x(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=$,e.webAttributionPlugin=$,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{a(n.next(e))}catch(e){o(e)}}function u(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(s,u)}a((n=n.apply(e,t||[])).next())}))}function i(e,t){var r,n,i,o,s={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function u(u){return function(a){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(s=0)),s;)try{if(r=1,n&&(i=2&u[0]?n.return:u[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,u[1])).done)return i;switch(n=0,i&&(u=[2&u[0],i.value]),u[0]){case 0:case 1:i=u;break;case 4:return s.label++,{value:u[1],done:!1};case 5:s.label++,n=u[1],u=[0];continue;case 7:u=s.ops.pop(),s.trys.pop();continue;default:if(!(i=s.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){s=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){s.label=u[1];break}if(6===u[0]&&s.label<i[1]){s.label=i[1],i=u;break}if(i&&s.label<i[2]){s.label=i[2],s.ops.push(u);break}i[2]&&s.ops.pop(),s.trys.pop();continue}u=t.call(e,s)}catch(e){u=[6,e],n=0}finally{r=i=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,a])}}}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}var s,u,a,c=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=l(r[0]),i=l(r[1]);return i?(e[n]=i,e):e}),{}):{}},l=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},f="dclid",p="fbclid",d="gbraid",h="gclid",v="ko_click_id",g="li_fat_id",m="msclkid",y="rtd_cid",b="ttclid",_="twclid",E="wbraid",w={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,rtd_cid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},T=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({},w),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=c();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=c();return(e={})[f]=t[f],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[_]=t[_],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.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE_CURRENCY="$currency",e.REVENUE="$revenue"}(u||(u={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(a||(a={}));var S="AMP",O=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!P(t,r))return!1}return!0},P=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 u=s.value;if(Array.isArray(u))return!1;if("object"==typeof u)i=i&&O(u);else if(!["number","string"].includes(typeof u))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 O(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},C=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(s.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(s.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(s.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(s.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(s.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(s.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(s.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(s.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(s.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[s.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[s.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===s.ADD?"number"==typeof r:e===s.UNSET||e===s.REMOVE||P(t,r)))},e}(),N=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,u=r(e,["referrer","referring_domain"]),a=t||{};a.referrer;var c=a.referring_domain,l=r(a,["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 f=JSON.stringify(u)!==JSON.stringify(l),p=N(s||"")!==N(c||""),d=!t||f||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}))},k=function(e,r){var n,i,s=t(t({},w),e),u=Object.entries(s).reduce((function(e,t){var n,i=o(t,2),s=i[0],u=i[1];return e.setOnce("initial_".concat(s),null!==(n=null!=u?u:r.initialEmptyValue)&&void 0!==n?n:"EMPTY"),u?e.set(s,u):e.unset(s)}),new C);return n=u,t(t({},i),{event_type:a.IDENTIFY,user_properties:n.getUserProperties()})},x=function(e,t){return void 0===t&&(t=Date.now()),Date.now()-t>e},A=function(){function e(e,r){var n,i,o,s,u,a;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===(u="MKTG")&&(u=""),void 0===a&&(a=10),[S,u,s.substring(0,a)].filter(Boolean).join("_")),this.currentCampaign=w,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||x(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 T).parse(),this.storage.get(this.storageKey)])];case 1:return[2,e.sent()]}}))}))},e.prototype.generateCampaignEvent=function(e){this.shouldTrackNewCampaign=!1;var t=k(this.currentCampaign,this.options);return e&&(t.event_id=e),t},e.prototype.shouldSetSessionIdOnNewCampaign=function(){return this.shouldTrackNewCampaign&&!!this.options.resetSessionOnNewCampaign},e}(),$=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,u,a,c;return i(this,(function(i){switch(i.label){case 0:return[4,(n=new A(e,t)).init()];case 1:return i.sent(),o=n.options,s=n.currentCampaign,u=n.previousCampaign,a=x(t.sessionTimeout,t.lastEventTime),R(s,u,o,t.loggerProvider,a)&&(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=$,e.webAttributionPlugin=$,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.32",
3
+ "version": "2.1.33",
4
4
  "description": "",
5
5
  "author": "Amplitude Inc",
6
6
  "homepage": "https://github.com/amplitude/Amplitude-TypeScript",
@@ -36,13 +36,13 @@
36
36
  "url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@amplitude/analytics-client-common": "^2.3.7",
40
- "@amplitude/analytics-core": "^2.5.5",
41
- "@amplitude/analytics-types": "^2.8.4",
39
+ "@amplitude/analytics-client-common": "^2.3.8",
40
+ "@amplitude/analytics-core": "^2.5.6",
41
+ "@amplitude/analytics-types": "^2.9.0",
42
42
  "tslib": "^2.4.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@amplitude/analytics-browser": "^2.11.12",
45
+ "@amplitude/analytics-browser": "^2.11.13",
46
46
  "@rollup/plugin-commonjs": "^23.0.4",
47
47
  "@rollup/plugin-node-resolve": "^15.0.1",
48
48
  "@rollup/plugin-typescript": "^10.0.1",
@@ -54,5 +54,5 @@
54
54
  "files": [
55
55
  "lib"
56
56
  ],
57
- "gitHead": "d8f0e2f45827d6f65c621a1f232a3b897cff8d3c"
57
+ "gitHead": "e9b1fd973f86c5f262465f2d033b73a742697219"
58
58
  }