@amplitude/plugin-web-attribution-browser 0.5.2 → 0.5.4

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
@@ -5,5 +5,5 @@ var web_attribution_1 = require("./web-attribution");
5
5
  Object.defineProperty(exports, "webAttributionPlugin", { enumerable: true, get: function () { return web_attribution_1.webAttributionPlugin; } });
6
6
  var web_attribution_2 = require("./web-attribution");
7
7
  Object.defineProperty(exports, "plugin", { enumerable: true, get: function () { return web_attribution_2.webAttributionPlugin; } });
8
- exports.Types = (0, tslib_1.__importStar)(require("./typings/web-attribution"));
8
+ exports.Types = tslib_1.__importStar(require("./typings/web-attribution"));
9
9
  //# sourceMappingURL=index.js.map
@@ -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;AACvC,gFAAmD","sourcesContent":["export { webAttributionPlugin } from './web-attribution';\nexport { webAttributionPlugin as plugin } from './web-attribution';\nexport * as Types from './typings/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;AACvC,2EAAmD","sourcesContent":["export { webAttributionPlugin } from './web-attribution';\nexport { webAttributionPlugin as plugin } from './web-attribution';\nexport * as Types from './typings/web-attribution';\n"]}
@@ -9,10 +9,8 @@ export declare class PluginCampaignTracker {
9
9
  event_properties?: {
10
10
  [key: string]: any;
11
11
  } | undefined;
12
- user_properties: import("@amplitude/analytics-types").IdentifyUserProperties | {
12
+ user_properties: {
13
13
  [key: string]: any;
14
- } | {
15
- [x: string]: any;
16
14
  };
17
15
  group_properties?: {
18
16
  [key: string]: any;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-campaign-tracker.d.ts","sourceRoot":"","sources":["../../src/plugin-campaign-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,qBAAa,qBAAqB;IAChC,eAAe,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,kBAAkB;IAUnF,mBAAmB,CAAC,eAAe,EAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIvC,YAAY,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,aAAa,EAAE,OAAO,CAAC;QAAC,eAAe,EAAE,QAAQ,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;YASjG,eAAe;CAY9B"}
1
+ {"version":3,"file":"plugin-campaign-tracker.d.ts","sourceRoot":"","sources":["../../src/plugin-campaign-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,qBAAa,qBAAqB;IAChC,eAAe,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,kBAAkB;IAUnF,mBAAmB,CAAC,eAAe,EAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIvC,YAAY,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,aAAa,EAAE,OAAO,CAAC;QAAC,eAAe,EAAE,QAAQ,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;YASjG,eAAe;CAY9B"}
@@ -4,15 +4,15 @@ var tslib_1 = require("tslib");
4
4
  var analytics_client_common_1 = require("@amplitude/analytics-client-common");
5
5
  var PluginCampaignTracker = /** @class */ (function () {
6
6
  function PluginCampaignTracker(apiKey, storage, options) {
7
- this.campaignTracker = new analytics_client_common_1.CampaignTracker(apiKey, (0, tslib_1.__assign)((0, tslib_1.__assign)({}, options), { trackPageViews: false, track: /* istanbul ignore next */ function () { return Promise.resolve(); }, onNewCampaign: /* istanbul ignore next */ function () { return function () { return undefined; }; }, storage: storage }));
7
+ this.campaignTracker = new analytics_client_common_1.CampaignTracker(apiKey, tslib_1.__assign(tslib_1.__assign({}, options), { trackPageViews: false, track: /* istanbul ignore next */ function () { return Promise.resolve(); }, onNewCampaign: /* istanbul ignore next */ function () { return function () { return undefined; }; }, storage: storage }));
8
8
  }
9
9
  PluginCampaignTracker.prototype.createCampaignEvent = function (currentCampaign) {
10
10
  return this.campaignTracker.createCampaignEvent(currentCampaign);
11
11
  };
12
12
  PluginCampaignTracker.prototype.onPageChange = function (callback) {
13
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
13
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
14
14
  var _a, currentState;
15
- return (0, tslib_1.__generator)(this, function (_b) {
15
+ return tslib_1.__generator(this, function (_b) {
16
16
  switch (_b.label) {
17
17
  case 0:
18
18
  _a = callback;
@@ -32,9 +32,9 @@ var PluginCampaignTracker = /** @class */ (function () {
32
32
  });
33
33
  };
34
34
  PluginCampaignTracker.prototype.getCurrentState = function () {
35
- return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
35
+ return tslib_1.__awaiter(this, void 0, void 0, function () {
36
36
  var currentCampaign, isNewCampaign, _a, _b, _c;
37
- return (0, tslib_1.__generator)(this, function (_d) {
37
+ return tslib_1.__generator(this, function (_d) {
38
38
  switch (_d.label) {
39
39
  case 0: return [4 /*yield*/, this.campaignTracker.parser.parse()];
40
40
  case 1:
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-campaign-tracker.js","sourceRoot":"","sources":["../../src/plugin-campaign-tracker.ts"],"names":[],"mappings":";;;AACA,8EAAqE;AAGrE;IAGE,+BAAY,MAAc,EAAE,OAA0B,EAAE,OAA2B;QACjF,IAAI,CAAC,eAAe,GAAG,IAAI,yCAAe,CAAC,MAAM,kDAC5C,OAAO,KACV,cAAc,EAAE,KAAK,EACrB,KAAK,EAAE,0BAA0B,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,EAAE,EAAjB,CAAiB,EACzD,aAAa,EAAE,0BAA0B,CAAC,cAAM,OAAA,cAAM,OAAA,SAAS,EAAT,CAAS,EAAf,CAAe,EAC/D,OAAO,SAAA,IACP,CAAC;IACL,CAAC;IAED,mDAAmB,GAAnB,UAAoB,eAAyB;QAC3C,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;IACnE,CAAC;IAEK,4CAAY,GAAlB,UAAmB,QAA4F;;;;;;wBACvG,KAAA,QAAQ,CAAA;wBAAC,qBAAM,IAAI,CAAC,eAAe,EAAE,EAAA;4BAA3C,qBAAM,kBAAS,SAA4B,EAAC,EAAA;;wBAA5C,SAA4C,CAAC;wBAExB,qBAAM,IAAI,CAAC,eAAe,EAAE,EAAA;;wBAA3C,YAAY,GAAG,SAA4B;wBACjD,IAAI,YAAY,CAAC,aAAa,EAAE;4BAC9B,KAAK,IAAI,CAAC,eAAe,CAAC,qBAAqB,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;yBAC/E;;;;;KACF;IAEa,+CAAe,GAA7B;;;;;4BAC0B,qBAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,EAAA;;wBAA3D,eAAe,GAAG,SAAyC;wBAC3C,KAAA,CAAA,KAAA,IAAI,CAAC,eAAe,CAAA,CAAC,aAAa,CAAA;8BACtD,eAAe;wBACf,qBAAM,IAAI,CAAC,eAAe,CAAC,sBAAsB,EAAE,EAAA;;wBAF/C,aAAa,GAAG,wBAEpB,SAAmD,EACnD,IAAI,GACL;wBACD,sBAAO;gCACL,aAAa,eAAA;gCACb,eAAe,iBAAA;6BAChB,EAAC;;;;KACH;IACH,4BAAC;AAAD,CAAC,AAtCD,IAsCC;AAtCY,sDAAqB","sourcesContent":["import { AttributionOptions, Campaign } from '@amplitude/analytics-types';\nimport { CampaignTracker } from '@amplitude/analytics-client-common';\nimport { Storage } from '@amplitude/analytics-types';\n\nexport class PluginCampaignTracker {\n campaignTracker: CampaignTracker;\n\n constructor(apiKey: string, storage: Storage<Campaign>, options: AttributionOptions) {\n this.campaignTracker = new CampaignTracker(apiKey, {\n ...options,\n trackPageViews: false,\n track: /* istanbul ignore next */ () => Promise.resolve(),\n onNewCampaign: /* istanbul ignore next */ () => () => undefined,\n storage,\n });\n }\n\n createCampaignEvent(currentCampaign: Campaign) {\n return this.campaignTracker.createCampaignEvent(currentCampaign);\n }\n\n async onPageChange(callback: (state: { isNewCampaign: boolean; currentCampaign: Campaign }) => Promise<unknown>) {\n await callback(await this.getCurrentState());\n\n const currentState = await this.getCurrentState();\n if (currentState.isNewCampaign) {\n void this.campaignTracker.saveCampaignToStorage(currentState.currentCampaign);\n }\n }\n\n private async getCurrentState() {\n const currentCampaign = await this.campaignTracker.parser.parse();\n const isNewCampaign = this.campaignTracker.isNewCampaign(\n currentCampaign,\n await this.campaignTracker.getCampaignFromStorage(),\n true,\n );\n return {\n isNewCampaign,\n currentCampaign,\n };\n }\n}\n"]}
1
+ {"version":3,"file":"plugin-campaign-tracker.js","sourceRoot":"","sources":["../../src/plugin-campaign-tracker.ts"],"names":[],"mappings":";;;AACA,8EAAqE;AAGrE;IAGE,+BAAY,MAAc,EAAE,OAA0B,EAAE,OAA2B;QACjF,IAAI,CAAC,eAAe,GAAG,IAAI,yCAAe,CAAC,MAAM,wCAC5C,OAAO,KACV,cAAc,EAAE,KAAK,EACrB,KAAK,EAAE,0BAA0B,CAAC,cAAM,OAAA,OAAO,CAAC,OAAO,EAAE,EAAjB,CAAiB,EACzD,aAAa,EAAE,0BAA0B,CAAC,cAAM,OAAA,cAAM,OAAA,SAAS,EAAT,CAAS,EAAf,CAAe,EAC/D,OAAO,SAAA,IACP,CAAC;IACL,CAAC;IAED,mDAAmB,GAAnB,UAAoB,eAAyB;QAC3C,OAAO,IAAI,CAAC,eAAe,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC;IACnE,CAAC;IAEK,4CAAY,GAAlB,UAAmB,QAA4F;;;;;;wBACvG,KAAA,QAAQ,CAAA;wBAAC,qBAAM,IAAI,CAAC,eAAe,EAAE,EAAA;4BAA3C,qBAAM,kBAAS,SAA4B,EAAC,EAAA;;wBAA5C,SAA4C,CAAC;wBAExB,qBAAM,IAAI,CAAC,eAAe,EAAE,EAAA;;wBAA3C,YAAY,GAAG,SAA4B;wBACjD,IAAI,YAAY,CAAC,aAAa,EAAE;4BAC9B,KAAK,IAAI,CAAC,eAAe,CAAC,qBAAqB,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC;yBAC/E;;;;;KACF;IAEa,+CAAe,GAA7B;;;;;4BAC0B,qBAAM,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,KAAK,EAAE,EAAA;;wBAA3D,eAAe,GAAG,SAAyC;wBAC3C,KAAA,CAAA,KAAA,IAAI,CAAC,eAAe,CAAA,CAAC,aAAa,CAAA;8BACtD,eAAe;wBACf,qBAAM,IAAI,CAAC,eAAe,CAAC,sBAAsB,EAAE,EAAA;;wBAF/C,aAAa,GAAG,wBAEpB,SAAmD,EACnD,IAAI,GACL;wBACD,sBAAO;gCACL,aAAa,eAAA;gCACb,eAAe,iBAAA;6BAChB,EAAC;;;;KACH;IACH,4BAAC;AAAD,CAAC,AAtCD,IAsCC;AAtCY,sDAAqB","sourcesContent":["import { AttributionOptions, Campaign } from '@amplitude/analytics-types';\nimport { CampaignTracker } from '@amplitude/analytics-client-common';\nimport { Storage } from '@amplitude/analytics-types';\n\nexport class PluginCampaignTracker {\n campaignTracker: CampaignTracker;\n\n constructor(apiKey: string, storage: Storage<Campaign>, options: AttributionOptions) {\n this.campaignTracker = new CampaignTracker(apiKey, {\n ...options,\n trackPageViews: false,\n track: /* istanbul ignore next */ () => Promise.resolve(),\n onNewCampaign: /* istanbul ignore next */ () => () => undefined,\n storage,\n });\n }\n\n createCampaignEvent(currentCampaign: Campaign) {\n return this.campaignTracker.createCampaignEvent(currentCampaign);\n }\n\n async onPageChange(callback: (state: { isNewCampaign: boolean; currentCampaign: Campaign }) => Promise<unknown>) {\n await callback(await this.getCurrentState());\n\n const currentState = await this.getCurrentState();\n if (currentState.isNewCampaign) {\n void this.campaignTracker.saveCampaignToStorage(currentState.currentCampaign);\n }\n }\n\n private async getCurrentState() {\n const currentCampaign = await this.campaignTracker.parser.parse();\n const isNewCampaign = this.campaignTracker.isNewCampaign(\n currentCampaign,\n await this.campaignTracker.getCampaignFromStorage(),\n true,\n );\n return {\n isNewCampaign,\n currentCampaign,\n };\n }\n}\n"]}
@@ -9,11 +9,11 @@ var webAttributionPlugin = function (client, options) {
9
9
  return ({
10
10
  name: 'web-attribution',
11
11
  type: analytics_types_1.PluginType.BEFORE,
12
- setup: function (config) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
12
+ setup: function (config) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
13
13
  var storage, campaignTracker;
14
14
  var _this = this;
15
15
  var _a;
16
- return (0, tslib_1.__generator)(this, function (_b) {
16
+ return tslib_1.__generator(this, function (_b) {
17
17
  config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser');
18
18
  // Disable "runAttributionStrategy" function
19
19
  if (!((_a = config.attribution) === null || _a === void 0 ? void 0 : _a.disabled)) {
@@ -23,12 +23,12 @@ var webAttributionPlugin = function (client, options) {
23
23
  };
24
24
  }
25
25
  storage = config.cookieStorage;
26
- campaignTracker = new plugin_campaign_tracker_1.PluginCampaignTracker(config.apiKey, storage, (0, tslib_1.__assign)({}, options));
26
+ campaignTracker = new plugin_campaign_tracker_1.PluginCampaignTracker(config.apiKey, storage, tslib_1.__assign({}, options));
27
27
  // Web Attribution tracking
28
28
  void campaignTracker.onPageChange(function (_a) {
29
29
  var isNewCampaign = _a.isNewCampaign, currentCampaign = _a.currentCampaign;
30
- return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
31
- return (0, tslib_1.__generator)(this, function (_b) {
30
+ return tslib_1.__awaiter(_this, void 0, void 0, function () {
31
+ return tslib_1.__generator(this, function (_b) {
32
32
  if (isNewCampaign) {
33
33
  if (options.resetSessionOnNewCampaign) {
34
34
  client.setSessionId(Date.now());
@@ -44,7 +44,7 @@ var webAttributionPlugin = function (client, options) {
44
44
  return [2 /*return*/];
45
45
  });
46
46
  }); },
47
- execute: function (event) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { return (0, tslib_1.__generator)(this, function (_a) {
47
+ execute: function (event) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
48
48
  return [2 /*return*/, event];
49
49
  }); }); },
50
50
  });
@@ -1 +1 @@
1
- {"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"AAAA,iBAmDA;;;;AAnDA,8DAQoC;AACpC,qEAAkE;AAG3D,IAAM,oBAAoB,GAAG,UAAC,MAAqB,EAAE,OAAqB;IAArB,wBAAA,EAAA,YAAqB;IAAmB,OAAA,CAAC;QACnG,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,4BAAU,CAAC,MAAM;QAEvB,KAAK,EAAE,UAAO,MAAqB;;;;;gBACjC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;gBAElF,4CAA4C;gBAC5C,IAAI,CAAC,CAAA,MAAA,MAAM,CAAC,WAAW,0CAAE,QAAQ,CAAA,EAAE;oBACjC,MAAM,CAAC,cAAc,CAAC,IAAI,CACxB,sHAAsH,CACvH,CAAC;oBACF,MAAM,CAAC,WAAW,GAAG;wBACnB,QAAQ,EAAE,IAAI;qBACf,CAAC;iBACH;gBAGK,OAAO,GAAG,MAAM,CAAC,aAA6C,CAAC;gBAE/D,eAAe,GAAG,IAAI,+CAAqB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,4BACnE,OAAO,EACV,CAAC;gBAEH,2BAA2B;gBAC3B,KAAK,eAAe,CAAC,YAAY,CAAC,UAAO,EAAkC;wBAAhC,aAAa,mBAAA,EAAE,eAAe,qBAAA;;;4BACvE,IAAI,aAAa,EAAE;gCACjB,IAAI,OAAO,CAAC,yBAAyB,EAAE;oCACrC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;oCAChC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;iCACrE;gCACD,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;gCACzD,KAAK,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC,CAAC;6BACzE;;;;iBACF,CAAC,CAAC;;;aACJ;QAED,OAAO,EAAE,UAAO,KAAY;YAAK,sBAAA,KAAK,EAAA;iBAAA;KACvC,CAAC;AAtCkG,CAsClG,CAAC;AAtCU,QAAA,oBAAoB,wBAsC9B","sourcesContent":["import {\n BeforePlugin,\n BrowserClient,\n BrowserConfig,\n Campaign,\n Event,\n PluginType,\n Storage,\n} from '@amplitude/analytics-types';\nimport { PluginCampaignTracker } from './plugin-campaign-tracker';\nimport { Options } from './typings/web-attribution';\n\nexport const webAttributionPlugin = (client: BrowserClient, options: Options = {}): BeforePlugin => ({\n name: 'web-attribution',\n type: PluginType.BEFORE,\n\n setup: async (config: BrowserConfig) => {\n config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser');\n\n // Disable \"runAttributionStrategy\" function\n if (!config.attribution?.disabled) {\n config.loggerProvider.warn(\n '@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser',\n );\n config.attribution = {\n disabled: true,\n };\n }\n\n // Share cookie storage with user session storage\n const storage = config.cookieStorage as unknown as Storage<Campaign>;\n\n const campaignTracker = new PluginCampaignTracker(config.apiKey, storage, {\n ...options,\n });\n\n // Web Attribution tracking\n void campaignTracker.onPageChange(async ({ isNewCampaign, currentCampaign }) => {\n if (isNewCampaign) {\n if (options.resetSessionOnNewCampaign) {\n client.setSessionId(Date.now());\n config.loggerProvider.log('Created a new session for new campaign');\n }\n config.loggerProvider.log('Tracking new campaign event');\n void client.track(campaignTracker.createCampaignEvent(currentCampaign));\n }\n });\n },\n\n execute: async (event: Event) => event,\n});\n"]}
1
+ {"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"AAAA,iBAmDA;;;;AAnDA,8DAQoC;AACpC,qEAAkE;AAG3D,IAAM,oBAAoB,GAAG,UAAC,MAAqB,EAAE,OAAqB;IAArB,wBAAA,EAAA,YAAqB;IAAmB,OAAA,CAAC;QACnG,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,4BAAU,CAAC,MAAM;QAEvB,KAAK,EAAE,UAAO,MAAqB;;;;;gBACjC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,sDAAsD,CAAC,CAAC;gBAElF,4CAA4C;gBAC5C,IAAI,CAAC,CAAA,MAAA,MAAM,CAAC,WAAW,0CAAE,QAAQ,CAAA,EAAE;oBACjC,MAAM,CAAC,cAAc,CAAC,IAAI,CACxB,sHAAsH,CACvH,CAAC;oBACF,MAAM,CAAC,WAAW,GAAG;wBACnB,QAAQ,EAAE,IAAI;qBACf,CAAC;iBACH;gBAGK,OAAO,GAAG,MAAM,CAAC,aAA6C,CAAC;gBAE/D,eAAe,GAAG,IAAI,+CAAqB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,uBACnE,OAAO,EACV,CAAC;gBAEH,2BAA2B;gBAC3B,KAAK,eAAe,CAAC,YAAY,CAAC,UAAO,EAAkC;wBAAhC,aAAa,mBAAA,EAAE,eAAe,qBAAA;;;4BACvE,IAAI,aAAa,EAAE;gCACjB,IAAI,OAAO,CAAC,yBAAyB,EAAE;oCACrC,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;oCAChC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,wCAAwC,CAAC,CAAC;iCACrE;gCACD,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,6BAA6B,CAAC,CAAC;gCACzD,KAAK,MAAM,CAAC,KAAK,CAAC,eAAe,CAAC,mBAAmB,CAAC,eAAe,CAAC,CAAC,CAAC;6BACzE;;;;iBACF,CAAC,CAAC;;;aACJ;QAED,OAAO,EAAE,UAAO,KAAY;YAAK,sBAAA,KAAK,EAAA;iBAAA;KACvC,CAAC;AAtCkG,CAsClG,CAAC;AAtCU,QAAA,oBAAoB,wBAsC9B","sourcesContent":["import {\n BeforePlugin,\n BrowserClient,\n BrowserConfig,\n Campaign,\n Event,\n PluginType,\n Storage,\n} from '@amplitude/analytics-types';\nimport { PluginCampaignTracker } from './plugin-campaign-tracker';\nimport { Options } from './typings/web-attribution';\n\nexport const webAttributionPlugin = (client: BrowserClient, options: Options = {}): BeforePlugin => ({\n name: 'web-attribution',\n type: PluginType.BEFORE,\n\n setup: async (config: BrowserConfig) => {\n config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser');\n\n // Disable \"runAttributionStrategy\" function\n if (!config.attribution?.disabled) {\n config.loggerProvider.warn(\n '@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser',\n );\n config.attribution = {\n disabled: true,\n };\n }\n\n // Share cookie storage with user session storage\n const storage = config.cookieStorage as unknown as Storage<Campaign>;\n\n const campaignTracker = new PluginCampaignTracker(config.apiKey, storage, {\n ...options,\n });\n\n // Web Attribution tracking\n void campaignTracker.onPageChange(async ({ isNewCampaign, currentCampaign }) => {\n if (isNewCampaign) {\n if (options.resetSessionOnNewCampaign) {\n client.setSessionId(Date.now());\n config.loggerProvider.log('Created a new session for new campaign');\n }\n config.loggerProvider.log('Tracking new campaign event');\n void client.track(campaignTracker.createCampaignEvent(currentCampaign));\n }\n });\n },\n\n execute: async (event: Event) => event,\n});\n"]}
@@ -9,10 +9,8 @@ export declare class PluginCampaignTracker {
9
9
  event_properties?: {
10
10
  [key: string]: any;
11
11
  } | undefined;
12
- user_properties: import("@amplitude/analytics-types").IdentifyUserProperties | {
12
+ user_properties: {
13
13
  [key: string]: any;
14
- } | {
15
- [x: string]: any;
16
14
  };
17
15
  group_properties?: {
18
16
  [key: string]: any;
@@ -1 +1 @@
1
- {"version":3,"file":"plugin-campaign-tracker.d.ts","sourceRoot":"","sources":["../../src/plugin-campaign-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,qBAAa,qBAAqB;IAChC,eAAe,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,kBAAkB;IAUnF,mBAAmB,CAAC,eAAe,EAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIvC,YAAY,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,aAAa,EAAE,OAAO,CAAC;QAAC,eAAe,EAAE,QAAQ,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;YASjG,eAAe;CAY9B"}
1
+ {"version":3,"file":"plugin-campaign-tracker.d.ts","sourceRoot":"","sources":["../../src/plugin-campaign-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,qBAAa,qBAAqB;IAChC,eAAe,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,kBAAkB;IAUnF,mBAAmB,CAAC,eAAe,EAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIvC,YAAY,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,aAAa,EAAE,OAAO,CAAC;QAAC,eAAe,EAAE,QAAQ,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;YASjG,eAAe;CAY9B"}
@@ -1 +1 @@
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(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}!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={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},l=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({},p),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={}).dclid=t.dclid,e.fbclid=t.fbclid,e.gbraid=t.gbraid,e.gclid=t.gclid,e.ko_click_id=t.ko_click_id,e.msclkid=t.msclkid,e.ttclid=t.ttclid,e.twclid=t.twclid,e.wbraid=t.wbraid,e},e}(),d="AMP",g=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!h(t,r))return!1}return!0},h=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&&g(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 g(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},v=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||h(r,n)))},e}(),m=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),[d,t,e.substring(0,r)].filter(Boolean).join("_")}(e,"MKTG"),this.parser=new l,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?y(n||"")!==y(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({},p),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 v),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}(),y=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},b=function(){function e(e,t,r){this.campaignTracker=new m(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}(),_=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 b(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]}))}))}}},E=Object.freeze({__proto__:null});return e.Types=E,e.plugin=_,e.webAttributionPlugin=_,Object.defineProperty(e,"__esModule",{value:!0}),e}({});
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}({});
Binary file
@@ -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,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(o){return function(u){return function(o){if(r)throw new TypeError("Generator is already executing.");for(;a;)try{if(r=1,n&&(i=2&o[0]?n.return:o[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,o[1])).done)return i;switch(n=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return a.label++,{value:o[1],done:!1};case 5:a.label++,n=o[1],o=[0];continue;case 7:o=a.ops.pop(),a.trys.pop();continue;default:if(!(i=a.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){a=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){a.label=o[1];break}if(6===o[0]&&a.label<i[1]){a.label=i[1],i=o;break}if(i&&a.label<i[2]){a.label=i[2],a.ops.push(o);break}i[2]&&a.ops.pop(),a.trys.pop();continue}o=t.call(e,a)}catch(e){o=[6,e],n=0}finally{r=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,u])}}}!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={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},l=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({},p),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={}).dclid=t.dclid,e.fbclid=t.fbclid,e.gbraid=t.gbraid,e.gclid=t.gclid,e.ko_click_id=t.ko_click_id,e.msclkid=t.msclkid,e.ttclid=t.ttclid,e.twclid=t.twclid,e.wbraid=t.wbraid,e},e}(),d="AMP",g=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!h(t,r))return!1}return!0},h=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&&g(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 g(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},v=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||h(r,n)))},e}(),m=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),[d,t,e.substring(0,r)].filter(Boolean).join("_")}(e,"MKTG"),this.parser=new l,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?y(n||"")!==y(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({},p),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 v),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}(),y=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},b=function(){function e(e,t,r){this.campaignTracker=new m(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}(),_=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 b(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]}))}))}}},E=Object.freeze({__proto__:null});e.Types=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,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})}));
Binary file
@@ -0,0 +1,4 @@
1
+ export { webAttributionPlugin } from './web-attribution';
2
+ export { webAttributionPlugin as plugin } from './web-attribution';
3
+ export * as Types from './typings/web-attribution';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AACzD,OAAO,EAAE,oBAAoB,IAAI,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACnE,OAAO,KAAK,KAAK,MAAM,2BAA2B,CAAC"}
@@ -0,0 +1,67 @@
1
+ import { AttributionOptions, Campaign } from '@amplitude/analytics-types';
2
+ import { CampaignTracker } from '@amplitude/analytics-client-common';
3
+ import { Storage } from '@amplitude/analytics-types';
4
+ export declare class PluginCampaignTracker {
5
+ campaignTracker: CampaignTracker;
6
+ constructor(apiKey: string, storage: Storage<Campaign>, options: AttributionOptions);
7
+ createCampaignEvent(currentCampaign: Campaign): {
8
+ event_type: string;
9
+ event_properties?: {
10
+ [key: string]: any;
11
+ } | undefined;
12
+ user_properties: {
13
+ [key: string]: any;
14
+ };
15
+ group_properties?: {
16
+ [key: string]: any;
17
+ } | undefined;
18
+ groups?: {
19
+ [key: string]: any;
20
+ } | undefined;
21
+ user_id?: string | undefined;
22
+ device_id?: string | undefined;
23
+ time?: number | undefined;
24
+ location_lat?: number | undefined;
25
+ location_lng?: number | undefined;
26
+ app_version?: string | undefined;
27
+ version_name?: string | undefined;
28
+ library?: string | undefined;
29
+ platform?: string | undefined;
30
+ os_name?: string | undefined;
31
+ os_version?: string | undefined;
32
+ device_brand?: string | undefined;
33
+ device_manufacturer?: string | undefined;
34
+ device_model?: string | undefined;
35
+ carrier?: string | undefined;
36
+ country?: string | undefined;
37
+ region?: string | undefined;
38
+ city?: string | undefined;
39
+ dma?: string | undefined;
40
+ idfa?: string | undefined;
41
+ idfv?: string | undefined;
42
+ adid?: string | undefined;
43
+ android_id?: string | undefined;
44
+ language?: string | undefined;
45
+ ip?: string | undefined;
46
+ price?: number | undefined;
47
+ quantity?: number | undefined;
48
+ revenue?: number | undefined;
49
+ productId?: string | undefined;
50
+ revenueType?: string | undefined;
51
+ event_id?: number | undefined;
52
+ session_id?: number | undefined;
53
+ insert_id?: string | undefined;
54
+ plan?: import("@amplitude/analytics-types").Plan | undefined;
55
+ ingestion_metadata?: import("@amplitude/analytics-types/lib/esm/ingestion-metadata").IngestionMetadataEventProperty | undefined;
56
+ partner_id?: string | undefined;
57
+ extra?: {
58
+ [key: string]: any;
59
+ } | undefined;
60
+ };
61
+ onPageChange(callback: (state: {
62
+ isNewCampaign: boolean;
63
+ currentCampaign: Campaign;
64
+ }) => Promise<unknown>): Promise<void>;
65
+ private getCurrentState;
66
+ }
67
+ //# sourceMappingURL=plugin-campaign-tracker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin-campaign-tracker.d.ts","sourceRoot":"","sources":["../../src/plugin-campaign-tracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AAC1E,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,OAAO,EAAE,MAAM,4BAA4B,CAAC;AAErD,qBAAa,qBAAqB;IAChC,eAAe,EAAE,eAAe,CAAC;gBAErB,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,EAAE,OAAO,EAAE,kBAAkB;IAUnF,mBAAmB,CAAC,eAAe,EAAE,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAIvC,YAAY,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE;QAAE,aAAa,EAAE,OAAO,CAAC;QAAC,eAAe,EAAE,QAAQ,CAAA;KAAE,KAAK,OAAO,CAAC,OAAO,CAAC;YASjG,eAAe;CAY9B"}
@@ -0,0 +1,7 @@
1
+ export interface Options {
2
+ disabled?: boolean;
3
+ excludeReferrers?: string[];
4
+ initialEmptyValue?: string;
5
+ resetSessionOnNewCampaign?: boolean;
6
+ }
7
+ //# sourceMappingURL=web-attribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../../src/typings/web-attribution.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,yBAAyB,CAAC,EAAE,OAAO,CAAC;CACrC"}
@@ -0,0 +1,4 @@
1
+ import { BeforePlugin, BrowserClient } from '@amplitude/analytics-types';
2
+ import { Options } from './typings/web-attribution';
3
+ export declare const webAttributionPlugin: (client: BrowserClient, options?: Options) => BeforePlugin;
4
+ //# sourceMappingURL=web-attribution.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,YAAY,EACZ,aAAa,EAMd,MAAM,4BAA4B,CAAC;AAEpC,OAAO,EAAE,OAAO,EAAE,MAAM,2BAA2B,CAAC;AAEpD,eAAO,MAAM,oBAAoB,WAAY,aAAa,YAAW,OAAO,KAAQ,YAsClF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amplitude/plugin-web-attribution-browser",
3
- "version": "0.5.2",
3
+ "version": "0.5.4",
4
4
  "description": "",
