@amplitude/plugin-web-attribution-browser
Advanced tools
Comparing version 0.5.7 to 0.6.0-beta.0
@@ -0,1 +1,2 @@ | ||
import { BeforePlugin, BrowserClient } from '@amplitude/analytics-types'; | ||
export interface Options { | ||
@@ -7,2 +8,7 @@ disabled?: boolean; | ||
} | ||
export interface CreateWebAttributionPlugin { | ||
(client: BrowserClient, options?: Options): BeforePlugin; | ||
(options?: Options): BeforePlugin; | ||
} | ||
export type CreateWebAttributionPluginParameters = [BrowserClient, Options?] | [Options?]; | ||
//# sourceMappingURL=web-attribution.d.ts.map |
@@ -1,4 +0,3 @@ | ||
import { BeforePlugin, BrowserClient } from '@amplitude/analytics-types'; | ||
import { Options } from './typings/web-attribution'; | ||
export declare const webAttributionPlugin: (client: BrowserClient, options?: Options) => BeforePlugin; | ||
import { CreateWebAttributionPlugin } from './typings/web-attribution'; | ||
export declare const webAttributionPlugin: CreateWebAttributionPlugin; | ||
//# sourceMappingURL=web-attribution.d.ts.map |
@@ -1,53 +0,92 @@ | ||
var _this = this; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.webAttributionPlugin = void 0; | ||
var tslib_1 = require("tslib"); | ||
var analytics_client_common_1 = require("@amplitude/analytics-client-common"); | ||
var analytics_types_1 = require("@amplitude/analytics-types"); | ||
var plugin_campaign_tracker_1 = require("./plugin-campaign-tracker"); | ||
var webAttributionPlugin = function (client, options) { | ||
if (options === void 0) { options = {}; } | ||
return ({ | ||
var helpers_1 = require("./helpers"); | ||
var webAttributionPlugin = function () { | ||
var _this = this; | ||
var _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var amplitude; | ||
var options = {}; | ||
var _b = tslib_1.__read(args, 2), clientOrOptions = _b[0], configOrUndefined = _b[1]; | ||
if (clientOrOptions && 'init' in clientOrOptions) { | ||
amplitude = clientOrOptions; | ||
if (configOrUndefined) { | ||
options = configOrUndefined; | ||
} | ||
} | ||
else if (clientOrOptions) { | ||
options = clientOrOptions; | ||
} | ||
var excludeReferrers = (_a = options.excludeReferrers) !== null && _a !== void 0 ? _a : []; | ||
if (typeof location !== 'undefined') { | ||
excludeReferrers.unshift(location.hostname); | ||
} | ||
options = tslib_1.__assign(tslib_1.__assign({ disabled: false, initialEmptyValue: 'EMPTY', resetSessionOnNewCampaign: false }, options), { excludeReferrers: excludeReferrers }); | ||
var plugin = { | ||
name: 'web-attribution', | ||
type: analytics_types_1.PluginType.BEFORE, | ||
setup: function (config) { return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
var storage, campaignTracker; | ||
var _this = this; | ||
setup: function (config, client) { | ||
var _a; | ||
return tslib_1.__generator(this, function (_b) { | ||
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser'); | ||
// Disable "runAttributionStrategy" function | ||
if (!((_a = config.attribution) === null || _a === void 0 ? void 0 : _a.disabled)) { | ||
config.loggerProvider.warn('@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser'); | ||
config.attribution = { | ||
disabled: true, | ||
}; | ||
} | ||
storage = config.cookieStorage; | ||
campaignTracker = new plugin_campaign_tracker_1.PluginCampaignTracker(config.apiKey, storage, tslib_1.__assign({}, options)); | ||
// Web Attribution tracking | ||
void campaignTracker.onPageChange(function (_a) { | ||
var isNewCampaign = _a.isNewCampaign, currentCampaign = _a.currentCampaign; | ||
return tslib_1.__awaiter(_this, void 0, void 0, function () { | ||
return tslib_1.__generator(this, function (_b) { | ||
if (isNewCampaign) { | ||
return tslib_1.__awaiter(this, void 0, void 0, function () { | ||
var receivedType, storage, storageKey, _b, currentCampaign, previousCampaign, pluginEnabledOverride, campaignEvent; | ||
return tslib_1.__generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
amplitude = amplitude !== null && amplitude !== void 0 ? amplitude : client; | ||
if (!amplitude) { | ||
receivedType = clientOrOptions ? 'Options' : 'undefined'; | ||
config.loggerProvider.error("Argument of type '".concat(receivedType, "' is not assignable to parameter of type 'BrowserClient'.")); | ||
return [2 /*return*/]; | ||
} | ||
if (options.disabled) { | ||
config.loggerProvider.log('@amplitude/plugin-web-attribution-browser is disabled. Attribution is not tracked.'); | ||
return [2 /*return*/]; | ||
} | ||
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.'); | ||
if (!client && !((_a = config.attribution) === null || _a === void 0 ? void 0 : _a.disabled)) { | ||
config.loggerProvider.warn('@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser. Resolve by disabling web attribution tracking in @amplitude/analytics-browser.'); | ||
config.attribution = { | ||
disabled: true, | ||
}; | ||
} | ||
storage = config.cookieStorage; | ||
storageKey = (0, helpers_1.getStorageKey)(config.apiKey); | ||
return [4 /*yield*/, Promise.all([ | ||
new analytics_client_common_1.CampaignParser().parse(), | ||
storage.get(storageKey), | ||
])]; | ||
case 1: | ||
_b = tslib_1.__read.apply(void 0, [_c.sent(), 2]), currentCampaign = _b[0], previousCampaign = _b[1]; | ||
pluginEnabledOverride = this.__pluginEnabledOverride; | ||
if (pluginEnabledOverride !== null && pluginEnabledOverride !== void 0 ? pluginEnabledOverride : (0, helpers_1.isNewCampaign)(currentCampaign, previousCampaign, options)) { | ||
if (options.resetSessionOnNewCampaign) { | ||
client.setSessionId(Date.now()); | ||
config.loggerProvider.log('Created a new session for new campaign'); | ||
amplitude.setSessionId(Date.now()); | ||
config.loggerProvider.log('Created a new session for new campaign.'); | ||
} | ||
config.loggerProvider.log('Tracking new campaign event'); | ||
void client.track(campaignTracker.createCampaignEvent(currentCampaign)); | ||
config.loggerProvider.log('Tracking attribution.'); | ||
campaignEvent = (0, helpers_1.createCampaignEvent)(currentCampaign, options); | ||
amplitude.track(campaignEvent); | ||
void storage.set(storageKey, currentCampaign); | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
} | ||
}); | ||
return [2 /*return*/]; | ||
}); | ||
}); }, | ||
}, | ||
execute: function (event) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { | ||
return [2 /*return*/, event]; | ||
}); }); }, | ||
}); | ||
}; | ||
// For Amplitude-internal functionality | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
plugin.__pluginEnabledOverride = undefined; | ||
return plugin; | ||
}; | ||
exports.webAttributionPlugin = webAttributionPlugin; | ||
//# sourceMappingURL=web-attribution.js.map |
@@ -0,1 +1,2 @@ | ||
import { BeforePlugin, BrowserClient } from '@amplitude/analytics-types'; | ||
export interface Options { | ||
@@ -7,2 +8,7 @@ disabled?: boolean; | ||
} | ||
export interface CreateWebAttributionPlugin { | ||
(client: BrowserClient, options?: Options): BeforePlugin; | ||
(options?: Options): BeforePlugin; | ||
} | ||
export type CreateWebAttributionPluginParameters = [BrowserClient, Options?] | [Options?]; | ||
//# sourceMappingURL=web-attribution.d.ts.map |
@@ -1,4 +0,3 @@ | ||
import { BeforePlugin, BrowserClient } from '@amplitude/analytics-types'; | ||
import { Options } from './typings/web-attribution'; | ||
export declare const webAttributionPlugin: (client: BrowserClient, options?: Options) => BeforePlugin; | ||
import { CreateWebAttributionPlugin } from './typings/web-attribution'; | ||
export declare const webAttributionPlugin: CreateWebAttributionPlugin; | ||
//# sourceMappingURL=web-attribution.d.ts.map |
@@ -1,48 +0,89 @@ | ||
import { __assign, __awaiter, __generator } from "tslib"; | ||
import { __assign, __awaiter, __generator, __read } from "tslib"; | ||
import { CampaignParser } from '@amplitude/analytics-client-common'; | ||
import { PluginType, } from '@amplitude/analytics-types'; | ||
import { PluginCampaignTracker } from './plugin-campaign-tracker'; | ||
export var webAttributionPlugin = function (client, options) { | ||
if (options === void 0) { options = {}; } | ||
return ({ | ||
import { createCampaignEvent, getStorageKey, isNewCampaign } from './helpers'; | ||
export var webAttributionPlugin = function () { | ||
var _this = this; | ||
var _a; | ||
var args = []; | ||
for (var _i = 0; _i < arguments.length; _i++) { | ||
args[_i] = arguments[_i]; | ||
} | ||
var amplitude; | ||
var options = {}; | ||
var _b = __read(args, 2), clientOrOptions = _b[0], configOrUndefined = _b[1]; | ||
if (clientOrOptions && 'init' in clientOrOptions) { | ||
amplitude = clientOrOptions; | ||
if (configOrUndefined) { | ||
options = configOrUndefined; | ||
} | ||
} | ||
else if (clientOrOptions) { | ||
options = clientOrOptions; | ||
} | ||
var excludeReferrers = (_a = options.excludeReferrers) !== null && _a !== void 0 ? _a : []; | ||
if (typeof location !== 'undefined') { | ||
excludeReferrers.unshift(location.hostname); | ||
} | ||
options = __assign(__assign({ disabled: false, initialEmptyValue: 'EMPTY', resetSessionOnNewCampaign: false }, options), { excludeReferrers: excludeReferrers }); | ||
var plugin = { | ||
name: 'web-attribution', | ||
type: PluginType.BEFORE, | ||
setup: function (config) { return __awaiter(void 0, void 0, void 0, function () { | ||
var storage, campaignTracker; | ||
setup: function (config, client) { | ||
var _a; | ||
return __generator(this, function (_b) { | ||
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser'); | ||
// Disable "runAttributionStrategy" function | ||
if (!((_a = config.attribution) === null || _a === void 0 ? void 0 : _a.disabled)) { | ||
config.loggerProvider.warn('@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser'); | ||
config.attribution = { | ||
disabled: true, | ||
}; | ||
} | ||
storage = config.cookieStorage; | ||
campaignTracker = new PluginCampaignTracker(config.apiKey, storage, __assign({}, options)); | ||
// Web Attribution tracking | ||
void campaignTracker.onPageChange(function (_a) { | ||
var isNewCampaign = _a.isNewCampaign, currentCampaign = _a.currentCampaign; | ||
return __awaiter(void 0, void 0, void 0, function () { | ||
return __generator(this, function (_b) { | ||
if (isNewCampaign) { | ||
return __awaiter(this, void 0, void 0, function () { | ||
var receivedType, storage, storageKey, _b, currentCampaign, previousCampaign, pluginEnabledOverride, campaignEvent; | ||
return __generator(this, function (_c) { | ||
switch (_c.label) { | ||
case 0: | ||
amplitude = amplitude !== null && amplitude !== void 0 ? amplitude : client; | ||
if (!amplitude) { | ||
receivedType = clientOrOptions ? 'Options' : 'undefined'; | ||
config.loggerProvider.error("Argument of type '".concat(receivedType, "' is not assignable to parameter of type 'BrowserClient'.")); | ||
return [2 /*return*/]; | ||
} | ||
if (options.disabled) { | ||
config.loggerProvider.log('@amplitude/plugin-web-attribution-browser is disabled. Attribution is not tracked.'); | ||
return [2 /*return*/]; | ||
} | ||
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.'); | ||
if (!client && !((_a = config.attribution) === null || _a === void 0 ? void 0 : _a.disabled)) { | ||
config.loggerProvider.warn('@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser. Resolve by disabling web attribution tracking in @amplitude/analytics-browser.'); | ||
config.attribution = { | ||
disabled: true, | ||
}; | ||
} | ||
storage = config.cookieStorage; | ||
storageKey = getStorageKey(config.apiKey); | ||
return [4 /*yield*/, Promise.all([ | ||
new CampaignParser().parse(), | ||
storage.get(storageKey), | ||
])]; | ||
case 1: | ||
_b = __read.apply(void 0, [_c.sent(), 2]), currentCampaign = _b[0], previousCampaign = _b[1]; | ||
pluginEnabledOverride = this.__pluginEnabledOverride; | ||
if (pluginEnabledOverride !== null && pluginEnabledOverride !== void 0 ? pluginEnabledOverride : isNewCampaign(currentCampaign, previousCampaign, options)) { | ||
if (options.resetSessionOnNewCampaign) { | ||
client.setSessionId(Date.now()); | ||
config.loggerProvider.log('Created a new session for new campaign'); | ||
amplitude.setSessionId(Date.now()); | ||
config.loggerProvider.log('Created a new session for new campaign.'); | ||
} | ||
config.loggerProvider.log('Tracking new campaign event'); | ||
void client.track(campaignTracker.createCampaignEvent(currentCampaign)); | ||
config.loggerProvider.log('Tracking attribution.'); | ||
campaignEvent = createCampaignEvent(currentCampaign, options); | ||
amplitude.track(campaignEvent); | ||
void storage.set(storageKey, currentCampaign); | ||
} | ||
return [2 /*return*/]; | ||
}); | ||
}); | ||
} | ||
}); | ||
return [2 /*return*/]; | ||
}); | ||
}); }, | ||
execute: function (event) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { | ||
}, | ||
execute: function (event) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) { | ||
return [2 /*return*/, event]; | ||
}); }); }, | ||
}); | ||
}; | ||
// For Amplitude-internal functionality | ||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access | ||
plugin.__pluginEnabledOverride = undefined; | ||
return plugin; | ||
}; | ||
//# sourceMappingURL=web-attribution.js.map |
@@ -1,1 +0,1 @@ | ||
var webAttribution=function(e){"use strict";var t,r,n,i,o=function(){return o=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},o.apply(this,arguments)};function a(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 u(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{s(n.next(e))}catch(e){o(e)}}function u(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(a,u)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,i,o,a={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(s){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)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 a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){a.label=u[1];break}if(6===u[0]&&a.label<i[1]){a.label=i[1],i=u;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(u);break}i[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}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,s])}}}!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={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(r||(r={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(n||(n={})),function(e){e.BEFORE="before",e.ENRICHMENT="enrichment",e.DESTINATION="destination"}(i||(i={}));var 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=p(r[0]),i=p(r[1]);return i?(e[n]=i,e):e}),{}):{}},p=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},f="dclid",l="fbclid",d="gbraid",g="gclid",h="ko_click_id",v="msclkid",m="ttclid",y="twclid",b="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,msclkid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},E=function(){function e(){}return e.prototype.parse=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){return[2,o(o(o(o({},_),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[l]=t[l],e[d]=t[d],e[g]=t[g],e[h]=t[h],e[v]=t[v],e[m]=t[m],e[y]=t[y],e[b]=t[b],e},e}(),w="AMP",S=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!C(t,r))return!1}return!0},C=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),a=o.next();!a.done;a=o.next()){var u=a.value;if(Array.isArray(u))return!1;if("object"==typeof u)i=i&&S(u);else if(!["number","string"].includes(typeof u))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return S(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 o({},this._properties)},e.prototype.set=function(e,r){return this._safeSet(t.SET,e,r),this},e.prototype.setOnce=function(e,r){return this._safeSet(t.SET_ONCE,e,r),this},e.prototype.append=function(e,r){return this._safeSet(t.APPEND,e,r),this},e.prototype.prepend=function(e,r){return this._safeSet(t.PREPEND,e,r),this},e.prototype.postInsert=function(e,r){return this._safeSet(t.POSTINSERT,e,r),this},e.prototype.preInsert=function(e,r){return this._safeSet(t.PREINSERT,e,r),this},e.prototype.remove=function(e,r){return this._safeSet(t.REMOVE,e,r),this},e.prototype.add=function(e,r){return this._safeSet(t.ADD,e,r),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,r,n){return void 0===this._properties[t.CLEAR_ALL]&&(!this._propertySet.has(r)&&(e===t.ADD?"number"==typeof n:e===t.UNSET||e===t.REMOVE||C(r,n)))},e}(),P=function(){function e(e,t){var r,n;this.storage=t.storage,this.storageKey=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[w,t,e.substring(0,r)].filter(Boolean).join("_")}(e,"MKTG"),this.parser=new E,this.track=t.track,this.onNewCampaign=t.onNewCampaign,this.disabled=Boolean(t.disabled),this.trackNewCampaigns=Boolean(t.trackNewCampaigns),this.trackPageViews=Boolean(t.trackPageViews),this.excludeReferrers=null!==(r=t.excludeReferrers)&&void 0!==r?r:[],"undefined"!=typeof location&&this.excludeReferrers.unshift(location.hostname),this.initialEmptyValue=null!==(n=t.initialEmptyValue)&&void 0!==n?n:"EMPTY"}return e.prototype.isNewCampaign=function(e,t,r){void 0===r&&(r=!1),e.referrer;var n=e.referring_domain,i=a(e,["referrer","referring_domain"]),o=t||{};o.referrer;var u=o.referring_domain,s=a(o,["referrer","referring_domain"]);if(e.referring_domain&&this.excludeReferrers.includes(e.referring_domain))return!1;var c=JSON.stringify(i)!==JSON.stringify(s),p=r?T(n||"")!==T(u||""):n!==u;return!t||c||p},e.prototype.saveCampaignToStorage=function(e){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.storage.set(this.storageKey,e)];case 1:return t.sent(),[2]}}))}))},e.prototype.getCampaignFromStorage=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.storage.get(this.storageKey)];case 1:return[2,e.sent()]}}))}))},e.prototype.createCampaignEvent=function(e){var t,r,i=this,a=o(o({},_),e),u=Object.entries(a).reduce((function(e,t){var r=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)a.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 a}(t,2),n=r[0],o=r[1];return e.setOnce("initial_".concat(n),o||i.initialEmptyValue),o?e.set(n,o):e.unset(n)}),new N),s={event_type:"Page View",event_properties:{page_title:"undefined"!=typeof document&&document.title||"",page_location:"undefined"!=typeof location&&location.href||"",page_path:"undefined"!=typeof location&&location.pathname||""}};return o(o({},(t=u,o(o({},r),{event_type:n.IDENTIFY,user_properties:t.getUserProperties()}))),this.trackPageViews&&s)},e.prototype.send=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return this.disabled?[2]:[4,this.parser.parse()];case 1:return t=n.sent(),[4,this.getCampaignFromStorage()];case 2:if(r=n.sent(),!e){if(!this.trackNewCampaigns||!this.isNewCampaign(t,r))return[2];this.onNewCampaign(t)}return[4,this.track(this.createCampaignEvent(t))];case 3:return n.sent(),[4,this.saveCampaignToStorage(t)];case 4:return n.sent(),[2]}}))}))},e}(),T=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},O=function(){function e(e,t,r){this.campaignTracker=new P(e,o(o({},r),{trackPageViews:!1,track:function(){return Promise.resolve()},onNewCampaign:function(){return function(){}},storage:t}))}return e.prototype.createCampaignEvent=function(e){return this.campaignTracker.createCampaignEvent(e)},e.prototype.onPageChange=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return t=e,[4,this.getCurrentState()];case 1:return[4,t.apply(void 0,[n.sent()])];case 2:return n.sent(),[4,this.getCurrentState()];case 3:return(r=n.sent()).isNewCampaign&&this.campaignTracker.saveCampaignToStorage(r.currentCampaign),[2]}}))}))},e.prototype.getCurrentState=function(){return u(this,void 0,void 0,(function(){var e,t,r,n;return s(this,(function(i){switch(i.label){case 0:return[4,this.campaignTracker.parser.parse()];case 1:return e=i.sent(),r=(t=this.campaignTracker).isNewCampaign,n=[e],[4,this.campaignTracker.getCampaignFromStorage()];case 2:return[2,{isNewCampaign:r.apply(t,n.concat([i.sent(),!0])),currentCampaign:e}]}}))}))},e}(),k=function(e,t){return void 0===t&&(t={}),{name:"web-attribution",type:i.BEFORE,setup:function(r){return u(void 0,void 0,void 0,(function(){var n,i,a;return s(this,(function(c){return r.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser"),(null===(a=r.attribution)||void 0===a?void 0:a.disabled)||(r.loggerProvider.warn("@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser"),r.attribution={disabled:!0}),n=r.cookieStorage,(i=new O(r.apiKey,n,o({},t))).onPageChange((function(n){var o=n.isNewCampaign,a=n.currentCampaign;return u(void 0,void 0,void 0,(function(){return s(this,(function(n){return o&&(t.resetSessionOnNewCampaign&&(e.setSessionId(Date.now()),r.loggerProvider.log("Created a new session for new campaign")),r.loggerProvider.log("Tracking new campaign event"),e.track(i.createCampaignEvent(a))),[2]}))}))})),[2]}))}))},execute:function(e){return u(void 0,void 0,void 0,(function(){return s(this,(function(t){return[2,e]}))}))}}},R=Object.freeze({__proto__:null});return e.Types=R,e.plugin=k,e.webAttributionPlugin=k,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); | ||
var webAttribution=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{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}l((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(l){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,l])}}}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,l,s,f=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=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""}},d="dclid",p="fbclid",v="gbraid",y="gclid",b="ko_click_id",g="msclkid",h="ttclid",m="twclid",_="wbraid",E={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,msclkid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},w=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({},E),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=f();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=f();return(e={})[d]=t[d],e[p]=t[p],e[v]=t[v],e[y]=t[y],e[b]=t[b],e[g]=t[g],e[h]=t[h],e[m]=t[m],e[_]=t[_],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"}(l||(l={})),function(e){e.BEFORE="before",e.ENRICHMENT="enrichment",e.DESTINATION="destination"}(s||(s={}));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),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},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||P(t,r)))},e}(),T=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[S,t,e.substring(0,r)].filter(Boolean).join("_")},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){var i;e.referrer;var o=e.referring_domain,u=r(e,["referrer","referring_domain"]),a=t||{};a.referrer;var l=a.referring_domain,s=r(a,["referrer","referring_domain"]);if(e.referring_domain&&(null===(i=n.excludeReferrers)||void 0===i?void 0:i.includes(e.referring_domain)))return!1;var f=JSON.stringify(u)!==JSON.stringify(s),c=N(o||"")!==N(l||"");return!t||f||c},A=function(e,r){var n,i,u=t(t({},E),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:l.IDENTIFY,user_properties:n.getUserProperties()})},k=function(){for(var e,r,u=this,a=[],l=0;l<arguments.length;l++)a[l]=arguments[l];var f={},c=o(a,2),d=c[0],p=c[1];d&&"init"in d?(r=d,p&&(f=p)):d&&(f=d);var v=null!==(e=f.excludeReferrers)&&void 0!==e?e:[];"undefined"!=typeof location&&v.unshift(location.hostname),f=t(t({disabled:!1,initialEmptyValue:"EMPTY",resetSessionOnNewCampaign:!1},f),{excludeReferrers:v});var y={name:"web-attribution",type:s.BEFORE,setup:function(e,t){var u;return n(this,void 0,void 0,(function(){var n,a,l,s,c,p,v,y;return i(this,(function(i){switch(i.label){case 0:return(r=null!=r?r:t)?f.disabled?(e.loggerProvider.log("@amplitude/plugin-web-attribution-browser is disabled. Attribution is not tracked."),[2]):(e.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser."),t||(null===(u=e.attribution)||void 0===u?void 0:u.disabled)||(e.loggerProvider.warn("@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser. Resolve by disabling web attribution tracking in @amplitude/analytics-browser."),e.attribution={disabled:!0}),a=e.cookieStorage,l=T(e.apiKey),[4,Promise.all([(new w).parse(),a.get(l)])]):(n=d?"Options":"undefined",e.loggerProvider.error("Argument of type '".concat(n,"' is not assignable to parameter of type 'BrowserClient'.")),[2]);case 1:return s=o.apply(void 0,[i.sent(),2]),c=s[0],p=s[1],(null!=(v=this.__pluginEnabledOverride)?v:I(c,p,f))&&(f.resetSessionOnNewCampaign&&(r.setSessionId(Date.now()),e.loggerProvider.log("Created a new session for new campaign.")),e.loggerProvider.log("Tracking attribution."),y=A(c,f),r.track(y),a.set(l,c)),[2]}}))}))},execute:function(e){return n(u,void 0,void 0,(function(){return i(this,(function(t){return[2,e]}))}))},__pluginEnabledOverride:void 0};return y},D=Object.freeze({__proto__:null});return e.Types=D,e.plugin=k,e.webAttributionPlugin=k,Object.defineProperty(e,"__esModule",{value:!0}),e}({}); |
@@ -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,r,n,i,o=function(){return o=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},o.apply(this,arguments)};function a(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 u(e,t,r,n){return new(r||(r=Promise))((function(i,o){function a(e){try{s(n.next(e))}catch(e){o(e)}}function u(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(a,u)}s((n=n.apply(e,t||[])).next())}))}function s(e,t){var r,n,i,o,a={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(s){return function(u){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,u[0]&&(a=0)),a;)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 a.label++,{value:u[1],done:!1};case 5:a.label++,n=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!i||u[1]>i[0]&&u[1]<i[3])){a.label=u[1];break}if(6===u[0]&&a.label<i[1]){a.label=i[1],i=u;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(u);break}i[2]&&a.ops.pop(),a.trys.pop();continue}u=t.call(e,a)}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,s])}}}!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={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(r||(r={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(n||(n={})),function(e){e.BEFORE="before",e.ENRICHMENT="enrichment",e.DESTINATION="destination"}(i||(i={}));var 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""}},p="dclid",l="fbclid",d="gbraid",g="gclid",h="ko_click_id",v="msclkid",m="ttclid",y="twclid",b="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,msclkid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},E=function(){function e(){}return e.prototype.parse=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){return[2,o(o(o(o({},_),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={})[p]=t[p],e[l]=t[l],e[d]=t[d],e[g]=t[g],e[h]=t[h],e[v]=t[v],e[m]=t[m],e[y]=t[y],e[b]=t[b],e},e}(),w="AMP",S=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!C(t,r))return!1}return!0},C=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),a=o.next();!a.done;a=o.next()){var u=a.value;if(Array.isArray(u))return!1;if("object"==typeof u)i=i&&S(u);else if(!["number","string"].includes(typeof u))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{a&&!a.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return S(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 o({},this._properties)},e.prototype.set=function(e,r){return this._safeSet(t.SET,e,r),this},e.prototype.setOnce=function(e,r){return this._safeSet(t.SET_ONCE,e,r),this},e.prototype.append=function(e,r){return this._safeSet(t.APPEND,e,r),this},e.prototype.prepend=function(e,r){return this._safeSet(t.PREPEND,e,r),this},e.prototype.postInsert=function(e,r){return this._safeSet(t.POSTINSERT,e,r),this},e.prototype.preInsert=function(e,r){return this._safeSet(t.PREINSERT,e,r),this},e.prototype.remove=function(e,r){return this._safeSet(t.REMOVE,e,r),this},e.prototype.add=function(e,r){return this._safeSet(t.ADD,e,r),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,r,n){return void 0===this._properties[t.CLEAR_ALL]&&(!this._propertySet.has(r)&&(e===t.ADD?"number"==typeof n:e===t.UNSET||e===t.REMOVE||C(r,n)))},e}(),T=function(){function e(e,t){var r,n;this.storage=t.storage,this.storageKey=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[w,t,e.substring(0,r)].filter(Boolean).join("_")}(e,"MKTG"),this.parser=new E,this.track=t.track,this.onNewCampaign=t.onNewCampaign,this.disabled=Boolean(t.disabled),this.trackNewCampaigns=Boolean(t.trackNewCampaigns),this.trackPageViews=Boolean(t.trackPageViews),this.excludeReferrers=null!==(r=t.excludeReferrers)&&void 0!==r?r:[],"undefined"!=typeof location&&this.excludeReferrers.unshift(location.hostname),this.initialEmptyValue=null!==(n=t.initialEmptyValue)&&void 0!==n?n:"EMPTY"}return e.prototype.isNewCampaign=function(e,t,r){void 0===r&&(r=!1),e.referrer;var n=e.referring_domain,i=a(e,["referrer","referring_domain"]),o=t||{};o.referrer;var u=o.referring_domain,s=a(o,["referrer","referring_domain"]);if(e.referring_domain&&this.excludeReferrers.includes(e.referring_domain))return!1;var c=JSON.stringify(i)!==JSON.stringify(s),f=r?P(n||"")!==P(u||""):n!==u;return!t||c||f},e.prototype.saveCampaignToStorage=function(e){return u(this,void 0,void 0,(function(){return s(this,(function(t){switch(t.label){case 0:return[4,this.storage.set(this.storageKey,e)];case 1:return t.sent(),[2]}}))}))},e.prototype.getCampaignFromStorage=function(){return u(this,void 0,void 0,(function(){return s(this,(function(e){switch(e.label){case 0:return[4,this.storage.get(this.storageKey)];case 1:return[2,e.sent()]}}))}))},e.prototype.createCampaignEvent=function(e){var t,r,i=this,a=o(o({},_),e),u=Object.entries(a).reduce((function(e,t){var r=function(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)a.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 a}(t,2),n=r[0],o=r[1];return e.setOnce("initial_".concat(n),o||i.initialEmptyValue),o?e.set(n,o):e.unset(n)}),new N),s={event_type:"Page View",event_properties:{page_title:"undefined"!=typeof document&&document.title||"",page_location:"undefined"!=typeof location&&location.href||"",page_path:"undefined"!=typeof location&&location.pathname||""}};return o(o({},(t=u,o(o({},r),{event_type:n.IDENTIFY,user_properties:t.getUserProperties()}))),this.trackPageViews&&s)},e.prototype.send=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return this.disabled?[2]:[4,this.parser.parse()];case 1:return t=n.sent(),[4,this.getCampaignFromStorage()];case 2:if(r=n.sent(),!e){if(!this.trackNewCampaigns||!this.isNewCampaign(t,r))return[2];this.onNewCampaign(t)}return[4,this.track(this.createCampaignEvent(t))];case 3:return n.sent(),[4,this.saveCampaignToStorage(t)];case 4:return n.sent(),[2]}}))}))},e}(),P=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},O=function(){function e(e,t,r){this.campaignTracker=new T(e,o(o({},r),{trackPageViews:!1,track:function(){return Promise.resolve()},onNewCampaign:function(){return function(){}},storage:t}))}return e.prototype.createCampaignEvent=function(e){return this.campaignTracker.createCampaignEvent(e)},e.prototype.onPageChange=function(e){return u(this,void 0,void 0,(function(){var t,r;return s(this,(function(n){switch(n.label){case 0:return t=e,[4,this.getCurrentState()];case 1:return[4,t.apply(void 0,[n.sent()])];case 2:return n.sent(),[4,this.getCurrentState()];case 3:return(r=n.sent()).isNewCampaign&&this.campaignTracker.saveCampaignToStorage(r.currentCampaign),[2]}}))}))},e.prototype.getCurrentState=function(){return u(this,void 0,void 0,(function(){var e,t,r,n;return s(this,(function(i){switch(i.label){case 0:return[4,this.campaignTracker.parser.parse()];case 1:return e=i.sent(),r=(t=this.campaignTracker).isNewCampaign,n=[e],[4,this.campaignTracker.getCampaignFromStorage()];case 2:return[2,{isNewCampaign:r.apply(t,n.concat([i.sent(),!0])),currentCampaign:e}]}}))}))},e}(),k=function(e,t){return void 0===t&&(t={}),{name:"web-attribution",type:i.BEFORE,setup:function(r){return u(void 0,void 0,void 0,(function(){var n,i,a;return s(this,(function(c){return r.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser"),(null===(a=r.attribution)||void 0===a?void 0:a.disabled)||(r.loggerProvider.warn("@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser"),r.attribution={disabled:!0}),n=r.cookieStorage,(i=new O(r.apiKey,n,o({},t))).onPageChange((function(n){var o=n.isNewCampaign,a=n.currentCampaign;return u(void 0,void 0,void 0,(function(){return s(this,(function(n){return o&&(t.resetSessionOnNewCampaign&&(e.setSessionId(Date.now()),r.loggerProvider.log("Created a new session for new campaign")),r.loggerProvider.log("Tracking new campaign event"),e.track(i.createCampaignEvent(a))),[2]}))}))})),[2]}))}))},execute:function(e){return u(void 0,void 0,void 0,(function(){return s(this,(function(t){return[2,e]}))}))}}},R=Object.freeze({__proto__:null});e.Types=R,e.plugin=k,e.webAttributionPlugin=k,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{l(n.next(e))}catch(e){o(e)}}function a(e){try{l(n.throw(e))}catch(e){o(e)}}function l(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}l((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(l){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,l])}}}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,l,s,f=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=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""}},d="dclid",p="fbclid",v="gbraid",y="gclid",b="ko_click_id",h="msclkid",g="ttclid",m="twclid",_="wbraid",E={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,msclkid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},w=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({},E),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=f();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=f();return(e={})[d]=t[d],e[p]=t[p],e[v]=t[v],e[y]=t[y],e[b]=t[b],e[h]=t[h],e[g]=t[g],e[m]=t[m],e[_]=t[_],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"}(l||(l={})),function(e){e.BEFORE="before",e.ENRICHMENT="enrichment",e.DESTINATION="destination"}(s||(s={}));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),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},T=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}(),R=function(e,t,r){return void 0===t&&(t=""),void 0===r&&(r=10),[S,t,e.substring(0,r)].filter(Boolean).join("_")},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){var i;e.referrer;var o=e.referring_domain,u=r(e,["referrer","referring_domain"]),a=t||{};a.referrer;var l=a.referring_domain,s=r(a,["referrer","referring_domain"]);if(e.referring_domain&&(null===(i=n.excludeReferrers)||void 0===i?void 0:i.includes(e.referring_domain)))return!1;var f=JSON.stringify(u)!==JSON.stringify(s),c=N(o||"")!==N(l||"");return!t||f||c},A=function(e,r){var n,i,u=t(t({},E),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 T);return n=a,t(t({},i),{event_type:l.IDENTIFY,user_properties:n.getUserProperties()})},k=function(){for(var e,r,u=this,a=[],l=0;l<arguments.length;l++)a[l]=arguments[l];var f={},c=o(a,2),d=c[0],p=c[1];d&&"init"in d?(r=d,p&&(f=p)):d&&(f=d);var v=null!==(e=f.excludeReferrers)&&void 0!==e?e:[];"undefined"!=typeof location&&v.unshift(location.hostname),f=t(t({disabled:!1,initialEmptyValue:"EMPTY",resetSessionOnNewCampaign:!1},f),{excludeReferrers:v});var y={name:"web-attribution",type:s.BEFORE,setup:function(e,t){var u;return n(this,void 0,void 0,(function(){var n,a,l,s,c,p,v,y;return i(this,(function(i){switch(i.label){case 0:return(r=null!=r?r:t)?f.disabled?(e.loggerProvider.log("@amplitude/plugin-web-attribution-browser is disabled. Attribution is not tracked."),[2]):(e.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser."),t||(null===(u=e.attribution)||void 0===u?void 0:u.disabled)||(e.loggerProvider.warn("@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser. Resolve by disabling web attribution tracking in @amplitude/analytics-browser."),e.attribution={disabled:!0}),a=e.cookieStorage,l=R(e.apiKey),[4,Promise.all([(new w).parse(),a.get(l)])]):(n=d?"Options":"undefined",e.loggerProvider.error("Argument of type '".concat(n,"' is not assignable to parameter of type 'BrowserClient'.")),[2]);case 1:return s=o.apply(void 0,[i.sent(),2]),c=s[0],p=s[1],(null!=(v=this.__pluginEnabledOverride)?v:I(c,p,f))&&(f.resetSessionOnNewCampaign&&(r.setSessionId(Date.now()),e.loggerProvider.log("Created a new session for new campaign.")),e.loggerProvider.log("Tracking attribution."),y=A(c,f),r.track(y),a.set(l,c)),[2]}}))}))},execute:function(e){return n(u,void 0,void 0,(function(){return i(this,(function(t){return[2,e]}))}))},__pluginEnabledOverride:void 0};return y},x=Object.freeze({__proto__:null});e.Types=x,e.plugin=k,e.webAttributionPlugin=k,Object.defineProperty(e,"__esModule",{value:!0})})); |
@@ -0,1 +1,2 @@ | ||
import { BeforePlugin, BrowserClient } from '@amplitude/analytics-types'; | ||
export interface Options { | ||
@@ -7,2 +8,7 @@ disabled?: boolean; | ||
} | ||
export interface CreateWebAttributionPlugin { | ||
(client: BrowserClient, options?: Options): BeforePlugin; | ||
(options?: Options): BeforePlugin; | ||
} | ||
export type CreateWebAttributionPluginParameters = [BrowserClient, Options?] | [Options?]; | ||
//# sourceMappingURL=web-attribution.d.ts.map |
@@ -1,4 +0,3 @@ | ||
import { BeforePlugin, BrowserClient } from '@amplitude/analytics-types'; | ||
import { Options } from './typings/web-attribution'; | ||
export declare const webAttributionPlugin: (client: BrowserClient, options?: Options) => BeforePlugin; | ||
import { CreateWebAttributionPlugin } from './typings/web-attribution'; | ||
export declare const webAttributionPlugin: CreateWebAttributionPlugin; | ||
//# sourceMappingURL=web-attribution.d.ts.map |
{ | ||
"name": "@amplitude/plugin-web-attribution-browser", | ||
"version": "0.5.7", | ||
"version": "0.6.0-beta.0", | ||
"description": "", | ||
@@ -39,8 +39,8 @@ "author": "Amplitude Inc", | ||
"dependencies": { | ||
"@amplitude/analytics-client-common": "^0.5.4", | ||
"@amplitude/analytics-types": "^0.16.0", | ||
"@amplitude/analytics-client-common": "^0.6.0-beta.0", | ||
"@amplitude/analytics-types": "^0.17.0-beta.0", | ||
"tslib": "^2.4.1" | ||
}, | ||
"devDependencies": { | ||
"@amplitude/analytics-browser": "^1.8.0", | ||
"@amplitude/analytics-browser": "^1.9.0-beta.0", | ||
"@rollup/plugin-commonjs": "^23.0.4", | ||
@@ -57,3 +57,3 @@ "@rollup/plugin-node-resolve": "^15.0.1", | ||
], | ||
"gitHead": "e9b73ad53882d499ca14e3d53e8885825554d0d9" | ||
"gitHead": "5590f7d77d93362d2f3db6d47116ca502afd1fc4" | ||
} |
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
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
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
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
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
81480
417
3
+ Added@amplitude/analytics-client-common@0.6.5(transitive)
+ Added@amplitude/analytics-core@0.13.3(transitive)
+ Added@amplitude/analytics-types@0.17.10.19.00.20.0(transitive)
- Removed@amplitude/analytics-client-common@0.5.4(transitive)
- Removed@amplitude/analytics-core@0.11.4(transitive)
- Removed@amplitude/analytics-types@0.16.0(transitive)