@amplitude/plugin-web-attribution-browser
Advanced tools
Comparing version 2.1.7 to 2.1.8-beta.0
@@ -5,4 +5,4 @@ Object.defineProperty(exports, "__esModule", { value: true }); | ||
var analytics_client_common_1 = require("@amplitude/analytics-client-common"); | ||
var helpers_1 = require("./helpers"); | ||
var analytics_client_common_2 = require("@amplitude/analytics-client-common"); | ||
var analytics_client_common_3 = require("@amplitude/analytics-client-common"); | ||
var webAttributionPlugin = function (options) { | ||
@@ -15,20 +15,16 @@ var _this = this; | ||
setup: function (config, amplitude) { | ||
var _a; | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var pluginConfig, storage, storageKey, _b, currentCampaign, previousCampaign, isEventInNewSession, campaignEvent; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
var webAttribution, pluginConfig, currentCampaign, previousCampaign, isEventInNewSession, campaignEvent; | ||
return tslib_1.__generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
pluginConfig = tslib_1.__assign({ initialEmptyValue: 'EMPTY', resetSessionOnNewCampaign: false, excludeReferrers: (0, helpers_1.getDefaultExcludedReferrers)((_a = config.cookieOptions) === null || _a === void 0 ? void 0 : _a.domain) }, options); | ||
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.'); | ||
storage = config.cookieStorage; | ||
storageKey = (0, helpers_1.getStorageKey)(config.apiKey, 'MKTG'); | ||
return [4 /*yield*/, Promise.all([ | ||
new analytics_client_common_1.CampaignParser().parse(), | ||
storage.get(storageKey), | ||
])]; | ||
webAttribution = new analytics_client_common_1.WebAttribution(options, config); | ||
return [4 /*yield*/, webAttribution.init()]; | ||
case 1: | ||
_b = tslib_1.__read.apply(void 0, [_c.sent(), 2]), currentCampaign = _b[0], previousCampaign = _b[1]; | ||
isEventInNewSession = (0, analytics_client_common_2.isNewSession)(config.sessionTimeout, config.lastEventTime); | ||
if ((0, helpers_1.isNewCampaign)(currentCampaign, previousCampaign, pluginConfig, isEventInNewSession)) { | ||
_a.sent(); | ||
pluginConfig = webAttribution.options; | ||
currentCampaign = webAttribution.currentCampaign; | ||
previousCampaign = webAttribution.previousCampaign; | ||
isEventInNewSession = (0, analytics_client_common_3.isNewSession)(config.sessionTimeout, config.lastEventTime); | ||
if ((0, analytics_client_common_2.isNewCampaign)(currentCampaign, previousCampaign, pluginConfig, isEventInNewSession)) { | ||
if (pluginConfig.resetSessionOnNewCampaign) { | ||
@@ -39,5 +35,4 @@ amplitude.setSessionId(Date.now()); | ||
config.loggerProvider.log('Tracking attribution.'); | ||
campaignEvent = (0, helpers_1.createCampaignEvent)(currentCampaign, pluginConfig); | ||
campaignEvent = webAttribution.generateCampaignEvent(); | ||
amplitude.track(campaignEvent); | ||
void storage.set(storageKey, currentCampaign); | ||
} | ||
@@ -44,0 +39,0 @@ return [2 /*return*/]; |
@@ -1,4 +0,4 @@ | ||
import { __assign, __awaiter, __generator, __read } from "tslib"; | ||
import { CampaignParser } from '@amplitude/analytics-client-common'; | ||
import { createCampaignEvent, getDefaultExcludedReferrers, getStorageKey, isNewCampaign } from './helpers'; | ||
import { __awaiter, __generator } from "tslib"; | ||
import { WebAttribution } from '@amplitude/analytics-client-common'; | ||
import { isNewCampaign } from '@amplitude/analytics-client-common'; | ||
import { isNewSession } from '@amplitude/analytics-client-common'; | ||
@@ -12,18 +12,14 @@ export var webAttributionPlugin = function (options) { | ||
setup: function (config, amplitude) { | ||
var _a; | ||
return __awaiter(this, void 0, void 0, function () { | ||
var pluginConfig, storage, storageKey, _b, currentCampaign, previousCampaign, isEventInNewSession, campaignEvent; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
var webAttribution, pluginConfig, currentCampaign, previousCampaign, isEventInNewSession, campaignEvent; | ||
return __generator(this, function (_a) { | ||
switch (_a.label) { | ||
case 0: | ||
pluginConfig = __assign({ initialEmptyValue: 'EMPTY', resetSessionOnNewCampaign: false, excludeReferrers: getDefaultExcludedReferrers((_a = config.cookieOptions) === null || _a === void 0 ? void 0 : _a.domain) }, options); | ||
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.'); | ||
storage = config.cookieStorage; | ||
storageKey = getStorageKey(config.apiKey, 'MKTG'); | ||
return [4 /*yield*/, Promise.all([ | ||
new CampaignParser().parse(), | ||
storage.get(storageKey), | ||
])]; | ||
webAttribution = new WebAttribution(options, config); | ||
return [4 /*yield*/, webAttribution.init()]; | ||
case 1: | ||
_b = __read.apply(void 0, [_c.sent(), 2]), currentCampaign = _b[0], previousCampaign = _b[1]; | ||
_a.sent(); | ||
pluginConfig = webAttribution.options; | ||
currentCampaign = webAttribution.currentCampaign; | ||
previousCampaign = webAttribution.previousCampaign; | ||
isEventInNewSession = isNewSession(config.sessionTimeout, config.lastEventTime); | ||
@@ -36,5 +32,4 @@ if (isNewCampaign(currentCampaign, previousCampaign, pluginConfig, isEventInNewSession)) { | ||
config.loggerProvider.log('Tracking attribution.'); | ||
campaignEvent = createCampaignEvent(currentCampaign, pluginConfig); | ||
campaignEvent = webAttribution.generateCampaignEvent(); | ||
amplitude.track(campaignEvent); | ||
void storage.set(storageKey, currentCampaign); | ||
} | ||
@@ -41,0 +36,0 @@ return [2 /*return*/]; |
@@ -1,1 +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 u(e){try{f(n.next(e))}catch(e){o(e)}}function a(e){try{f(n.throw(e))}catch(e){o(e)}}function f(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}f((n=n.apply(e,t||[])).next())}))}function i(e,t){var r,n,i,o,u={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(f){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)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 u.label++,{value:a[1],done:!1};case 5:u.label++,n=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}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,f])}}}function o(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)u.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 u}var u,a,f,s=function(){var e,t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0;return(null===(e=null==t?void 0:t.location)||void 0===e?void 0:e.search)?t.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""}},c="dclid",d="fbclid",p="gbraid",v="gclid",y="ko_click_id",h="li_fat_id",m="msclkid",_="rtd_cid",g="ttclid",b="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},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({},w),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=s();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=s();return(e={})[c]=t[c],e[d]=t[d],e[p]=t[p],e[v]=t[v],e[y]=t[y],e[h]=t[h],e[m]=t[m],e[_]=t[_],e[g]=t[g],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"}(u||(u={})),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"}(f||(f={}));var O="AMP",P=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!T(t,r))return!1}return!0},T=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),u=o.next();!u.done;u=o.next()){var a=u.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{u&&!u.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},R=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(u.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(u.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(u.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(u.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(u.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(u.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(u.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(u.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(u.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[u.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[u.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===u.ADD?"number"==typeof r:e===u.UNSET||e===u.REMOVE||T(t,r)))},e}(),N=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},I=function(e,t,n,i){void 0===i&&(i=!0),e.referrer;var o=e.referring_domain,u=r(e,["referrer","referring_domain"]),a=t||{};a.referrer;var f=a.referring_domain,s=r(a,["referrer","referring_domain"]);if(A(n.excludeReferrers,e.referring_domain))return!1;if(!i&&function(e){return Object.values(e).every((function(e){return!e}))}(e)&&t)return!1;var l=JSON.stringify(u)!==JSON.stringify(s),c=N(o||"")!==N(f||"");return!t||l||c},A=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}))},x=function(e,r){var n,i,u=t(t({},w),e),a=Object.entries(u).reduce((function(e,t){var n,i=o(t,2),u=i[0],a=i[1];return e.setOnce("initial_".concat(u),null!==(n=null!=a?a:r.initialEmptyValue)&&void 0!==n?n:"EMPTY"),a?e.set(u,a):e.unset(u)}),new R);return n=a,t(t({},i),{event_type:f.IDENTIFY,user_properties:n.getUserProperties()})},D=function(e){var r=this;return void 0===e&&(e={}),{name:"@amplitude/plugin-web-attribution-browser",type:"before",setup:function(r,u){var a;return n(this,void 0,void 0,(function(){var n,f,s,l,c,d,p,v;return i(this,(function(i){switch(i.label){case 0:return n=t({initialEmptyValue:"EMPTY",resetSessionOnNewCampaign:!1,excludeReferrers:(b=null===(a=r.cookieOptions)||void 0===a?void 0:a.domain,E=b,E?(E.startsWith(".")&&(E=E.substring(1)),[new RegExp("".concat(E.replace(".","\\."),"$"))]):[])},e),r.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser."),f=r.cookieStorage,m=r.apiKey,void 0===(_="MKTG")&&(_=""),void 0===g&&(g=10),s=[O,_,m.substring(0,g)].filter(Boolean).join("_"),[4,Promise.all([(new S).parse(),f.get(s)])];case 1:return l=o.apply(void 0,[i.sent(),2]),c=l[0],d=l[1],y=r.sessionTimeout,void 0===(h=r.lastEventTime)&&(h=Date.now()),p=Date.now()-h>y,I(c,d,n,p)&&(n.resetSessionOnNewCampaign&&(u.setSessionId(Date.now()),r.loggerProvider.log("Created a new session for new campaign.")),r.loggerProvider.log("Tracking attribution."),v=x(c,n),u.track(v),f.set(s,c)),[2]}var y,h,m,_,g,b,E}))}))},execute:function(e){return n(r,void 0,void 0,(function(){return i(this,(function(t){return[2,e]}))}))}}};e.plugin=D,e.webAttributionPlugin=D,Object.defineProperty(e,"__esModule",{value:!0})})); | ||
!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 u(e){try{s(n.next(e))}catch(e){o(e)}}function a(e){try{s(n.throw(e))}catch(e){o(e)}}function s(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}s((n=n.apply(e,t||[])).next())}))}function i(e,t){var r,n,i,o,u={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(s){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)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 u.label++,{value:a[1],done:!1};case 5:u.label++,n=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}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,s])}}}function o(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)u.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 u}var u,a,s,c=function(){var e,t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0;return(null===(e=null==t?void 0:t.location)||void 0===e?void 0:e.search)?t.location.search.substring(1).split("&").filter(Boolean).reduce((function(e,t){var r=t.split("=",2),n=f(r[0]),i=f(r[1]);return i?(e[n]=i,e):e}),{}):{}},f=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},l="dclid",p="fbclid",d="gbraid",v="gclid",h="ko_click_id",y="li_fat_id",g="msclkid",m="rtd_cid",_="ttclid",b="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},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({},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={})[l]=t[l],e[p]=t[p],e[d]=t[d],e[v]=t[v],e[h]=t[h],e[y]=t[y],e[g]=t[g],e[m]=t[m],e[_]=t[_],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"}(u||(u={})),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"}(s||(s={}));var T="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),u=o.next();!u.done;u=o.next()){var a=u.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{u&&!u.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},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(u.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(u.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(u.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(u.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(u.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(u.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(u.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(u.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(u.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[u.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[u.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===u.ADD?"number"==typeof r:e===u.UNSET||e===u.REMOVE||P(t,r)))},e}(),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){void 0===i&&(i=!0),e.referrer;var o=e.referring_domain,u=r(e,["referrer","referring_domain"]),a=t||{};a.referrer;var s=a.referring_domain,c=r(a,["referrer","referring_domain"]);if(I(n.excludeReferrers,e.referring_domain))return!1;if(!i&&function(e){return Object.values(e).every((function(e){return!e}))}(e)&&t)return!1;var f=JSON.stringify(u)!==JSON.stringify(c),l=C(o||"")!==C(s||"");return!t||f||l},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,u=t(t({},w),e),a=Object.entries(u).reduce((function(e,t){var n,i=o(t,2),u=i[0],a=i[1];return e.setOnce("initial_".concat(u),null!==(n=null!=a?a:r.initialEmptyValue)&&void 0!==n?n:"EMPTY"),a?e.set(u,a):e.unset(u)}),new N);return n=a,t(t({},i),{event_type:s.IDENTIFY,user_properties:n.getUserProperties()})},A=function(){function e(e,r){var n,i,o,u,a,s;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=(u=r.apiKey,void 0===(a="MKTG")&&(a=""),void 0===s&&(s=10),[T,a,u.substring(0,s)].filter(Boolean).join("_")),this.currentCampaign=w,r.loggerProvider.log("Installing web attribution tracking.")}return e.prototype.init=function(){return n(this,void 0,void 0,(function(){var e;return i(this,(function(t){switch(t.label){case 0:return[4,this.fetchCampaign()];case 1:return e=o.apply(void 0,[t.sent(),2]),this.currentCampaign=e[0],this.previousCampaign=e[1],R(this.currentCampaign,this.previousCampaign,this.options)?(this.shouldTrackNewCampaign=!0,[4,this.storage.set(this.storageKey,this.currentCampaign)]):[3,3];case 2:t.sent(),t.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=k(this.currentCampaign,this.options);return e&&(t.event_id=e),t},e.prototype.shouldSetSessionIdOnNewCampaign=function(){return this.shouldTrackNewCampaign&&!!this.options.resetSessionOnNewCampaign},e}(),x=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,u,a,s,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,u=n.currentCampaign,a=n.previousCampaign,f=t.sessionTimeout,void 0===(l=t.lastEventTime)&&(l=Date.now()),s=Date.now()-l>f,R(u,a,o,s)&&(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]}var f,l}))}))},execute:function(e){return n(t,void 0,void 0,(function(){return i(this,(function(t){return[2,e]}))}))}}};e.plugin=x,e.webAttributionPlugin=x,Object.defineProperty(e,"__esModule",{value:!0})})); |
{ | ||
"name": "@amplitude/plugin-web-attribution-browser", | ||
"version": "2.1.7", | ||
"version": "2.1.8-beta.0", | ||
"description": "", | ||
@@ -39,3 +39,3 @@ "author": "Amplitude Inc", | ||
"dependencies": { | ||
"@amplitude/analytics-client-common": "^2.1.3", | ||
"@amplitude/analytics-client-common": "^2.1.4-beta.0", | ||
"@amplitude/analytics-core": "^2.2.4", | ||
@@ -46,3 +46,3 @@ "@amplitude/analytics-types": "^2.5.0", | ||
"devDependencies": { | ||
"@amplitude/analytics-browser": "^2.6.2", | ||
"@amplitude/analytics-browser": "^2.6.3-beta.0", | ||
"@rollup/plugin-commonjs": "^23.0.4", | ||
@@ -59,3 +59,3 @@ "@rollup/plugin-node-resolve": "^15.0.1", | ||
], | ||
"gitHead": "4820f115b7d250892c1c077242d24f22e329fa9c" | ||
"gitHead": "e55f597fcaed19a1deeb8ec02d8e623593a7b3e8" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 1 instance in 1 package
38259
35
180
1