5
5
  "author": "Amplitude Inc",
6
6
  "homepage": "https://github.com/amplitude/Amplitude-TypeScript",
@@ -36,22 +36,22 @@
36
36
  "url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
37
37
  },
38
38
  "dependencies": {
39
- "@amplitude/analytics-client-common": "^0.5.0",
39
+ "@amplitude/analytics-client-common": "^0.5.2",
40
40
  "@amplitude/analytics-types": "^0.14.0",
41
- "tslib": "^2.3.1"
41
+ "tslib": "^2.4.1"
42
42
  },
43
43
  "devDependencies": {
44
- "@amplitude/analytics-browser": "^1.6.6",
45
- "@rollup/plugin-commonjs": "^21.0.2",
46
- "@rollup/plugin-node-resolve": "^13.1.3",
47
- "@rollup/plugin-typescript": "^8.3.1",
48
- "rollup": "^2.69.0",
44
+ "@amplitude/analytics-browser": "^1.6.8",
45
+ "@rollup/plugin-commonjs": "^23.0.4",
46
+ "@rollup/plugin-node-resolve": "^15.0.1",
47
+ "@rollup/plugin-typescript": "^10.0.1",
48
+ "rollup": "^2.79.1",
49
49
  "rollup-plugin-execute": "^1.1.1",
50
- "rollup-plugin-gzip": "^3.0.0",
50
+ "rollup-plugin-gzip": "^3.1.0",
51
51
  "rollup-plugin-terser": "^7.0.2"
52
52
  },
53
53
  "files": [
54
54
  "lib"
55
55
  ],
56
- "gitHead": "7ea7523f845b1a0dbc5b8e863bc0d2658f8bf38d"
56
+ "gitHead": "cd3e4d96fe15cecc2ea3442ef52be74c642f7222"
57
57
  }