@amplitude/plugin-web-attribution-browser 2.0.17 → 2.0.18
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/web-attribution.d.ts.map +1 -1
- package/lib/cjs/web-attribution.js +15 -70
- package/lib/cjs/web-attribution.js.map +1 -1
- package/lib/esm/web-attribution.d.ts.map +1 -1
- package/lib/esm/web-attribution.js +16 -71
- package/lib/esm/web-attribution.js.map +1 -1
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/web-attribution.d.ts.map +1 -1
- package/package.json +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAW,MAAM,2BAA2B,CAAC;AAGhF,eAAO,MAAM,oBAAoB,EAAE,0BAyClC,CAAC"}
|
|
@@ -3,19 +3,19 @@ exports.webAttributionPlugin = void 0;
|
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var analytics_client_common_1 = require("@amplitude/analytics-client-common");
|
|
5
5
|
var helpers_1 = require("./helpers");
|
|
6
|
+
var analytics_client_common_2 = require("@amplitude/analytics-client-common");
|
|
6
7
|
var webAttributionPlugin = function (options) {
|
|
7
8
|
var _this = this;
|
|
8
9
|
if (options === void 0) { options = {}; }
|
|
9
|
-
var campaignPerSession = {};
|
|
10
10
|
var plugin = {
|
|
11
11
|
name: '@amplitude/plugin-web-attribution-browser',
|
|
12
12
|
type: 'before',
|
|
13
13
|
setup: function (config, amplitude) {
|
|
14
|
-
var _a
|
|
14
|
+
var _a;
|
|
15
15
|
return tslib_1.__awaiter(this, void 0, void 0, function () {
|
|
16
|
-
var pluginConfig, storage, storageKey,
|
|
17
|
-
return tslib_1.__generator(this, function (
|
|
18
|
-
switch (
|
|
16
|
+
var pluginConfig, storage, storageKey, _b, currentCampaign, previousCampaign, isEventInNewSession, campaignEvent;
|
|
17
|
+
return tslib_1.__generator(this, function (_c) {
|
|
18
|
+
switch (_c.label) {
|
|
19
19
|
case 0:
|
|
20
20
|
pluginConfig = tslib_1.__assign({ initialEmptyValue: 'EMPTY', resetSessionOnNewCampaign: false, excludeReferrers: (0, helpers_1.getDefaultExcludedReferrers)((_a = config.cookieOptions) === null || _a === void 0 ? void 0 : _a.domain) }, options);
|
|
21
21
|
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.');
|
|
@@ -26,25 +26,15 @@ var webAttributionPlugin = function (options) {
|
|
|
26
26
|
storage.get(storageKey),
|
|
27
27
|
])];
|
|
28
28
|
case 1:
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// If yes, set a new session ID
|
|
36
|
-
if (isMostRecentSessionExpired || pluginConfig.resetSessionOnNewCampaign) {
|
|
37
|
-
sessionId = Date.now();
|
|
38
|
-
amplitude.setSessionId(sessionId);
|
|
39
|
-
if (pluginConfig.resetSessionOnNewCampaign) {
|
|
40
|
-
config.loggerProvider.log('Created a new session for new campaign.');
|
|
41
|
-
}
|
|
29
|
+
_b = tslib_1.__read.apply(void 0, [_c.sent(), 2]), currentCampaign = _b[0], previousCampaign = _b[1];
|
|
30
|
+
isEventInNewSession = (0, analytics_client_common_2.isNewSession)(config.sessionTimeout, config.lastEventTime);
|
|
31
|
+
if ((0, helpers_1.isNewCampaign)(currentCampaign, previousCampaign, pluginConfig, isEventInNewSession)) {
|
|
32
|
+
if (pluginConfig.resetSessionOnNewCampaign) {
|
|
33
|
+
amplitude.setSessionId(Date.now());
|
|
34
|
+
config.loggerProvider.log('Created a new session for new campaign.');
|
|
42
35
|
}
|
|
36
|
+
config.loggerProvider.log('Tracking attribution.');
|
|
43
37
|
campaignEvent = (0, helpers_1.createCampaignEvent)(currentCampaign, pluginConfig);
|
|
44
|
-
campaignEvent.session_id = sessionId;
|
|
45
|
-
// Cache campaign event with its associated session ID as key
|
|
46
|
-
campaignPerSession[sessionId] = campaignEvent;
|
|
47
|
-
// Additionally, track the same event
|
|
48
38
|
amplitude.track(campaignEvent);
|
|
49
39
|
void storage.set(storageKey, currentCampaign);
|
|
50
40
|
}
|
|
@@ -53,56 +43,11 @@ var webAttributionPlugin = function (options) {
|
|
|
53
43
|
});
|
|
54
44
|
});
|
|
55
45
|
},
|
|
56
|
-
execute: function (event) { return tslib_1.__awaiter(_this, void 0, void 0, function () {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
if (event.session_id) {
|
|
60
|
-
campaignEvent = campaignPerSession[event.session_id];
|
|
61
|
-
if (campaignEvent) {
|
|
62
|
-
// If yes, merge first seen event with with campaign event.
|
|
63
|
-
// It is possible that `event` is equal to `campaignEvent`
|
|
64
|
-
// when `campaignEvent` is what is first passed to `execute`.
|
|
65
|
-
event.user_properties = mergeDeep(campaignEvent.user_properties, event.user_properties);
|
|
66
|
-
event.event_properties = tslib_1.__assign(tslib_1.__assign({}, event.event_properties), campaignEvent.event_properties);
|
|
67
|
-
if (Object.keys(event.event_properties).length === 0) {
|
|
68
|
-
delete event.event_properties;
|
|
69
|
-
}
|
|
70
|
-
// Remove cached campaign event
|
|
71
|
-
delete campaignPerSession[event.session_id];
|
|
72
|
-
}
|
|
73
|
-
else if ((0, analytics_client_common_1.isCampaignEvent)(event)) {
|
|
74
|
-
// If no campaign event event cache for session ID exists,
|
|
75
|
-
// then campaign event has been merged with another event
|
|
76
|
-
// and this is a dupe that must be dropped.
|
|
77
|
-
return [2 /*return*/, null];
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return [2 /*return*/, event];
|
|
81
|
-
});
|
|
82
|
-
}); },
|
|
46
|
+
execute: function (event) { return tslib_1.__awaiter(_this, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) {
|
|
47
|
+
return [2 /*return*/, event];
|
|
48
|
+
}); }); },
|
|
83
49
|
};
|
|
84
50
|
return plugin;
|
|
85
51
|
};
|
|
86
52
|
exports.webAttributionPlugin = webAttributionPlugin;
|
|
87
|
-
var isObject = function (item) {
|
|
88
|
-
return Boolean(item) && typeof item === 'object' && !Array.isArray(item);
|
|
89
|
-
};
|
|
90
|
-
var mergeDeep = function (target, source) {
|
|
91
|
-
var _a, _b;
|
|
92
|
-
if (isObject(target) && isObject(source)) {
|
|
93
|
-
for (var key in source) {
|
|
94
|
-
if (isObject(source[key])) {
|
|
95
|
-
if (!target[key]) {
|
|
96
|
-
Object.assign(target, (_a = {}, _a[key] = {}, _a));
|
|
97
|
-
}
|
|
98
|
-
mergeDeep(target[key], source[key]);
|
|
99
|
-
}
|
|
100
|
-
else {
|
|
101
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
102
|
-
Object.assign(target, (_b = {}, _b[key] = source[key], _b));
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return target;
|
|
107
|
-
};
|
|
108
53
|
//# sourceMappingURL=web-attribution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";;;AAAA,
|
|
1
|
+
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";;;AAAA,8EAAoE;AAEpE,qCAA2G;AAE3G,8EAAkE;AAE3D,IAAM,oBAAoB,GAA+B,UAAU,OAAqB;IAA/B,iBAyC/D;IAzCyE,wBAAA,EAAA,YAAqB;IAC7F,IAAM,MAAM,GAAiB;QAC3B,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,QAAQ;QAEd,KAAK,EAAE,UAAgB,MAAqB,EAAE,SAAwB;;;;;;;4BAC9D,YAAY,sBAChB,iBAAiB,EAAE,OAAO,EAC1B,yBAAyB,EAAE,KAAK,EAChC,gBAAgB,EAAE,IAAA,qCAA2B,EAAC,MAAA,MAAM,CAAC,aAAa,0CAAE,MAAM,CAAC,IACxE,OAAO,CACX,CAAC;4BACF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;4BAG7E,OAAO,GAAG,MAAM,CAAC,aAA6C,CAAC;4BAC/D,UAAU,GAAG,IAAA,uBAAa,EAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;4BAEZ,qBAAM,OAAO,CAAC,GAAG,CAAC;oCAC5D,IAAI,wCAAc,EAAE,CAAC,KAAK,EAAE;oCAC5B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;iCACxB,CAAC,EAAA;;4BAHI,KAAA,8BAAsC,SAG1C,KAAA,EAHK,eAAe,QAAA,EAAE,gBAAgB,QAAA;4BAKlC,mBAAmB,GAAG,IAAA,sCAAY,EAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;4BAEtF,IAAI,IAAA,uBAAa,EAAC,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,mBAAmB,CAAC,EAAE;gCACvF,IAAI,YAAY,CAAC,yBAAyB,EAAE;oCAC1C,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;oCACnC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;iCACtE;gCACD,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;gCAC7C,aAAa,GAAG,IAAA,6BAAmB,EAAC,eAAe,EAAE,YAAY,CAAC,CAAC;gCACzE,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;gCAC/B,KAAK,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;6BAC/C;;;;;SACF;QAED,OAAO,EAAE,UAAO,KAAY;YAAK,sBAAA,KAAK,EAAA;iBAAA;KACvC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC;AAzCW,QAAA,oBAAoB,wBAyC/B","sourcesContent":["import { CampaignParser } from '@amplitude/analytics-client-common';\nimport { BeforePlugin, BrowserClient, BrowserConfig, Campaign, Event, Storage } from '@amplitude/analytics-types';\nimport { createCampaignEvent, getDefaultExcludedReferrers, getStorageKey, isNewCampaign } from './helpers';\nimport { CreateWebAttributionPlugin, Options } from './typings/web-attribution';\nimport { isNewSession } from '@amplitude/analytics-client-common';\n\nexport const webAttributionPlugin: CreateWebAttributionPlugin = function (options: Options = {}) {\n const plugin: BeforePlugin = {\n name: '@amplitude/plugin-web-attribution-browser',\n type: 'before',\n\n setup: async function (config: BrowserConfig, amplitude: BrowserClient) {\n const pluginConfig = {\n initialEmptyValue: 'EMPTY',\n resetSessionOnNewCampaign: false,\n excludeReferrers: getDefaultExcludedReferrers(config.cookieOptions?.domain),\n ...options,\n };\n config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.');\n\n // Share cookie storage with user session storage\n const storage = config.cookieStorage as unknown as Storage<Campaign>;\n const storageKey = getStorageKey(config.apiKey, 'MKTG');\n\n const [currentCampaign, previousCampaign] = await Promise.all([\n new CampaignParser().parse(),\n storage.get(storageKey),\n ]);\n\n const isEventInNewSession = isNewSession(config.sessionTimeout, config.lastEventTime);\n\n if (isNewCampaign(currentCampaign, previousCampaign, pluginConfig, isEventInNewSession)) {\n if (pluginConfig.resetSessionOnNewCampaign) {\n amplitude.setSessionId(Date.now());\n config.loggerProvider.log('Created a new session for new campaign.');\n }\n config.loggerProvider.log('Tracking attribution.');\n const campaignEvent = createCampaignEvent(currentCampaign, pluginConfig);\n amplitude.track(campaignEvent);\n void storage.set(storageKey, currentCampaign);\n }\n },\n\n execute: async (event: Event) => event,\n };\n\n return plugin;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAW,MAAM,2BAA2B,CAAC;AAGhF,eAAO,MAAM,oBAAoB,EAAE,0BAyClC,CAAC"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { __assign, __awaiter, __generator, __read } from "tslib";
|
|
2
|
-
import { CampaignParser
|
|
2
|
+
import { CampaignParser } from '@amplitude/analytics-client-common';
|
|
3
3
|
import { createCampaignEvent, getDefaultExcludedReferrers, getStorageKey, isNewCampaign } from './helpers';
|
|
4
|
+
import { isNewSession } from '@amplitude/analytics-client-common';
|
|
4
5
|
export var webAttributionPlugin = function (options) {
|
|
5
6
|
var _this = this;
|
|
6
7
|
if (options === void 0) { options = {}; }
|
|
7
|
-
var campaignPerSession = {};
|
|
8
8
|
var plugin = {
|
|
9
9
|
name: '@amplitude/plugin-web-attribution-browser',
|
|
10
10
|
type: 'before',
|
|
11
11
|
setup: function (config, amplitude) {
|
|
12
|
-
var _a
|
|
12
|
+
var _a;
|
|
13
13
|
return __awaiter(this, void 0, void 0, function () {
|
|
14
|
-
var pluginConfig, storage, storageKey,
|
|
15
|
-
return __generator(this, function (
|
|
16
|
-
switch (
|
|
14
|
+
var pluginConfig, storage, storageKey, _b, currentCampaign, previousCampaign, isEventInNewSession, campaignEvent;
|
|
15
|
+
return __generator(this, function (_c) {
|
|
16
|
+
switch (_c.label) {
|
|
17
17
|
case 0:
|
|
18
18
|
pluginConfig = __assign({ initialEmptyValue: 'EMPTY', resetSessionOnNewCampaign: false, excludeReferrers: getDefaultExcludedReferrers((_a = config.cookieOptions) === null || _a === void 0 ? void 0 : _a.domain) }, options);
|
|
19
19
|
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.');
|
|
@@ -24,25 +24,15 @@ export var webAttributionPlugin = function (options) {
|
|
|
24
24
|
storage.get(storageKey),
|
|
25
25
|
])];
|
|
26
26
|
case 1:
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
// If yes, set a new session ID
|
|
34
|
-
if (isMostRecentSessionExpired || pluginConfig.resetSessionOnNewCampaign) {
|
|
35
|
-
sessionId = Date.now();
|
|
36
|
-
amplitude.setSessionId(sessionId);
|
|
37
|
-
if (pluginConfig.resetSessionOnNewCampaign) {
|
|
38
|
-
config.loggerProvider.log('Created a new session for new campaign.');
|
|
39
|
-
}
|
|
27
|
+
_b = __read.apply(void 0, [_c.sent(), 2]), currentCampaign = _b[0], previousCampaign = _b[1];
|
|
28
|
+
isEventInNewSession = isNewSession(config.sessionTimeout, config.lastEventTime);
|
|
29
|
+
if (isNewCampaign(currentCampaign, previousCampaign, pluginConfig, isEventInNewSession)) {
|
|
30
|
+
if (pluginConfig.resetSessionOnNewCampaign) {
|
|
31
|
+
amplitude.setSessionId(Date.now());
|
|
32
|
+
config.loggerProvider.log('Created a new session for new campaign.');
|
|
40
33
|
}
|
|
34
|
+
config.loggerProvider.log('Tracking attribution.');
|
|
41
35
|
campaignEvent = createCampaignEvent(currentCampaign, pluginConfig);
|
|
42
|
-
campaignEvent.session_id = sessionId;
|
|
43
|
-
// Cache campaign event with its associated session ID as key
|
|
44
|
-
campaignPerSession[sessionId] = campaignEvent;
|
|
45
|
-
// Additionally, track the same event
|
|
46
36
|
amplitude.track(campaignEvent);
|
|
47
37
|
void storage.set(storageKey, currentCampaign);
|
|
48
38
|
}
|
|
@@ -51,55 +41,10 @@ export var webAttributionPlugin = function (options) {
|
|
|
51
41
|
});
|
|
52
42
|
});
|
|
53
43
|
},
|
|
54
|
-
execute: function (event) { return __awaiter(_this, void 0, void 0, function () {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
if (event.session_id) {
|
|
58
|
-
campaignEvent = campaignPerSession[event.session_id];
|
|
59
|
-
if (campaignEvent) {
|
|
60
|
-
// If yes, merge first seen event with with campaign event.
|
|
61
|
-
// It is possible that `event` is equal to `campaignEvent`
|
|
62
|
-
// when `campaignEvent` is what is first passed to `execute`.
|
|
63
|
-
event.user_properties = mergeDeep(campaignEvent.user_properties, event.user_properties);
|
|
64
|
-
event.event_properties = __assign(__assign({}, event.event_properties), campaignEvent.event_properties);
|
|
65
|
-
if (Object.keys(event.event_properties).length === 0) {
|
|
66
|
-
delete event.event_properties;
|
|
67
|
-
}
|
|
68
|
-
// Remove cached campaign event
|
|
69
|
-
delete campaignPerSession[event.session_id];
|
|
70
|
-
}
|
|
71
|
-
else if (isCampaignEvent(event)) {
|
|
72
|
-
// If no campaign event event cache for session ID exists,
|
|
73
|
-
// then campaign event has been merged with another event
|
|
74
|
-
// and this is a dupe that must be dropped.
|
|
75
|
-
return [2 /*return*/, null];
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return [2 /*return*/, event];
|
|
79
|
-
});
|
|
80
|
-
}); },
|
|
44
|
+
execute: function (event) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
45
|
+
return [2 /*return*/, event];
|
|
46
|
+
}); }); },
|
|
81
47
|
};
|
|
82
48
|
return plugin;
|
|
83
49
|
};
|
|
84
|
-
var isObject = function (item) {
|
|
85
|
-
return Boolean(item) && typeof item === 'object' && !Array.isArray(item);
|
|
86
|
-
};
|
|
87
|
-
var mergeDeep = function (target, source) {
|
|
88
|
-
var _a, _b;
|
|
89
|
-
if (isObject(target) && isObject(source)) {
|
|
90
|
-
for (var key in source) {
|
|
91
|
-
if (isObject(source[key])) {
|
|
92
|
-
if (!target[key]) {
|
|
93
|
-
Object.assign(target, (_a = {}, _a[key] = {}, _a));
|
|
94
|
-
}
|
|
95
|
-
mergeDeep(target[key], source[key]);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
|
99
|
-
Object.assign(target, (_b = {}, _b[key] = source[key], _b));
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
return target;
|
|
104
|
-
};
|
|
105
50
|
//# sourceMappingURL=web-attribution.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEpE,OAAO,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,WAAW,CAAC;AAE3G,OAAO,EAAE,YAAY,EAAE,MAAM,oCAAoC,CAAC;AAElE,MAAM,CAAC,IAAM,oBAAoB,GAA+B,UAAU,OAAqB;IAA/B,iBAyC/D;IAzCyE,wBAAA,EAAA,YAAqB;IAC7F,IAAM,MAAM,GAAiB;QAC3B,IAAI,EAAE,2CAA2C;QACjD,IAAI,EAAE,QAAQ;QAEd,KAAK,EAAE,UAAgB,MAAqB,EAAE,SAAwB;;;;;;;4BAC9D,YAAY,cAChB,iBAAiB,EAAE,OAAO,EAC1B,yBAAyB,EAAE,KAAK,EAChC,gBAAgB,EAAE,2BAA2B,CAAC,MAAA,MAAM,CAAC,aAAa,0CAAE,MAAM,CAAC,IACxE,OAAO,CACX,CAAC;4BACF,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uDAAuD,CAAC,CAAC;4BAG7E,OAAO,GAAG,MAAM,CAAC,aAA6C,CAAC;4BAC/D,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;4BAEZ,qBAAM,OAAO,CAAC,GAAG,CAAC;oCAC5D,IAAI,cAAc,EAAE,CAAC,KAAK,EAAE;oCAC5B,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC;iCACxB,CAAC,EAAA;;4BAHI,KAAA,sBAAsC,SAG1C,KAAA,EAHK,eAAe,QAAA,EAAE,gBAAgB,QAAA;4BAKlC,mBAAmB,GAAG,YAAY,CAAC,MAAM,CAAC,cAAc,EAAE,MAAM,CAAC,aAAa,CAAC,CAAC;4BAEtF,IAAI,aAAa,CAAC,eAAe,EAAE,gBAAgB,EAAE,YAAY,EAAE,mBAAmB,CAAC,EAAE;gCACvF,IAAI,YAAY,CAAC,yBAAyB,EAAE;oCAC1C,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;oCACnC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,yCAAyC,CAAC,CAAC;iCACtE;gCACD,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;gCAC7C,aAAa,GAAG,mBAAmB,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;gCACzE,SAAS,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC;gCAC/B,KAAK,OAAO,CAAC,GAAG,CAAC,UAAU,EAAE,eAAe,CAAC,CAAC;6BAC/C;;;;;SACF;QAED,OAAO,EAAE,UAAO,KAAY;YAAK,sBAAA,KAAK,EAAA;iBAAA;KACvC,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["import { CampaignParser } from '@amplitude/analytics-client-common';\nimport { BeforePlugin, BrowserClient, BrowserConfig, Campaign, Event, Storage } from '@amplitude/analytics-types';\nimport { createCampaignEvent, getDefaultExcludedReferrers, getStorageKey, isNewCampaign } from './helpers';\nimport { CreateWebAttributionPlugin, Options } from './typings/web-attribution';\nimport { isNewSession } from '@amplitude/analytics-client-common';\n\nexport const webAttributionPlugin: CreateWebAttributionPlugin = function (options: Options = {}) {\n const plugin: BeforePlugin = {\n name: '@amplitude/plugin-web-attribution-browser',\n type: 'before',\n\n setup: async function (config: BrowserConfig, amplitude: BrowserClient) {\n const pluginConfig = {\n initialEmptyValue: 'EMPTY',\n resetSessionOnNewCampaign: false,\n excludeReferrers: getDefaultExcludedReferrers(config.cookieOptions?.domain),\n ...options,\n };\n config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser.');\n\n // Share cookie storage with user session storage\n const storage = config.cookieStorage as unknown as Storage<Campaign>;\n const storageKey = getStorageKey(config.apiKey, 'MKTG');\n\n const [currentCampaign, previousCampaign] = await Promise.all([\n new CampaignParser().parse(),\n storage.get(storageKey),\n ]);\n\n const isEventInNewSession = isNewSession(config.sessionTimeout, config.lastEventTime);\n\n if (isNewCampaign(currentCampaign, previousCampaign, pluginConfig, isEventInNewSession)) {\n if (pluginConfig.resetSessionOnNewCampaign) {\n amplitude.setSessionId(Date.now());\n config.loggerProvider.log('Created a new session for new campaign.');\n }\n config.loggerProvider.log('Tracking attribution.');\n const campaignEvent = createCampaignEvent(currentCampaign, pluginConfig);\n amplitude.track(campaignEvent);\n void storage.set(storageKey, currentCampaign);\n }\n },\n\n execute: async (event: Event) => event,\n };\n\n return plugin;\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).amplitude={})}(this,(function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},t.apply(this,arguments)};function r(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function n(e,t,r,n){return new(r||(r=Promise))((function(i,o){function u(e){try{a(n.next(e))}catch(e){o(e)}}function s(e){try{a(n.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,s)}a((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:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(s){return function(a){return function(s){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,s[0]&&(u=0)),u;)try{if(r=1,n&&(i=2&s[0]?n.return:s[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,s[1])).done)return i;switch(n=0,i&&(s=[2&s[0],i.value]),s[0]){case 0:case 1:i=s;break;case 4:return u.label++,{value:s[1],done:!1};case 5:u.label++,n=s[1],s=[0];continue;case 7:s=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==s[0]&&2!==s[0])){u=0;continue}if(3===s[0]&&(!i||s[1]>i[0]&&s[1]<i[3])){u.label=s[1];break}if(6===s[0]&&u.label<i[1]){u.label=i[1],i=s;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(s);break}i[2]&&u.ops.pop(),u.trys.pop();continue}s=t.call(e,u)}catch(e){s=[6,e],n=0}finally{r=i=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,a])}}}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}function u(e,t,r){if(r||2===arguments.length)for(var n,i=0,o=t.length;i<o;i++)!n&&i in t||(n||(n=Array.prototype.slice.call(t,0,i)),n[i]=t[i]);return e.concat(n||Array.prototype.slice.call(t))}var s,a,f,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=l(r[0]),i=l(r[1]);return i?(e[n]=i,e):e}),{}):{}},l=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},p="dclid",d="fbclid",v="gbraid",y="gclid",_="ko_click_id",h="li_fat_id",m="msclkid",g="rtd_cid",b="ttclid",E="twclid",S="wbraid",w={utm_campaign:void 0,utm_content:void 0,utm_id:void 0,utm_medium:void 0,utm_source:void 0,utm_term:void 0,referrer:void 0,referring_domain:void 0,dclid:void 0,gbraid:void 0,gclid:void 0,fbclid:void 0,ko_click_id:void 0,li_fat_id:void 0,msclkid:void 0,rtd_cid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},O=function(){function e(){}return e.prototype.parse=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){return[2,t(t(t(t({},w),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=c();return{utm_campaign:e.utm_campaign,utm_content:e.utm_content,utm_id:e.utm_id,utm_medium:e.utm_medium,utm_source:e.utm_source,utm_term:e.utm_term}},e.prototype.getReferrer=function(){var e,t,r={referrer:void 0,referring_domain:void 0};try{r.referrer=document.referrer||void 0,r.referring_domain=null!==(t=null===(e=r.referrer)||void 0===e?void 0:e.split("/")[2])&&void 0!==t?t:void 0}catch(e){}return r},e.prototype.getClickIds=function(){var e,t=c();return(e={})[p]=t[p],e[d]=t[d],e[v]=t[v],e[y]=t[y],e[_]=t[_],e[h]=t[h],e[m]=t[m],e[g]=t[g],e[b]=t[b],e[E]=t[E],e[S]=t[S],e},e}();!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(s||(s={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(a||(a={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(f||(f={}));var T="AMP",P=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!R(t,r))return!1}return!0},R=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 s=u.value;if(Array.isArray(s))return!1;if("object"==typeof s)i=i&&P(s);else if(!["number","string"].includes(typeof s))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return P(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},N=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return t({},this._properties)},e.prototype.set=function(e,t){return this._safeSet(s.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(s.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(s.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(s.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(s.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(s.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(s.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(s.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(s.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[s.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,r){if(this._validate(e,t,r)){var n=this._properties[e];return void 0===n&&(n={},this._properties[e]=n),n[t]=r,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,t,r){return void 0===this._properties[s.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===s.ADD?"number"==typeof r:e===s.UNSET||e===s.REMOVE||R(t,r)))},e}(),I=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},A=function(e,t,n,i){void 0===i&&(i=!0),e.referrer;var o=e.referring_domain,u=r(e,["referrer","referring_domain"]),s=t||{};s.referrer;var a=s.referring_domain,f=r(s,["referrer","referring_domain"]);if(j(n.excludeReferrers,e.referring_domain))return!1;if(!i&&function(e){return Object.values(e).every((function(e){return!e}))}(e)&&t)return!1;var c=JSON.stringify(u)!==JSON.stringify(f),l=I(o||"")!==I(a||"");return!t||c||l},j=function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=""),e.some((function(e){return e instanceof RegExp?e.test(t):e===t}))},k=function(e,r){var n,i,u=t(t({},w),e),s=Object.entries(u).reduce((function(e,t){var n,i=o(t,2),u=i[0],s=i[1];return e.setOnce("initial_".concat(u),null!==(n=null!=s?s:r.initialEmptyValue)&&void 0!==n?n:"EMPTY"),s?e.set(u,s):e.unset(u)}),new N);return n=s,t(t({},i),{event_type:f.IDENTIFY,user_properties:n.getUserProperties()})},x=function(e){var r=this;void 0===e&&(e={});var a={};return{name:"@amplitude/plugin-web-attribution-browser",type:"before",setup:function(r,u){var s,f;return n(this,void 0,void 0,(function(){var n,c,l,p,d,v,y,_,h;return i(this,(function(i){switch(i.label){case 0:return n=t({initialEmptyValue:"EMPTY",resetSessionOnNewCampaign:!1,excludeReferrers:(w=null===(s=r.cookieOptions)||void 0===s?void 0:s.domain,P=w,P?(P.startsWith(".")&&(P=P.substring(1)),[new RegExp("".concat(P.replace(".","\\."),"$"))]):[])},e),r.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser."),c=r.cookieStorage,b=r.apiKey,void 0===(E="MKTG")&&(E=""),void 0===S&&(S=10),l=[T,E,b.substring(0,S)].filter(Boolean).join("_"),[4,Promise.all([(new O).parse(),c.get(l)])];case 1:return p=o.apply(void 0,[i.sent(),2]),d=p[0],v=p[1],m=r.sessionTimeout,void 0===(g=r.lastEventTime)&&(g=Date.now()),y=Date.now()-g>m,A(d,v,n,y)&&(_=null!==(f=r.sessionId)&&void 0!==f?f:-1,(y||n.resetSessionOnNewCampaign)&&(_=Date.now(),u.setSessionId(_),n.resetSessionOnNewCampaign&&r.loggerProvider.log("Created a new session for new campaign.")),(h=k(d,n)).session_id=_,a[_]=h,u.track(h),c.set(l,d)),[2]}var m,g,b,E,S,w,P}))}))},execute:function(e){return n(r,void 0,void 0,(function(){var r;return i(this,(function(n){if(e.session_id)if(r=a[e.session_id])e.user_properties=U(r.user_properties,e.user_properties),e.event_properties=t(t({},e.event_properties),r.event_properties),0===Object.keys(e.event_properties).length&&delete e.event_properties,delete a[e.session_id];else if(function(e){if(e.user_properties){var t=e.user_properties,r=t[s.SET]||{},n=t[s.UNSET]||{},i=u(u([],o(Object.keys(r)),!1),o(Object.keys(n)),!1);return Object.keys(w).every((function(e){return i.includes(e)}))}return!1}(e))return[2,null];return[2,e]}))}))}}},D=function(e){return Boolean(e)&&"object"==typeof e&&!Array.isArray(e)},U=function(e,t){var r,n;if(D(e)&&D(t))for(var i in t)D(t[i])?(e[i]||Object.assign(e,((r={})[i]={},r)),U(e[i],t[i])):Object.assign(e,((n={})[i]=t[i],n));return e};e.plugin=x,e.webAttributionPlugin=x,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).amplitude={})}(this,(function(e){"use strict";var t=function(){return t=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e},t.apply(this,arguments)};function r(e,t){var r={};for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&t.indexOf(n)<0&&(r[n]=e[n]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var i=0;for(n=Object.getOwnPropertySymbols(e);i<n.length;i++)t.indexOf(n[i])<0&&Object.prototype.propertyIsEnumerable.call(e,n[i])&&(r[n[i]]=e[n[i]])}return r}function n(e,t,r,n){return new(r||(r=Promise))((function(i,o){function u(e){try{f(n.next(e))}catch(e){o(e)}}function a(e){try{f(n.throw(e))}catch(e){o(e)}}function f(e){var t;e.done?i(e.value):(t=e.value,t instanceof r?t:new r((function(e){e(t)}))).then(u,a)}f((n=n.apply(e,t||[])).next())}))}function i(e,t){var r,n,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:a(0),throw:a(1),return:a(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function a(a){return function(f){return function(a){if(r)throw new TypeError("Generator is already executing.");for(;o&&(o=0,a[0]&&(u=0)),u;)try{if(r=1,n&&(i=2&a[0]?n.return:a[0]?n.throw||((i=n.return)&&i.call(n),0):n.next)&&!(i=i.call(n,a[1])).done)return i;switch(n=0,i&&(a=[2&a[0],i.value]),a[0]){case 0:case 1:i=a;break;case 4:return u.label++,{value:a[1],done:!1};case 5:u.label++,n=a[1],a=[0];continue;case 7:a=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==a[0]&&2!==a[0])){u=0;continue}if(3===a[0]&&(!i||a[1]>i[0]&&a[1]<i[3])){u.label=a[1];break}if(6===a[0]&&u.label<i[1]){u.label=i[1],i=a;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(a);break}i[2]&&u.ops.pop(),u.trys.pop();continue}a=t.call(e,u)}catch(e){a=[6,e],n=0}finally{r=i=0}if(5&a[0])throw a[1];return{value:a[0]?a[1]:void 0,done:!0}}([a,f])}}}function o(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),u=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)u.push(n.value)}catch(e){i={error:e}}finally{try{n&&!n.done&&(r=o.return)&&r.call(o)}finally{if(i)throw i.error}}return u}var u,a,f,s=function(){var e,t="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof self?self:"undefined"!=typeof global?global:void 0;return(null===(e=null==t?void 0:t.location)||void 0===e?void 0:e.search)?t.location.search.substring(1).split("&").filter(Boolean).reduce((function(e,t){var r=t.split("=",2),n=l(r[0]),i=l(r[1]);return i?(e[n]=i,e):e}),{}):{}},l=function(e){void 0===e&&(e="");try{return decodeURIComponent(e)}catch(e){return""}},c="dclid",d="fbclid",p="gbraid",v="gclid",y="ko_click_id",h="li_fat_id",m="msclkid",_="rtd_cid",g="ttclid",b="twclid",E="wbraid",w={utm_campaign:void 0,utm_content:void 0,utm_id:void 0,utm_medium:void 0,utm_source:void 0,utm_term:void 0,referrer:void 0,referring_domain:void 0,dclid:void 0,gbraid:void 0,gclid:void 0,fbclid:void 0,ko_click_id:void 0,li_fat_id:void 0,msclkid:void 0,rtd_cid:void 0,ttclid:void 0,twclid:void 0,wbraid:void 0},S=function(){function e(){}return e.prototype.parse=function(){return n(this,void 0,void 0,(function(){return i(this,(function(e){return[2,t(t(t(t({},w),this.getUtmParam()),this.getReferrer()),this.getClickIds())]}))}))},e.prototype.getUtmParam=function(){var e=s();return{utm_campaign:e.utm_campaign,utm_content:e.utm_content,utm_id:e.utm_id,utm_medium:e.utm_medium,utm_source:e.utm_source,utm_term:e.utm_term}},e.prototype.getReferrer=function(){var e,t,r={referrer:void 0,referring_domain:void 0};try{r.referrer=document.referrer||void 0,r.referring_domain=null!==(t=null===(e=r.referrer)||void 0===e?void 0:e.split("/")[2])&&void 0!==t?t:void 0}catch(e){}return r},e.prototype.getClickIds=function(){var e,t=s();return(e={})[c]=t[c],e[d]=t[d],e[p]=t[p],e[v]=t[v],e[y]=t[y],e[h]=t[h],e[m]=t[m],e[_]=t[_],e[g]=t[g],e[b]=t[b],e[E]=t[E],e},e}();!function(e){e.SET="$set",e.SET_ONCE="$setOnce",e.ADD="$add",e.APPEND="$append",e.PREPEND="$prepend",e.REMOVE="$remove",e.PREINSERT="$preInsert",e.POSTINSERT="$postInsert",e.UNSET="$unset",e.CLEAR_ALL="$clearAll"}(u||(u={})),function(e){e.REVENUE_PRODUCT_ID="$productId",e.REVENUE_QUANTITY="$quantity",e.REVENUE_PRICE="$price",e.REVENUE_TYPE="$revenueType",e.REVENUE="$revenue"}(a||(a={})),function(e){e.IDENTIFY="$identify",e.GROUP_IDENTIFY="$groupidentify",e.REVENUE="revenue_amount"}(f||(f={}));var O="AMP",P=function(e){if(Object.keys(e).length>1e3)return!1;for(var t in e){var r=e[t];if(!T(t,r))return!1}return!0},T=function(e,t){var r,n;if("string"!=typeof e)return!1;if(Array.isArray(t)){var i=!0;try{for(var o=function(e){var t="function"==typeof Symbol&&Symbol.iterator,r=t&&e[t],n=0;if(r)return r.call(e);if(e&&"number"==typeof e.length)return{next:function(){return e&&n>=e.length&&(e=void 0),{value:e&&e[n++],done:!e}}};throw new TypeError(t?"Object is not iterable.":"Symbol.iterator is not defined.")}(t),u=o.next();!u.done;u=o.next()){var a=u.value;if(Array.isArray(a))return!1;if("object"==typeof a)i=i&&P(a);else if(!["number","string"].includes(typeof a))return!1;if(!i)return!1}}catch(e){r={error:e}}finally{try{u&&!u.done&&(n=o.return)&&n.call(o)}finally{if(r)throw r.error}}}else{if(null==t)return!1;if("object"==typeof t)return P(t);if(!["number","string","boolean"].includes(typeof t))return!1}return!0},R=function(){function e(){this._propertySet=new Set,this._properties={}}return e.prototype.getUserProperties=function(){return t({},this._properties)},e.prototype.set=function(e,t){return this._safeSet(u.SET,e,t),this},e.prototype.setOnce=function(e,t){return this._safeSet(u.SET_ONCE,e,t),this},e.prototype.append=function(e,t){return this._safeSet(u.APPEND,e,t),this},e.prototype.prepend=function(e,t){return this._safeSet(u.PREPEND,e,t),this},e.prototype.postInsert=function(e,t){return this._safeSet(u.POSTINSERT,e,t),this},e.prototype.preInsert=function(e,t){return this._safeSet(u.PREINSERT,e,t),this},e.prototype.remove=function(e,t){return this._safeSet(u.REMOVE,e,t),this},e.prototype.add=function(e,t){return this._safeSet(u.ADD,e,t),this},e.prototype.unset=function(e){return this._safeSet(u.UNSET,e,"-"),this},e.prototype.clearAll=function(){return this._properties={},this._properties[u.CLEAR_ALL]="-",this},e.prototype._safeSet=function(e,t,r){if(this._validate(e,t,r)){var n=this._properties[e];return void 0===n&&(n={},this._properties[e]=n),n[t]=r,this._propertySet.add(t),!0}return!1},e.prototype._validate=function(e,t,r){return void 0===this._properties[u.CLEAR_ALL]&&(!this._propertySet.has(t)&&(e===u.ADD?"number"==typeof r:e===u.UNSET||e===u.REMOVE||T(t,r)))},e}(),N=function(e){var t=e.split(".");return t.length<=2?e:t.slice(t.length-2,t.length).join(".")},I=function(e,t,n,i){void 0===i&&(i=!0),e.referrer;var o=e.referring_domain,u=r(e,["referrer","referring_domain"]),a=t||{};a.referrer;var f=a.referring_domain,s=r(a,["referrer","referring_domain"]);if(A(n.excludeReferrers,e.referring_domain))return!1;if(!i&&function(e){return Object.values(e).every((function(e){return!e}))}(e)&&t)return!1;var l=JSON.stringify(u)!==JSON.stringify(s),c=N(o||"")!==N(f||"");return!t||l||c},A=function(e,t){return void 0===e&&(e=[]),void 0===t&&(t=""),e.some((function(e){return e instanceof RegExp?e.test(t):e===t}))},x=function(e,r){var n,i,u=t(t({},w),e),a=Object.entries(u).reduce((function(e,t){var n,i=o(t,2),u=i[0],a=i[1];return e.setOnce("initial_".concat(u),null!==(n=null!=a?a:r.initialEmptyValue)&&void 0!==n?n:"EMPTY"),a?e.set(u,a):e.unset(u)}),new R);return n=a,t(t({},i),{event_type:f.IDENTIFY,user_properties:n.getUserProperties()})},D=function(e){var r=this;return void 0===e&&(e={}),{name:"@amplitude/plugin-web-attribution-browser",type:"before",setup:function(r,u){var a;return n(this,void 0,void 0,(function(){var n,f,s,l,c,d,p,v;return i(this,(function(i){switch(i.label){case 0:return n=t({initialEmptyValue:"EMPTY",resetSessionOnNewCampaign:!1,excludeReferrers:(b=null===(a=r.cookieOptions)||void 0===a?void 0:a.domain,E=b,E?(E.startsWith(".")&&(E=E.substring(1)),[new RegExp("".concat(E.replace(".","\\."),"$"))]):[])},e),r.loggerProvider.log("Installing @amplitude/plugin-web-attribution-browser."),f=r.cookieStorage,m=r.apiKey,void 0===(_="MKTG")&&(_=""),void 0===g&&(g=10),s=[O,_,m.substring(0,g)].filter(Boolean).join("_"),[4,Promise.all([(new S).parse(),f.get(s)])];case 1:return l=o.apply(void 0,[i.sent(),2]),c=l[0],d=l[1],y=r.sessionTimeout,void 0===(h=r.lastEventTime)&&(h=Date.now()),p=Date.now()-h>y,I(c,d,n,p)&&(n.resetSessionOnNewCampaign&&(u.setSessionId(Date.now()),r.loggerProvider.log("Created a new session for new campaign.")),r.loggerProvider.log("Tracking attribution."),v=x(c,n),u.track(v),f.set(s,c)),[2]}var y,h,m,_,g,b,E}))}))},execute:function(e){return n(r,void 0,void 0,(function(){return i(this,(function(t){return[2,e]}))}))}}};e.plugin=D,e.webAttributionPlugin=D,Object.defineProperty(e,"__esModule",{value:!0})}));
|
|
Binary file
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"web-attribution.d.ts","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,0BAA0B,EAAW,MAAM,2BAA2B,CAAC;AAGhF,eAAO,MAAM,oBAAoB,EAAE,0BAyClC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/plugin-web-attribution-browser",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.18",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Amplitude Inc",
|
|
6
6
|
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
@@ -36,13 +36,13 @@
|
|
|
36
36
|
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
-
"@amplitude/analytics-client-common": "^2.0.
|
|
40
|
-
"@amplitude/analytics-core": "^2.1.
|
|
39
|
+
"@amplitude/analytics-client-common": "^2.0.10",
|
|
40
|
+
"@amplitude/analytics-core": "^2.1.3",
|
|
41
41
|
"@amplitude/analytics-types": "^2.3.1",
|
|
42
42
|
"tslib": "^2.4.1"
|
|
43
43
|
},
|
|
44
44
|
"devDependencies": {
|
|
45
|
-
"@amplitude/analytics-browser": "^2.3.
|
|
45
|
+
"@amplitude/analytics-browser": "^2.3.8",
|
|
46
46
|
"@rollup/plugin-commonjs": "^23.0.4",
|
|
47
47
|
"@rollup/plugin-node-resolve": "^15.0.1",
|
|
48
48
|
"@rollup/plugin-typescript": "^10.0.1",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"files": [
|
|
55
55
|
"lib"
|
|
56
56
|
],
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "c87f8bead0ff7330ff39c9c5a8698ddb65f5eb8e"
|
|
58
58
|
}
|