@amplitude/plugin-web-attribution-browser 0.1.3
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/LICENSE +21 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.d.ts.map +1 -0
- package/lib/cjs/index.js +7 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/plugin-campaign-tracker.d.ts +69 -0
- package/lib/cjs/plugin-campaign-tracker.d.ts.map +1 -0
- package/lib/cjs/plugin-campaign-tracker.js +58 -0
- package/lib/cjs/plugin-campaign-tracker.js.map +1 -0
- package/lib/cjs/typings/web-attribution.d.ts +7 -0
- package/lib/cjs/typings/web-attribution.d.ts.map +1 -0
- package/lib/cjs/typings/web-attribution.js +2 -0
- package/lib/cjs/typings/web-attribution.js.map +1 -0
- package/lib/cjs/web-attribution.d.ts +4 -0
- package/lib/cjs/web-attribution.d.ts.map +1 -0
- package/lib/cjs/web-attribution.js +53 -0
- package/lib/cjs/web-attribution.js.map +1 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.d.ts.map +1 -0
- package/lib/esm/index.js +4 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/plugin-campaign-tracker.d.ts +69 -0
- package/lib/esm/plugin-campaign-tracker.d.ts.map +1 -0
- package/lib/esm/plugin-campaign-tracker.js +56 -0
- package/lib/esm/plugin-campaign-tracker.js.map +1 -0
- package/lib/esm/typings/web-attribution.d.ts +7 -0
- package/lib/esm/typings/web-attribution.d.ts.map +1 -0
- package/lib/esm/typings/web-attribution.js +2 -0
- package/lib/esm/typings/web-attribution.js.map +1 -0
- package/lib/esm/web-attribution.d.ts +4 -0
- package/lib/esm/web-attribution.d.ts.map +1 -0
- package/lib/esm/web-attribution.js +48 -0
- package/lib/esm/web-attribution.js.map +1 -0
- package/package.json +45 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 Amplitude Analytics
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -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,KAAK,KAAK,MAAM,2BAA2B,CAAC"}
|
package/lib/cjs/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.Types = exports.webAttributionPlugin = void 0;
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var web_attribution_1 = require("./web-attribution");
|
|
5
|
+
Object.defineProperty(exports, "webAttributionPlugin", { enumerable: true, get: function () { return web_attribution_1.webAttributionPlugin; } });
|
|
6
|
+
exports.Types = (0, tslib_1.__importStar)(require("./typings/web-attribution"));
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAyD;AAAhD,uHAAA,oBAAoB,OAAA;AAC7B,gFAAmD","sourcesContent":["export { webAttributionPlugin } from './web-attribution';\nexport * as Types from './typings/web-attribution';\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
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: import("@amplitude/analytics-types").IdentifyUserProperties | {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
} | {
|
|
15
|
+
[x: string]: any;
|
|
16
|
+
};
|
|
17
|
+
group_properties?: {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
} | undefined;
|
|
20
|
+
groups?: {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
} | undefined;
|
|
23
|
+
user_id?: string | undefined;
|
|
24
|
+
device_id?: string | undefined;
|
|
25
|
+
time?: number | undefined;
|
|
26
|
+
location_lat?: number | undefined;
|
|
27
|
+
location_lng?: number | undefined;
|
|
28
|
+
app_version?: string | undefined;
|
|
29
|
+
version_name?: string | undefined;
|
|
30
|
+
library?: string | undefined;
|
|
31
|
+
platform?: string | undefined;
|
|
32
|
+
os_name?: string | undefined;
|
|
33
|
+
os_version?: string | undefined;
|
|
34
|
+
device_brand?: string | undefined;
|
|
35
|
+
device_manufacturer?: string | undefined;
|
|
36
|
+
device_model?: string | undefined;
|
|
37
|
+
carrier?: string | undefined;
|
|
38
|
+
country?: string | undefined;
|
|
39
|
+
region?: string | undefined;
|
|
40
|
+
city?: string | undefined;
|
|
41
|
+
dma?: string | undefined;
|
|
42
|
+
idfa?: string | undefined;
|
|
43
|
+
idfv?: string | undefined;
|
|
44
|
+
adid?: string | undefined;
|
|
45
|
+
android_id?: string | undefined;
|
|
46
|
+
language?: string | undefined;
|
|
47
|
+
ip?: string | undefined;
|
|
48
|
+
price?: number | undefined;
|
|
49
|
+
quantity?: number | undefined;
|
|
50
|
+
revenue?: number | undefined;
|
|
51
|
+
productId?: string | undefined;
|
|
52
|
+
revenueType?: string | undefined;
|
|
53
|
+
event_id?: number | undefined;
|
|
54
|
+
session_id?: number | undefined;
|
|
55
|
+
insert_id?: string | undefined;
|
|
56
|
+
plan?: import("@amplitude/analytics-types").Plan | undefined;
|
|
57
|
+
ingestion_metadata?: import("@amplitude/analytics-types/lib/esm/ingestion-metadata").IngestionMetadataEventProperty | undefined;
|
|
58
|
+
partner_id?: string | undefined;
|
|
59
|
+
extra?: {
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
} | undefined;
|
|
62
|
+
};
|
|
63
|
+
onPageChange(callback: (state: {
|
|
64
|
+
isNewCampaign: boolean;
|
|
65
|
+
currentCampaign: Campaign;
|
|
66
|
+
}) => Promise<unknown>): Promise<void>;
|
|
67
|
+
private getCurrentState;
|
|
68
|
+
}
|
|
69
|
+
//# 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;CAW9B"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
exports.PluginCampaignTracker = void 0;
|
|
3
|
+
var tslib_1 = require("tslib");
|
|
4
|
+
var analytics_client_common_1 = require("@amplitude/analytics-client-common");
|
|
5
|
+
var PluginCampaignTracker = /** @class */ (function () {
|
|
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 }));
|
|
8
|
+
}
|
|
9
|
+
PluginCampaignTracker.prototype.createCampaignEvent = function (currentCampaign) {
|
|
10
|
+
return this.campaignTracker.createCampaignEvent(currentCampaign);
|
|
11
|
+
};
|
|
12
|
+
PluginCampaignTracker.prototype.onPageChange = function (callback) {
|
|
13
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
14
|
+
var _a, currentState;
|
|
15
|
+
return (0, tslib_1.__generator)(this, function (_b) {
|
|
16
|
+
switch (_b.label) {
|
|
17
|
+
case 0:
|
|
18
|
+
_a = callback;
|
|
19
|
+
return [4 /*yield*/, this.getCurrentState()];
|
|
20
|
+
case 1: return [4 /*yield*/, _a.apply(void 0, [_b.sent()])];
|
|
21
|
+
case 2:
|
|
22
|
+
_b.sent();
|
|
23
|
+
return [4 /*yield*/, this.getCurrentState()];
|
|
24
|
+
case 3:
|
|
25
|
+
currentState = _b.sent();
|
|
26
|
+
if (currentState.isNewCampaign) {
|
|
27
|
+
void this.campaignTracker.saveCampaignToStorage(currentState.currentCampaign);
|
|
28
|
+
}
|
|
29
|
+
return [2 /*return*/];
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
PluginCampaignTracker.prototype.getCurrentState = function () {
|
|
35
|
+
return (0, tslib_1.__awaiter)(this, void 0, void 0, function () {
|
|
36
|
+
var currentCampaign, isNewCampaign, _a, _b, _c;
|
|
37
|
+
return (0, tslib_1.__generator)(this, function (_d) {
|
|
38
|
+
switch (_d.label) {
|
|
39
|
+
case 0: return [4 /*yield*/, this.campaignTracker.parser.parse()];
|
|
40
|
+
case 1:
|
|
41
|
+
currentCampaign = _d.sent();
|
|
42
|
+
_b = (_a = this.campaignTracker).isNewCampaign;
|
|
43
|
+
_c = [currentCampaign];
|
|
44
|
+
return [4 /*yield*/, this.campaignTracker.getCampaignFromStorage()];
|
|
45
|
+
case 2:
|
|
46
|
+
isNewCampaign = _b.apply(_a, _c.concat([_d.sent()]));
|
|
47
|
+
return [2 /*return*/, {
|
|
48
|
+
isNewCampaign: isNewCampaign,
|
|
49
|
+
currentCampaign: currentCampaign,
|
|
50
|
+
}];
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
return PluginCampaignTracker;
|
|
56
|
+
}());
|
|
57
|
+
exports.PluginCampaignTracker = PluginCampaignTracker;
|
|
58
|
+
//# sourceMappingURL=plugin-campaign-tracker.js.map
|
|
@@ -0,0 +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,GACpD;wBACD,sBAAO;gCACL,aAAa,eAAA;gCACb,eAAe,iBAAA;6BAChB,EAAC;;;;KACH;IACH,4BAAC;AAAD,CAAC,AArCD,IAqCC;AArCY,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 );\n return {\n isNewCampaign,\n currentCampaign,\n };\n }\n}\n"]}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../../src/typings/web-attribution.ts"],"names":[],"mappings":"","sourcesContent":["export interface Options {\n disabled?: boolean;\n excludeReferrers?: string[];\n initialEmptyValue?: string;\n resetSessionOnNewCampaign?: boolean;\n}\n"]}
|
|
@@ -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"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
var _this = this;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.webAttributionPlugin = void 0;
|
|
4
|
+
var tslib_1 = require("tslib");
|
|
5
|
+
var analytics_types_1 = require("@amplitude/analytics-types");
|
|
6
|
+
var plugin_campaign_tracker_1 = require("./plugin-campaign-tracker");
|
|
7
|
+
var webAttributionPlugin = function (client, options) {
|
|
8
|
+
if (options === void 0) { options = {}; }
|
|
9
|
+
return ({
|
|
10
|
+
name: 'web-attribution',
|
|
11
|
+
type: analytics_types_1.PluginType.BEFORE,
|
|
12
|
+
setup: function (config) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () {
|
|
13
|
+
var storage, campaignTracker;
|
|
14
|
+
var _this = this;
|
|
15
|
+
var _a;
|
|
16
|
+
return (0, tslib_1.__generator)(this, function (_b) {
|
|
17
|
+
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser');
|
|
18
|
+
// Disable "runAttributionStrategy" function
|
|
19
|
+
if (!((_a = config.attribution) === null || _a === void 0 ? void 0 : _a.disabled)) {
|
|
20
|
+
config.loggerProvider.warn('@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser');
|
|
21
|
+
config.attribution = {
|
|
22
|
+
disabled: true,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
storage = config.cookieStorage;
|
|
26
|
+
campaignTracker = new plugin_campaign_tracker_1.PluginCampaignTracker(config.apiKey, storage, (0, tslib_1.__assign)({}, options));
|
|
27
|
+
// Web Attribution tracking
|
|
28
|
+
void campaignTracker.onPageChange(function (_a) {
|
|
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) {
|
|
32
|
+
if (isNewCampaign) {
|
|
33
|
+
if (options.resetSessionOnNewCampaign) {
|
|
34
|
+
client.setSessionId(Date.now());
|
|
35
|
+
config.loggerProvider.log('Created a new session for new campaign');
|
|
36
|
+
}
|
|
37
|
+
config.loggerProvider.log('Tracking new campaign event');
|
|
38
|
+
void client.track(campaignTracker.createCampaignEvent(currentCampaign));
|
|
39
|
+
}
|
|
40
|
+
return [2 /*return*/];
|
|
41
|
+
});
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
return [2 /*return*/];
|
|
45
|
+
});
|
|
46
|
+
}); },
|
|
47
|
+
execute: function (event) { return (0, tslib_1.__awaiter)(_this, void 0, void 0, function () { return (0, tslib_1.__generator)(this, function (_a) {
|
|
48
|
+
return [2 /*return*/, event];
|
|
49
|
+
}); }); },
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
exports.webAttributionPlugin = webAttributionPlugin;
|
|
53
|
+
//# sourceMappingURL=web-attribution.js.map
|
|
@@ -0,0 +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"]}
|
|
@@ -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,KAAK,KAAK,MAAM,2BAA2B,CAAC"}
|
package/lib/esm/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;yBAClC,2BAA2B;oBAAtC,KAAK","sourcesContent":["export { webAttributionPlugin } from './web-attribution';\nexport * as Types from './typings/web-attribution';\n"]}
|
|
@@ -0,0 +1,69 @@
|
|
|
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: import("@amplitude/analytics-types").IdentifyUserProperties | {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
} | {
|
|
15
|
+
[x: string]: any;
|
|
16
|
+
};
|
|
17
|
+
group_properties?: {
|
|
18
|
+
[key: string]: any;
|
|
19
|
+
} | undefined;
|
|
20
|
+
groups?: {
|
|
21
|
+
[key: string]: any;
|
|
22
|
+
} | undefined;
|
|
23
|
+
user_id?: string | undefined;
|
|
24
|
+
device_id?: string | undefined;
|
|
25
|
+
time?: number | undefined;
|
|
26
|
+
location_lat?: number | undefined;
|
|
27
|
+
location_lng?: number | undefined;
|
|
28
|
+
app_version?: string | undefined;
|
|
29
|
+
version_name?: string | undefined;
|
|
30
|
+
library?: string | undefined;
|
|
31
|
+
platform?: string | undefined;
|
|
32
|
+
os_name?: string | undefined;
|
|
33
|
+
os_version?: string | undefined;
|
|
34
|
+
device_brand?: string | undefined;
|
|
35
|
+
device_manufacturer?: string | undefined;
|
|
36
|
+
device_model?: string | undefined;
|
|
37
|
+
carrier?: string | undefined;
|
|
38
|
+
country?: string | undefined;
|
|
39
|
+
region?: string | undefined;
|
|
40
|
+
city?: string | undefined;
|
|
41
|
+
dma?: string | undefined;
|
|
42
|
+
idfa?: string | undefined;
|
|
43
|
+
idfv?: string | undefined;
|
|
44
|
+
adid?: string | undefined;
|
|
45
|
+
android_id?: string | undefined;
|
|
46
|
+
language?: string | undefined;
|
|
47
|
+
ip?: string | undefined;
|
|
48
|
+
price?: number | undefined;
|
|
49
|
+
quantity?: number | undefined;
|
|
50
|
+
revenue?: number | undefined;
|
|
51
|
+
productId?: string | undefined;
|
|
52
|
+
revenueType?: string | undefined;
|
|
53
|
+
event_id?: number | undefined;
|
|
54
|
+
session_id?: number | undefined;
|
|
55
|
+
insert_id?: string | undefined;
|
|
56
|
+
plan?: import("@amplitude/analytics-types").Plan | undefined;
|
|
57
|
+
ingestion_metadata?: import("@amplitude/analytics-types/lib/esm/ingestion-metadata").IngestionMetadataEventProperty | undefined;
|
|
58
|
+
partner_id?: string | undefined;
|
|
59
|
+
extra?: {
|
|
60
|
+
[key: string]: any;
|
|
61
|
+
} | undefined;
|
|
62
|
+
};
|
|
63
|
+
onPageChange(callback: (state: {
|
|
64
|
+
isNewCampaign: boolean;
|
|
65
|
+
currentCampaign: Campaign;
|
|
66
|
+
}) => Promise<unknown>): Promise<void>;
|
|
67
|
+
private getCurrentState;
|
|
68
|
+
}
|
|
69
|
+
//# 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;CAW9B"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
|
+
import { CampaignTracker } from '@amplitude/analytics-client-common';
|
|
3
|
+
var PluginCampaignTracker = /** @class */ (function () {
|
|
4
|
+
function PluginCampaignTracker(apiKey, storage, options) {
|
|
5
|
+
this.campaignTracker = new CampaignTracker(apiKey, __assign(__assign({}, options), { trackPageViews: false, track: /* istanbul ignore next */ function () { return Promise.resolve(); }, onNewCampaign: /* istanbul ignore next */ function () { return function () { return undefined; }; }, storage: storage }));
|
|
6
|
+
}
|
|
7
|
+
PluginCampaignTracker.prototype.createCampaignEvent = function (currentCampaign) {
|
|
8
|
+
return this.campaignTracker.createCampaignEvent(currentCampaign);
|
|
9
|
+
};
|
|
10
|
+
PluginCampaignTracker.prototype.onPageChange = function (callback) {
|
|
11
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
12
|
+
var _a, currentState;
|
|
13
|
+
return __generator(this, function (_b) {
|
|
14
|
+
switch (_b.label) {
|
|
15
|
+
case 0:
|
|
16
|
+
_a = callback;
|
|
17
|
+
return [4 /*yield*/, this.getCurrentState()];
|
|
18
|
+
case 1: return [4 /*yield*/, _a.apply(void 0, [_b.sent()])];
|
|
19
|
+
case 2:
|
|
20
|
+
_b.sent();
|
|
21
|
+
return [4 /*yield*/, this.getCurrentState()];
|
|
22
|
+
case 3:
|
|
23
|
+
currentState = _b.sent();
|
|
24
|
+
if (currentState.isNewCampaign) {
|
|
25
|
+
void this.campaignTracker.saveCampaignToStorage(currentState.currentCampaign);
|
|
26
|
+
}
|
|
27
|
+
return [2 /*return*/];
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
PluginCampaignTracker.prototype.getCurrentState = function () {
|
|
33
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
34
|
+
var currentCampaign, isNewCampaign, _a, _b, _c;
|
|
35
|
+
return __generator(this, function (_d) {
|
|
36
|
+
switch (_d.label) {
|
|
37
|
+
case 0: return [4 /*yield*/, this.campaignTracker.parser.parse()];
|
|
38
|
+
case 1:
|
|
39
|
+
currentCampaign = _d.sent();
|
|
40
|
+
_b = (_a = this.campaignTracker).isNewCampaign;
|
|
41
|
+
_c = [currentCampaign];
|
|
42
|
+
return [4 /*yield*/, this.campaignTracker.getCampaignFromStorage()];
|
|
43
|
+
case 2:
|
|
44
|
+
isNewCampaign = _b.apply(_a, _c.concat([_d.sent()]));
|
|
45
|
+
return [2 /*return*/, {
|
|
46
|
+
isNewCampaign: isNewCampaign,
|
|
47
|
+
currentCampaign: currentCampaign,
|
|
48
|
+
}];
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
return PluginCampaignTracker;
|
|
54
|
+
}());
|
|
55
|
+
export { PluginCampaignTracker };
|
|
56
|
+
//# sourceMappingURL=plugin-campaign-tracker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugin-campaign-tracker.js","sourceRoot":"","sources":["../../src/plugin-campaign-tracker.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AAGrE;IAGE,+BAAY,MAAc,EAAE,OAA0B,EAAE,OAA2B;QACjF,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAC,MAAM,wBAC5C,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,GACpD;wBACD,sBAAO;gCACL,aAAa,eAAA;gCACb,eAAe,iBAAA;6BAChB,EAAC;;;;KACH;IACH,4BAAC;AAAD,CAAC,AArCD,IAqCC","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 );\n return {\n isNewCampaign,\n currentCampaign,\n };\n }\n}\n"]}
|
|
@@ -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 @@
|
|
|
1
|
+
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../../src/typings/web-attribution.ts"],"names":[],"mappings":"","sourcesContent":["export interface Options {\n disabled?: boolean;\n excludeReferrers?: string[];\n initialEmptyValue?: string;\n resetSessionOnNewCampaign?: boolean;\n}\n"]}
|
|
@@ -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"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { __assign, __awaiter, __generator } from "tslib";
|
|
2
|
+
import { PluginType, } from '@amplitude/analytics-types';
|
|
3
|
+
import { PluginCampaignTracker } from './plugin-campaign-tracker';
|
|
4
|
+
export var webAttributionPlugin = function (client, options) {
|
|
5
|
+
if (options === void 0) { options = {}; }
|
|
6
|
+
return ({
|
|
7
|
+
name: 'web-attribution',
|
|
8
|
+
type: PluginType.BEFORE,
|
|
9
|
+
setup: function (config) { return __awaiter(void 0, void 0, void 0, function () {
|
|
10
|
+
var storage, campaignTracker;
|
|
11
|
+
var _a;
|
|
12
|
+
return __generator(this, function (_b) {
|
|
13
|
+
config.loggerProvider.log('Installing @amplitude/plugin-web-attribution-browser');
|
|
14
|
+
// Disable "runAttributionStrategy" function
|
|
15
|
+
if (!((_a = config.attribution) === null || _a === void 0 ? void 0 : _a.disabled)) {
|
|
16
|
+
config.loggerProvider.warn('@amplitude/plugin-web-attribution-browser overrides web attribution behavior defined in @amplitude/analytics-browser');
|
|
17
|
+
config.attribution = {
|
|
18
|
+
disabled: true,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
storage = config.cookieStorage;
|
|
22
|
+
campaignTracker = new PluginCampaignTracker(config.apiKey, storage, __assign({}, options));
|
|
23
|
+
// Web Attribution tracking
|
|
24
|
+
void campaignTracker.onPageChange(function (_a) {
|
|
25
|
+
var isNewCampaign = _a.isNewCampaign, currentCampaign = _a.currentCampaign;
|
|
26
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
|
27
|
+
return __generator(this, function (_b) {
|
|
28
|
+
if (isNewCampaign) {
|
|
29
|
+
if (options.resetSessionOnNewCampaign) {
|
|
30
|
+
client.setSessionId(Date.now());
|
|
31
|
+
config.loggerProvider.log('Created a new session for new campaign');
|
|
32
|
+
}
|
|
33
|
+
config.loggerProvider.log('Tracking new campaign event');
|
|
34
|
+
void client.track(campaignTracker.createCampaignEvent(currentCampaign));
|
|
35
|
+
}
|
|
36
|
+
return [2 /*return*/];
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
return [2 /*return*/];
|
|
41
|
+
});
|
|
42
|
+
}); },
|
|
43
|
+
execute: function (event) { return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) {
|
|
44
|
+
return [2 /*return*/, event];
|
|
45
|
+
}); }); },
|
|
46
|
+
});
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=web-attribution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-attribution.js","sourceRoot":"","sources":["../../src/web-attribution.ts"],"names":[],"mappings":";AAAA,OAAO,EAML,UAAU,GAEX,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,2BAA2B,CAAC;AAGlE,MAAM,CAAC,IAAM,oBAAoB,GAAG,UAAC,MAAqB,EAAE,OAAqB;IAArB,wBAAA,EAAA,YAAqB;IAAmB,OAAA,CAAC;QACnG,IAAI,EAAE,iBAAiB;QACvB,IAAI,EAAE,UAAU,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,qBAAqB,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,eACnE,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","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"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@amplitude/plugin-web-attribution-browser",
|
|
3
|
+
"version": "0.1.3",
|
|
4
|
+
"description": "",
|
|
5
|
+
"author": "Amplitude Inc",
|
|
6
|
+
"homepage": "https://github.com/amplitude/Amplitude-TypeScript",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "lib/cjs/index.js",
|
|
9
|
+
"module": "lib/esm/index.js",
|
|
10
|
+
"types": "lib/esm/index.d.ts",
|
|
11
|
+
"publishConfig": {
|
|
12
|
+
"access": "public"
|
|
13
|
+
},
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/amplitude/Amplitude-TypeScript.git"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "yarn build:es5 && yarn build:esm",
|
|
20
|
+
"build:es5": "tsc -p ./tsconfig.es5.json",
|
|
21
|
+
"build:esm": "tsc -p ./tsconfig.esm.json",
|
|
22
|
+
"clean": "rimraf node_modules lib coverage",
|
|
23
|
+
"fix": "yarn fix:eslint & yarn fix:prettier",
|
|
24
|
+
"fix:eslint": "eslint '{src,test}/**/*.ts' --fix",
|
|
25
|
+
"fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
|
|
26
|
+
"lint": "yarn lint:eslint & yarn lint:prettier",
|
|
27
|
+
"lint:eslint": "eslint '{src,test}/**/*.ts'",
|
|
28
|
+
"lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
|
|
29
|
+
"test": "jest",
|
|
30
|
+
"typecheck": "tsc -p ./tsconfig.json"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@amplitude/analytics-browser": "^1.5.0",
|
|
37
|
+
"@amplitude/analytics-client-common": "^0.2.1",
|
|
38
|
+
"@amplitude/analytics-types": "^0.10.2",
|
|
39
|
+
"tslib": "^2.3.1"
|
|
40
|
+
},
|
|
41
|
+
"files": [
|
|
42
|
+
"lib"
|
|
43
|
+
],
|
|
44
|
+
"gitHead": "d5d22e7f4f52d5ed816cd473acc4c9e57a9e61dd"
|
|
45
|
+
}
|