@amplitude/analytics-browser 1.1.4 → 1.2.1
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/README.md +1 -1
- package/lib/cjs/attribution/campaign-tracker.d.ts +3 -0
- package/lib/cjs/attribution/campaign-tracker.d.ts.map +1 -1
- package/lib/cjs/browser-client.d.ts +4 -205
- package/lib/cjs/browser-client.d.ts.map +1 -1
- package/lib/cjs/browser-client.js +35 -207
- package/lib/cjs/browser-client.js.map +1 -1
- package/lib/cjs/config.d.ts +2 -30
- package/lib/cjs/config.d.ts.map +1 -1
- package/lib/cjs/config.js +10 -15
- package/lib/cjs/config.js.map +1 -1
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.d.ts.map +1 -1
- package/lib/cjs/index.js +6 -21
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/plugins/context.d.ts.map +1 -1
- package/lib/cjs/plugins/context.js.map +1 -1
- package/lib/cjs/snippet-index.js +6 -0
- package/lib/cjs/snippet-index.js.map +1 -1
- package/lib/cjs/storage/cookie.js +1 -1
- package/lib/cjs/storage/cookie.js.map +1 -1
- package/lib/cjs/utils/query-params.d.ts +1 -0
- package/lib/cjs/utils/query-params.d.ts.map +1 -1
- package/lib/cjs/utils/query-params.js +15 -4
- package/lib/cjs/utils/query-params.js.map +1 -1
- package/lib/cjs/utils/snippet-helper.js.map +1 -1
- package/lib/cjs/version.d.ts +1 -1
- package/lib/cjs/version.js +1 -1
- package/lib/cjs/version.js.map +1 -1
- package/lib/esm/attribution/campaign-tracker.d.ts +3 -0
- package/lib/esm/attribution/campaign-tracker.d.ts.map +1 -1
- package/lib/esm/browser-client.d.ts +4 -205
- package/lib/esm/browser-client.d.ts.map +1 -1
- package/lib/esm/browser-client.js +34 -207
- package/lib/esm/browser-client.js.map +1 -1
- package/lib/esm/config.d.ts +2 -30
- package/lib/esm/config.d.ts.map +1 -1
- package/lib/esm/config.js +10 -15
- package/lib/esm/config.js.map +1 -1
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.d.ts.map +1 -1
- package/lib/esm/index.js +4 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/plugins/context.d.ts.map +1 -1
- package/lib/esm/plugins/context.js.map +1 -1
- package/lib/esm/snippet-index.js +6 -0
- package/lib/esm/snippet-index.js.map +1 -1
- package/lib/esm/storage/cookie.js +1 -1
- package/lib/esm/storage/cookie.js.map +1 -1
- package/lib/esm/utils/query-params.d.ts +1 -0
- package/lib/esm/utils/query-params.d.ts.map +1 -1
- package/lib/esm/utils/query-params.js +13 -3
- package/lib/esm/utils/query-params.js.map +1 -1
- package/lib/esm/utils/snippet-helper.js.map +1 -1
- package/lib/esm/version.d.ts +1 -1
- package/lib/esm/version.js +1 -1
- package/lib/esm/version.js.map +1 -1
- package/lib/scripts/amplitude-min.js +1 -1
- package/lib/scripts/amplitude-min.js.gz +0 -0
- package/lib/scripts/amplitude-min.umd.js +1 -1
- package/lib/scripts/amplitude-min.umd.js.gz +0 -0
- package/lib/scripts/amplitude-snippet-instructions.html +1 -1
- package/lib/scripts/amplitude-snippet-min.js +1 -1
- package/package.json +4 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AmplitudeCore } from '@amplitude/analytics-core';
|
|
2
|
-
import { AdditionalBrowserOptions, AttributionBrowserOptions, BrowserConfig, BrowserOptions, EventOptions, Identify as IIdentify, Result, Revenue as IRevenue, TransportType } from '@amplitude/analytics-types';
|
|
2
|
+
import { AdditionalBrowserOptions, AttributionBrowserOptions, BrowserClient, BrowserConfig, BrowserOptions, EventOptions, Identify as IIdentify, Result, Revenue as IRevenue, TransportType } from '@amplitude/analytics-types';
|
|
3
3
|
export declare class AmplitudeBrowser extends AmplitudeCore<BrowserConfig> {
|
|
4
4
|
init(apiKey: string, userId?: string, options?: BrowserOptions & AdditionalBrowserOptions): Promise<void>;
|
|
5
5
|
runAttributionStrategy(attributionConfig?: AttributionBrowserOptions, isNewSession?: boolean): Promise<void>;
|
|
@@ -15,208 +15,7 @@ export declare class AmplitudeBrowser extends AmplitudeCore<BrowserConfig> {
|
|
|
15
15
|
groupIdentify(groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions): Promise<Result>;
|
|
16
16
|
revenue(revenue: IRevenue, eventOptions?: EventOptions): Promise<Result>;
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
*
|
|
22
|
-
* ```typescript
|
|
23
|
-
* await init(API_KEY, USER_ID, options).promise;
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare const init: (apiKey: string, userId?: string | undefined, options?: (BrowserOptions & AdditionalBrowserOptions) | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
27
|
-
/**
|
|
28
|
-
* Adds a new plugin.
|
|
29
|
-
*
|
|
30
|
-
* ```typescript
|
|
31
|
-
* const plugin = {...};
|
|
32
|
-
* amplitude.add(plugin);
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export declare const add: (plugin: import("@amplitude/analytics-types").Plugin) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
36
|
-
/**
|
|
37
|
-
* Removes a plugin.
|
|
38
|
-
*
|
|
39
|
-
* ```typescript
|
|
40
|
-
* amplitude.remove('myPlugin');
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
|
-
export declare const remove: (pluginName: string) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
44
|
-
/**
|
|
45
|
-
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
46
|
-
*
|
|
47
|
-
* ```typescript
|
|
48
|
-
* // event tracking with event type only
|
|
49
|
-
* track('Page Load');
|
|
50
|
-
*
|
|
51
|
-
* // event tracking with event type and additional event properties
|
|
52
|
-
* track('Page Load', { loadTime: 1000 });
|
|
53
|
-
*
|
|
54
|
-
* // event tracking with event type, additional event properties, and overwritten event options
|
|
55
|
-
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
56
|
-
*
|
|
57
|
-
* // alternatively, this tracking method is awaitable
|
|
58
|
-
* const result = await track('Page Load').promise;
|
|
59
|
-
* console.log(result.event); // {...}
|
|
60
|
-
* console.log(result.code); // 200
|
|
61
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
export declare const track: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<Result>>;
|
|
65
|
-
/**
|
|
66
|
-
* Alias for track()
|
|
67
|
-
*/
|
|
68
|
-
export declare const logEvent: (eventInput: string | import("@amplitude/analytics-types").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<Result>>;
|
|
69
|
-
/**
|
|
70
|
-
* Sends an identify event containing user property operations
|
|
71
|
-
*
|
|
72
|
-
* ```typescript
|
|
73
|
-
* const id = new Identify();
|
|
74
|
-
* id.set('colors', ['rose', 'gold']);
|
|
75
|
-
* identify(id);
|
|
76
|
-
*
|
|
77
|
-
* // alternatively, this tracking method is awaitable
|
|
78
|
-
* const result = await identify(id).promise;
|
|
79
|
-
* console.log(result.event); // {...}
|
|
80
|
-
* console.log(result.code); // 200
|
|
81
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
82
|
-
* ```
|
|
83
|
-
*/
|
|
84
|
-
export declare const identify: (identify: IIdentify, eventOptions?: EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<Result>>;
|
|
85
|
-
/**
|
|
86
|
-
* Sends a group identify event containing group property operations.
|
|
87
|
-
*
|
|
88
|
-
* ```typescript
|
|
89
|
-
* const id = new Identify();
|
|
90
|
-
* id.set('skills', ['js', 'ts']);
|
|
91
|
-
* const groupType = 'org';
|
|
92
|
-
* const groupName = 'engineering';
|
|
93
|
-
* groupIdentify(groupType, groupName, id);
|
|
94
|
-
*
|
|
95
|
-
* // alternatively, this tracking method is awaitable
|
|
96
|
-
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
97
|
-
* console.log(result.event); // {...}
|
|
98
|
-
* console.log(result.code); // 200
|
|
99
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
100
|
-
* ```
|
|
101
|
-
*/
|
|
102
|
-
export declare const groupIdentify: (groupType: string, groupName: string | string[], identify: IIdentify, eventOptions?: EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<Result>>;
|
|
103
|
-
export declare const setGroup: (groupType: string, groupName: string | string[]) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<Result>>;
|
|
104
|
-
/**
|
|
105
|
-
* Sends a revenue event containing revenue property operations.
|
|
106
|
-
*
|
|
107
|
-
* ```typescript
|
|
108
|
-
* const rev = new Revenue();
|
|
109
|
-
* rev.setRevenue(100);
|
|
110
|
-
* revenue(rev);
|
|
111
|
-
*
|
|
112
|
-
* // alternatively, this tracking method is awaitable
|
|
113
|
-
* const result = await revenue(rev).promise;
|
|
114
|
-
* console.log(result.event); // {...}
|
|
115
|
-
* console.log(result.code); // 200
|
|
116
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
117
|
-
* ```
|
|
118
|
-
*/
|
|
119
|
-
export declare const revenue: (revenue: IRevenue, eventOptions?: EventOptions | undefined) => import("@amplitude/analytics-types").AmplitudeReturn<Promise<Result>>;
|
|
120
|
-
/**
|
|
121
|
-
* Returns current user ID.
|
|
122
|
-
*
|
|
123
|
-
* ```typescript
|
|
124
|
-
* const userId = getUserId();
|
|
125
|
-
* ```
|
|
126
|
-
*/
|
|
127
|
-
export declare const getUserId: () => string | undefined;
|
|
128
|
-
/**
|
|
129
|
-
* Sets a new user ID.
|
|
130
|
-
*
|
|
131
|
-
* ```typescript
|
|
132
|
-
* setUserId('userId');
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
export declare const setUserId: (userId: string | undefined) => void;
|
|
136
|
-
/**
|
|
137
|
-
* Returns current device ID.
|
|
138
|
-
*
|
|
139
|
-
* ```typescript
|
|
140
|
-
* const deviceId = getDeviceId();
|
|
141
|
-
* ```
|
|
142
|
-
*/
|
|
143
|
-
export declare const getDeviceId: () => string | undefined;
|
|
144
|
-
/**
|
|
145
|
-
* Sets a new device ID.
|
|
146
|
-
* When setting a custom device ID, make sure the value is sufficiently unique.
|
|
147
|
-
* A uuid is recommended.
|
|
148
|
-
*
|
|
149
|
-
* ```typescript
|
|
150
|
-
* setDeviceId('deviceId');
|
|
151
|
-
* ```
|
|
152
|
-
*/
|
|
153
|
-
export declare const setDeviceId: (deviceId: string) => void;
|
|
154
|
-
/**
|
|
155
|
-
* reset is a shortcut to anonymize users after they log out, by:
|
|
156
|
-
* - setting userId to `undefined`
|
|
157
|
-
* - regenerating a new random deviceId
|
|
158
|
-
*
|
|
159
|
-
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
160
|
-
*
|
|
161
|
-
* ```typescript
|
|
162
|
-
* reset();
|
|
163
|
-
* ```
|
|
164
|
-
*/
|
|
165
|
-
export declare const reset: () => void;
|
|
166
|
-
/**
|
|
167
|
-
* Returns current session ID.
|
|
168
|
-
*
|
|
169
|
-
* ```typescript
|
|
170
|
-
* const sessionId = getSessionId();
|
|
171
|
-
* ```
|
|
172
|
-
*/
|
|
173
|
-
export declare const getSessionId: () => number | undefined;
|
|
174
|
-
/**
|
|
175
|
-
* Sets a new session ID.
|
|
176
|
-
* When settign a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).
|
|
177
|
-
*
|
|
178
|
-
* ```typescript
|
|
179
|
-
* setSessionId(Date.now());
|
|
180
|
-
* ```
|
|
181
|
-
*/
|
|
182
|
-
export declare const setSessionId: (sessionId: number) => void;
|
|
183
|
-
/**
|
|
184
|
-
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
185
|
-
*
|
|
186
|
-
*```typescript
|
|
187
|
-
* // Stops tracking
|
|
188
|
-
* setOptOut(true);
|
|
189
|
-
*
|
|
190
|
-
* // Starts/resumes tracking
|
|
191
|
-
* setOptOut(false);
|
|
192
|
-
* ```
|
|
193
|
-
*/
|
|
194
|
-
export declare const setOptOut: (optOut: boolean) => void;
|
|
195
|
-
/**
|
|
196
|
-
* Sets the network transport type for events.
|
|
197
|
-
*
|
|
198
|
-
* ```typescript
|
|
199
|
-
* // Use Fetch API
|
|
200
|
-
* setTransport('fetch');
|
|
201
|
-
*
|
|
202
|
-
* // Use XMLHttpRequest API
|
|
203
|
-
* setTransport('xhr');
|
|
204
|
-
*
|
|
205
|
-
* // Use navigator.sendBeacon API
|
|
206
|
-
* setTransport('beacon');
|
|
207
|
-
* ```
|
|
208
|
-
*/
|
|
209
|
-
export declare const setTransport: (transport: TransportType) => void;
|
|
210
|
-
/**
|
|
211
|
-
* Flush and send all the events which haven't been sent.
|
|
212
|
-
*
|
|
213
|
-
*```typescript
|
|
214
|
-
* // Send all the unsent events
|
|
215
|
-
* flush();
|
|
216
|
-
*
|
|
217
|
-
* // alternatively, this tracking method is awaitable
|
|
218
|
-
* await flush().promise;
|
|
219
|
-
* ```
|
|
220
|
-
*/
|
|
221
|
-
export declare const flush: () => import("@amplitude/analytics-types").AmplitudeReturn<Promise<void>>;
|
|
18
|
+
export declare const createInstance: () => BrowserClient;
|
|
19
|
+
declare const _default: BrowserClient;
|
|
20
|
+
export default _default;
|
|
222
21
|
//# sourceMappingURL=browser-client.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-client.d.ts","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAuD,MAAM,2BAA2B,CAAC;AAC/G,OAAO,EACL,wBAAwB,EACxB,yBAAyB,EACzB,aAAa,EACb,cAAc,EAEd,YAAY,EACZ,QAAQ,IAAI,SAAS,EACrB,MAAM,EACN,OAAO,I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C,MAAM,CAAC;IASlB,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,YAAY,CAAC,EAAE,YAAY;CAQvD;AAED,eAAO,MAAM,cAAc,QAAO,aAuBjC,CAAC;;AAEF,wBAAgC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { __assign, __awaiter, __extends, __generator } from "tslib";
|
|
2
|
-
import { AmplitudeCore, Destination, Identify, Revenue,
|
|
2
|
+
import { AmplitudeCore, Destination, Identify, Revenue, UUID, returnWrapper } from '@amplitude/analytics-core';
|
|
3
3
|
import { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';
|
|
4
4
|
import { Context } from './plugins/context';
|
|
5
5
|
import { useBrowserConfig, createTransport, createFlexibleStorage } from './config';
|
|
@@ -19,7 +19,13 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
19
19
|
var _this = this;
|
|
20
20
|
return __generator(this, function (_d) {
|
|
21
21
|
switch (_d.label) {
|
|
22
|
-
case 0:
|
|
22
|
+
case 0:
|
|
23
|
+
// Step 0: Block concurrent initialization
|
|
24
|
+
if (this.initializing) {
|
|
25
|
+
return [2 /*return*/];
|
|
26
|
+
}
|
|
27
|
+
this.initializing = true;
|
|
28
|
+
return [4 /*yield*/, parseOldCookies(apiKey, options)];
|
|
23
29
|
case 1:
|
|
24
30
|
oldCookies = _d.sent();
|
|
25
31
|
return [4 /*yield*/, useBrowserConfig(apiKey, userId || oldCookies.userId, __assign(__assign({}, options), { deviceId: (_a = oldCookies.deviceId) !== null && _a !== void 0 ? _a : options === null || options === void 0 ? void 0 : options.deviceId, sessionId: (_b = oldCookies.sessionId) !== null && _b !== void 0 ? _b : options === null || options === void 0 ? void 0 : options.sessionId, optOut: (_c = options === null || options === void 0 ? void 0 : options.optOut) !== null && _c !== void 0 ? _c : oldCookies.optOut, lastEventTime: oldCookies.lastEventTime }))];
|
|
@@ -58,6 +64,7 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
58
64
|
return [4 /*yield*/, this.add(new Destination())];
|
|
59
65
|
case 6:
|
|
60
66
|
_d.sent();
|
|
67
|
+
this.initializing = false;
|
|
61
68
|
// Step 5: Set timeline ready for processing events
|
|
62
69
|
// Send existing events, which might be collected by track before init
|
|
63
70
|
this.timeline.isReady = true;
|
|
@@ -167,209 +174,29 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
167
174
|
return AmplitudeBrowser;
|
|
168
175
|
}(AmplitudeCore));
|
|
169
176
|
export { AmplitudeBrowser };
|
|
170
|
-
var
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
*/
|
|
196
|
-
export var remove = returnWrapper(client.remove.bind(client));
|
|
197
|
-
/**
|
|
198
|
-
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
199
|
-
*
|
|
200
|
-
* ```typescript
|
|
201
|
-
* // event tracking with event type only
|
|
202
|
-
* track('Page Load');
|
|
203
|
-
*
|
|
204
|
-
* // event tracking with event type and additional event properties
|
|
205
|
-
* track('Page Load', { loadTime: 1000 });
|
|
206
|
-
*
|
|
207
|
-
* // event tracking with event type, additional event properties, and overwritten event options
|
|
208
|
-
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
209
|
-
*
|
|
210
|
-
* // alternatively, this tracking method is awaitable
|
|
211
|
-
* const result = await track('Page Load').promise;
|
|
212
|
-
* console.log(result.event); // {...}
|
|
213
|
-
* console.log(result.code); // 200
|
|
214
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
215
|
-
* ```
|
|
216
|
-
*/
|
|
217
|
-
export var track = returnWrapper(client.track.bind(client));
|
|
218
|
-
/**
|
|
219
|
-
* Alias for track()
|
|
220
|
-
*/
|
|
221
|
-
export var logEvent = returnWrapper(client.logEvent.bind(client));
|
|
222
|
-
/**
|
|
223
|
-
* Sends an identify event containing user property operations
|
|
224
|
-
*
|
|
225
|
-
* ```typescript
|
|
226
|
-
* const id = new Identify();
|
|
227
|
-
* id.set('colors', ['rose', 'gold']);
|
|
228
|
-
* identify(id);
|
|
229
|
-
*
|
|
230
|
-
* // alternatively, this tracking method is awaitable
|
|
231
|
-
* const result = await identify(id).promise;
|
|
232
|
-
* console.log(result.event); // {...}
|
|
233
|
-
* console.log(result.code); // 200
|
|
234
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
235
|
-
* ```
|
|
236
|
-
*/
|
|
237
|
-
export var identify = returnWrapper(client.identify.bind(client));
|
|
238
|
-
/**
|
|
239
|
-
* Sends a group identify event containing group property operations.
|
|
240
|
-
*
|
|
241
|
-
* ```typescript
|
|
242
|
-
* const id = new Identify();
|
|
243
|
-
* id.set('skills', ['js', 'ts']);
|
|
244
|
-
* const groupType = 'org';
|
|
245
|
-
* const groupName = 'engineering';
|
|
246
|
-
* groupIdentify(groupType, groupName, id);
|
|
247
|
-
*
|
|
248
|
-
* // alternatively, this tracking method is awaitable
|
|
249
|
-
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
250
|
-
* console.log(result.event); // {...}
|
|
251
|
-
* console.log(result.code); // 200
|
|
252
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
253
|
-
* ```
|
|
254
|
-
*/
|
|
255
|
-
export var groupIdentify = returnWrapper(client.groupIdentify.bind(client));
|
|
256
|
-
export var setGroup = returnWrapper(client.setGroup.bind(client));
|
|
257
|
-
/**
|
|
258
|
-
* Sends a revenue event containing revenue property operations.
|
|
259
|
-
*
|
|
260
|
-
* ```typescript
|
|
261
|
-
* const rev = new Revenue();
|
|
262
|
-
* rev.setRevenue(100);
|
|
263
|
-
* revenue(rev);
|
|
264
|
-
*
|
|
265
|
-
* // alternatively, this tracking method is awaitable
|
|
266
|
-
* const result = await revenue(rev).promise;
|
|
267
|
-
* console.log(result.event); // {...}
|
|
268
|
-
* console.log(result.code); // 200
|
|
269
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
270
|
-
* ```
|
|
271
|
-
*/
|
|
272
|
-
export var revenue = returnWrapper(client.revenue.bind(client));
|
|
273
|
-
/**
|
|
274
|
-
* Returns current user ID.
|
|
275
|
-
*
|
|
276
|
-
* ```typescript
|
|
277
|
-
* const userId = getUserId();
|
|
278
|
-
* ```
|
|
279
|
-
*/
|
|
280
|
-
export var getUserId = client.getUserId.bind(client);
|
|
281
|
-
/**
|
|
282
|
-
* Sets a new user ID.
|
|
283
|
-
*
|
|
284
|
-
* ```typescript
|
|
285
|
-
* setUserId('userId');
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
export var setUserId = client.setUserId.bind(client);
|
|
289
|
-
/**
|
|
290
|
-
* Returns current device ID.
|
|
291
|
-
*
|
|
292
|
-
* ```typescript
|
|
293
|
-
* const deviceId = getDeviceId();
|
|
294
|
-
* ```
|
|
295
|
-
*/
|
|
296
|
-
export var getDeviceId = client.getDeviceId.bind(client);
|
|
297
|
-
/**
|
|
298
|
-
* Sets a new device ID.
|
|
299
|
-
* When setting a custom device ID, make sure the value is sufficiently unique.
|
|
300
|
-
* A uuid is recommended.
|
|
301
|
-
*
|
|
302
|
-
* ```typescript
|
|
303
|
-
* setDeviceId('deviceId');
|
|
304
|
-
* ```
|
|
305
|
-
*/
|
|
306
|
-
export var setDeviceId = client.setDeviceId.bind(client);
|
|
307
|
-
/**
|
|
308
|
-
* reset is a shortcut to anonymize users after they log out, by:
|
|
309
|
-
* - setting userId to `undefined`
|
|
310
|
-
* - regenerating a new random deviceId
|
|
311
|
-
*
|
|
312
|
-
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
313
|
-
*
|
|
314
|
-
* ```typescript
|
|
315
|
-
* reset();
|
|
316
|
-
* ```
|
|
317
|
-
*/
|
|
318
|
-
export var reset = client.reset.bind(client);
|
|
319
|
-
/**
|
|
320
|
-
* Returns current session ID.
|
|
321
|
-
*
|
|
322
|
-
* ```typescript
|
|
323
|
-
* const sessionId = getSessionId();
|
|
324
|
-
* ```
|
|
325
|
-
*/
|
|
326
|
-
export var getSessionId = client.getSessionId.bind(client);
|
|
327
|
-
/**
|
|
328
|
-
* Sets a new session ID.
|
|
329
|
-
* When settign a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).
|
|
330
|
-
*
|
|
331
|
-
* ```typescript
|
|
332
|
-
* setSessionId(Date.now());
|
|
333
|
-
* ```
|
|
334
|
-
*/
|
|
335
|
-
export var setSessionId = client.setSessionId.bind(client);
|
|
336
|
-
/**
|
|
337
|
-
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
338
|
-
*
|
|
339
|
-
*```typescript
|
|
340
|
-
* // Stops tracking
|
|
341
|
-
* setOptOut(true);
|
|
342
|
-
*
|
|
343
|
-
* // Starts/resumes tracking
|
|
344
|
-
* setOptOut(false);
|
|
345
|
-
* ```
|
|
346
|
-
*/
|
|
347
|
-
export var setOptOut = client.setOptOut.bind(client);
|
|
348
|
-
/**
|
|
349
|
-
* Sets the network transport type for events.
|
|
350
|
-
*
|
|
351
|
-
* ```typescript
|
|
352
|
-
* // Use Fetch API
|
|
353
|
-
* setTransport('fetch');
|
|
354
|
-
*
|
|
355
|
-
* // Use XMLHttpRequest API
|
|
356
|
-
* setTransport('xhr');
|
|
357
|
-
*
|
|
358
|
-
* // Use navigator.sendBeacon API
|
|
359
|
-
* setTransport('beacon');
|
|
360
|
-
* ```
|
|
361
|
-
*/
|
|
362
|
-
export var setTransport = client.setTransport.bind(client);
|
|
363
|
-
/**
|
|
364
|
-
* Flush and send all the events which haven't been sent.
|
|
365
|
-
*
|
|
366
|
-
*```typescript
|
|
367
|
-
* // Send all the unsent events
|
|
368
|
-
* flush();
|
|
369
|
-
*
|
|
370
|
-
* // alternatively, this tracking method is awaitable
|
|
371
|
-
* await flush().promise;
|
|
372
|
-
* ```
|
|
373
|
-
*/
|
|
374
|
-
export var flush = returnWrapper(client.flush.bind(client));
|
|
177
|
+
export var createInstance = function () {
|
|
178
|
+
var client = new AmplitudeBrowser();
|
|
179
|
+
return {
|
|
180
|
+
init: returnWrapper(client.init.bind(client)),
|
|
181
|
+
add: returnWrapper(client.add.bind(client)),
|
|
182
|
+
remove: returnWrapper(client.remove.bind(client)),
|
|
183
|
+
track: returnWrapper(client.track.bind(client)),
|
|
184
|
+
logEvent: returnWrapper(client.logEvent.bind(client)),
|
|
185
|
+
identify: returnWrapper(client.identify.bind(client)),
|
|
186
|
+
groupIdentify: returnWrapper(client.groupIdentify.bind(client)),
|
|
187
|
+
setGroup: returnWrapper(client.setGroup.bind(client)),
|
|
188
|
+
revenue: returnWrapper(client.revenue.bind(client)),
|
|
189
|
+
flush: returnWrapper(client.flush.bind(client)),
|
|
190
|
+
getUserId: client.getUserId.bind(client),
|
|
191
|
+
setUserId: client.setUserId.bind(client),
|
|
192
|
+
getDeviceId: client.getDeviceId.bind(client),
|
|
193
|
+
setDeviceId: client.setDeviceId.bind(client),
|
|
194
|
+
reset: client.reset.bind(client),
|
|
195
|
+
getSessionId: client.getSessionId.bind(client),
|
|
196
|
+
setSessionId: client.setSessionId.bind(client),
|
|
197
|
+
setOptOut: client.setOptOut.bind(client),
|
|
198
|
+
setTransport: client.setTransport.bind(client),
|
|
199
|
+
};
|
|
200
|
+
};
|
|
201
|
+
export default createInstance();
|
|
375
202
|
//# sourceMappingURL=browser-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAa/G,OAA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AW,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE3D;;;;;;;;GAQG;AACH,MAAM,CAAC,IAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE/C;;;;;;GAMG;AACH,MAAM,CAAC,IAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE7D;;;;;;;GAOG;AACH,MAAM,CAAC,IAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,IAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,MAAM,CAAC,IAAM,KAAK,GAAG,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC","sourcesContent":["import { AmplitudeCore, Destination, Identify, Revenue, returnWrapper, UUID } from '@amplitude/analytics-core';\nimport {\n AdditionalBrowserOptions,\n AttributionBrowserOptions,\n BrowserConfig,\n BrowserOptions,\n Campaign,\n EventOptions,\n Identify as IIdentify,\n Result,\n Revenue as IRevenue,\n TransportType,\n} from '@amplitude/analytics-types';\nimport { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';\nimport { Context } from './plugins/context';\nimport { useBrowserConfig, createTransport, createFlexibleStorage } from './config';\nimport { parseOldCookies } from './cookie-migration';\nimport { CampaignTracker } from './attribution/campaign-tracker';\nimport { getAnalyticsConnector } from './utils/analytics-connector';\nimport { IdentityEventSender } from './plugins/identity';\n\nexport class AmplitudeBrowser extends AmplitudeCore<BrowserConfig> {\n async init(apiKey: string, userId?: string, options?: BrowserOptions & AdditionalBrowserOptions) {\n // Step 1: Read cookies stored by old SDK\n const oldCookies = await parseOldCookies(apiKey, options);\n\n // Step 2: Create browser config\n const browserOptions = await useBrowserConfig(apiKey, userId || oldCookies.userId, {\n ...options,\n deviceId: oldCookies.deviceId ?? options?.deviceId,\n sessionId: oldCookies.sessionId ?? options?.sessionId,\n optOut: options?.optOut ?? oldCookies.optOut,\n lastEventTime: oldCookies.lastEventTime,\n });\n await super._init(browserOptions);\n\n // Step 3: Manage session\n let isNewSession = !this.config.lastEventTime;\n if (\n !this.config.sessionId ||\n (this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout)\n ) {\n // Either\n // 1) No previous session; or\n // 2) Previous session expired\n this.setSessionId(Date.now());\n isNewSession = true;\n }\n\n // Set up the analytics connector to integrate with the experiment SDK.\n // Send events from the experiment SDK and forward identifies to the\n // identity store.\n const connector = getAnalyticsConnector();\n connector.eventBridge.setEventReceiver((event) => {\n void this.track(event.eventType, event.eventProperties);\n });\n connector.identityStore.setIdentity({\n userId: this.config.userId,\n deviceId: this.config.deviceId,\n });\n\n // Step 4: Install plugins\n // Do not track any events before this\n await this.add(new Context());\n await this.add(new IdentityEventSender());\n await this.add(new Destination());\n\n // Step 5: Set timeline ready for processing events\n // Send existing events, which might be collected by track before init\n this.timeline.isReady = true;\n if (!this.config.optOut) {\n this.timeline.scheduleApply(0);\n }\n\n // Step 6: Track attributions\n await this.runAttributionStrategy(options?.attribution, isNewSession);\n }\n\n async runAttributionStrategy(attributionConfig?: AttributionBrowserOptions, isNewSession = false) {\n const track = this.track.bind(this);\n const onNewCampaign = this.setSessionId.bind(this, Date.now());\n\n const storage = await createFlexibleStorage<Campaign>(this.config);\n const campaignTracker = new CampaignTracker(this.config.apiKey, {\n ...attributionConfig,\n storage,\n track,\n onNewCampaign,\n });\n\n await campaignTracker.send(isNewSession);\n }\n\n getUserId() {\n return this.config?.userId;\n }\n\n setUserId(userId: string | undefined) {\n if (!this.config) {\n this.q.push(this.setUserId.bind(this, userId));\n return;\n }\n this.config.userId = userId;\n }\n\n getDeviceId() {\n return this.config?.deviceId;\n }\n\n setDeviceId(deviceId: string) {\n if (!this.config) {\n this.q.push(this.setDeviceId.bind(this, deviceId));\n return;\n }\n this.config.deviceId = deviceId;\n }\n\n reset() {\n this.setUserId(undefined);\n this.setDeviceId(UUID());\n }\n\n getSessionId() {\n return this.config?.sessionId;\n }\n\n setSessionId(sessionId: number) {\n if (!this.config) {\n this.q.push(this.setSessionId.bind(this, sessionId));\n return;\n }\n this.config.sessionId = sessionId;\n this.config.lastEventTime = undefined;\n }\n\n setTransport(transport: TransportType) {\n if (!this.config) {\n this.q.push(this.setTransport.bind(this, transport));\n return;\n }\n this.config.transportProvider = createTransport(transport);\n }\n\n identify(identify: IIdentify, eventOptions?: EventOptions): Promise<Result> {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return super.identify(identify, eventOptions);\n }\n\n groupIdentify(\n groupType: string,\n groupName: string | string[],\n identify: IIdentify,\n eventOptions?: EventOptions,\n ): Promise<Result> {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return super.groupIdentify(groupType, groupName, identify, eventOptions);\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n if (isInstanceProxy(revenue)) {\n const queue = revenue._q;\n revenue._q = [];\n revenue = convertProxyObjectToRealObject(new Revenue(), queue);\n }\n return super.revenue(revenue, eventOptions);\n }\n}\n\nconst client = new AmplitudeBrowser();\n\n/**\n * Initializes the Amplitude SDK with your apiKey, userId and optional configurations.\n * This method must be called before any other operations.\n *\n * ```typescript\n * await init(API_KEY, USER_ID, options).promise;\n * ```\n */\nexport const init = returnWrapper(client.init.bind(client));\n\n/**\n * Adds a new plugin.\n *\n * ```typescript\n * const plugin = {...};\n * amplitude.add(plugin);\n * ```\n */\nexport const add = returnWrapper(client.add.bind(client));\n\n/**\n * Removes a plugin.\n *\n * ```typescript\n * amplitude.remove('myPlugin');\n * ```\n */\nexport const remove = returnWrapper(client.remove.bind(client));\n\n/**\n * Tracks user-defined event, with specified type, optional event properties and optional overwrites.\n *\n * ```typescript\n * // event tracking with event type only\n * track('Page Load');\n *\n * // event tracking with event type and additional event properties\n * track('Page Load', { loadTime: 1000 });\n *\n * // event tracking with event type, additional event properties, and overwritten event options\n * track('Page Load', { loadTime: 1000 }, { sessionId: -1 });\n *\n * // alternatively, this tracking method is awaitable\n * const result = await track('Page Load').promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const track = returnWrapper(client.track.bind(client));\n\n/**\n * Alias for track()\n */\nexport const logEvent = returnWrapper(client.logEvent.bind(client));\n\n/**\n * Sends an identify event containing user property operations\n *\n * ```typescript\n * const id = new Identify();\n * id.set('colors', ['rose', 'gold']);\n * identify(id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await identify(id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const identify = returnWrapper(client.identify.bind(client));\n\n/**\n * Sends a group identify event containing group property operations.\n *\n * ```typescript\n * const id = new Identify();\n * id.set('skills', ['js', 'ts']);\n * const groupType = 'org';\n * const groupName = 'engineering';\n * groupIdentify(groupType, groupName, id);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await groupIdentify(groupType, groupName, id).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const groupIdentify = returnWrapper(client.groupIdentify.bind(client));\nexport const setGroup = returnWrapper(client.setGroup.bind(client));\n\n/**\n * Sends a revenue event containing revenue property operations.\n *\n * ```typescript\n * const rev = new Revenue();\n * rev.setRevenue(100);\n * revenue(rev);\n *\n * // alternatively, this tracking method is awaitable\n * const result = await revenue(rev).promise;\n * console.log(result.event); // {...}\n * console.log(result.code); // 200\n * console.log(result.message); // \"Event tracked successfully\"\n * ```\n */\nexport const revenue = returnWrapper(client.revenue.bind(client));\n\n/**\n * Returns current user ID.\n *\n * ```typescript\n * const userId = getUserId();\n * ```\n */\nexport const getUserId = client.getUserId.bind(client);\n\n/**\n * Sets a new user ID.\n *\n * ```typescript\n * setUserId('userId');\n * ```\n */\nexport const setUserId = client.setUserId.bind(client);\n\n/**\n * Returns current device ID.\n *\n * ```typescript\n * const deviceId = getDeviceId();\n * ```\n */\nexport const getDeviceId = client.getDeviceId.bind(client);\n\n/**\n * Sets a new device ID.\n * When setting a custom device ID, make sure the value is sufficiently unique.\n * A uuid is recommended.\n *\n * ```typescript\n * setDeviceId('deviceId');\n * ```\n */\nexport const setDeviceId = client.setDeviceId.bind(client);\n\n/**\n * reset is a shortcut to anonymize users after they log out, by:\n * - setting userId to `undefined`\n * - regenerating a new random deviceId\n *\n * With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.\n *\n * ```typescript\n * reset();\n * ```\n */\nexport const reset = client.reset.bind(client);\n\n/**\n * Returns current session ID.\n *\n * ```typescript\n * const sessionId = getSessionId();\n * ```\n */\nexport const getSessionId = client.getSessionId.bind(client);\n\n/**\n * Sets a new session ID.\n * When settign a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).\n *\n * ```typescript\n * setSessionId(Date.now());\n * ```\n */\nexport const setSessionId = client.setSessionId.bind(client);\n\n/**\n * Sets a new optOut config value. This toggles event tracking on/off.\n *\n *```typescript\n * // Stops tracking\n * setOptOut(true);\n *\n * // Starts/resumes tracking\n * setOptOut(false);\n * ```\n */\nexport const setOptOut = client.setOptOut.bind(client);\n\n/**\n * Sets the network transport type for events.\n *\n * ```typescript\n * // Use Fetch API\n * setTransport('fetch');\n *\n * // Use XMLHttpRequest API\n * setTransport('xhr');\n *\n * // Use navigator.sendBeacon API\n * setTransport('beacon');\n * ```\n */\nexport const setTransport = client.setTransport.bind(client);\n\n/**\n * Flush and send all the events which haven't been sent.\n *\n *```typescript\n * // Send all the unsent events\n * flush();\n *\n * // alternatively, this tracking method is awaitable\n * await flush().promise;\n * ```\n */\nexport const flush = returnWrapper(client.flush.bind(client));\n"]}
|
|
1
|
+
{"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../src/browser-client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAc/G,OAAO,EAAE,8BAA8B,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzF,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,qBAAqB,EAAE,MAAM,UAAU,CAAC;AACpF,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAC;AACpE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAEzD;IAAsC,oCAA4B;IAAlE;;IAiKA,CAAC;IAhKO,+BAAI,GAAV,UAAW,MAAc,EAAE,MAAe,EAAE,OAAmD;;;;;;;;wBAC7F,0CAA0C;wBAC1C,IAAI,IAAI,CAAC,YAAY,EAAE;4BACrB,sBAAO;yBACR;wBACD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;wBAGN,qBAAM,eAAe,CAAC,MAAM,EAAE,OAAO,CAAC,EAAA;;wBAAnD,UAAU,GAAG,SAAsC;wBAGlC,qBAAM,g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C,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACnD,KAAK,EAAE,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAC/C,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;QACxC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;QACxC,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;QAC5C,WAAW,EAAE,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC;QAC5C,KAAK,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;QAChC,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;QAC9C,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;QAC9C,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC;QACxC,YAAY,EAAE,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC;KAC/C,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,EAAE,CAAC","sourcesContent":["import { AmplitudeCore, Destination, Identify, Revenue, UUID, returnWrapper } from '@amplitude/analytics-core';\nimport {\n AdditionalBrowserOptions,\n AttributionBrowserOptions,\n BrowserClient,\n BrowserConfig,\n BrowserOptions,\n Campaign,\n EventOptions,\n Identify as IIdentify,\n Result,\n Revenue as IRevenue,\n TransportType,\n} from '@amplitude/analytics-types';\nimport { convertProxyObjectToRealObject, isInstanceProxy } from './utils/snippet-helper';\nimport { Context } from './plugins/context';\nimport { useBrowserConfig, createTransport, createFlexibleStorage } from './config';\nimport { parseOldCookies } from './cookie-migration';\nimport { CampaignTracker } from './attribution/campaign-tracker';\nimport { getAnalyticsConnector } from './utils/analytics-connector';\nimport { IdentityEventSender } from './plugins/identity';\n\nexport class AmplitudeBrowser extends AmplitudeCore<BrowserConfig> {\n async init(apiKey: string, userId?: string, options?: BrowserOptions & AdditionalBrowserOptions) {\n // Step 0: Block concurrent initialization\n if (this.initializing) {\n return;\n }\n this.initializing = true;\n\n // Step 1: Read cookies stored by old SDK\n const oldCookies = await parseOldCookies(apiKey, options);\n\n // Step 2: Create browser config\n const browserOptions = await useBrowserConfig(apiKey, userId || oldCookies.userId, {\n ...options,\n deviceId: oldCookies.deviceId ?? options?.deviceId,\n sessionId: oldCookies.sessionId ?? options?.sessionId,\n optOut: options?.optOut ?? oldCookies.optOut,\n lastEventTime: oldCookies.lastEventTime,\n });\n await super._init(browserOptions);\n\n // Step 3: Manage session\n let isNewSession = !this.config.lastEventTime;\n if (\n !this.config.sessionId ||\n (this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout)\n ) {\n // Either\n // 1) No previous session; or\n // 2) Previous session expired\n this.setSessionId(Date.now());\n isNewSession = true;\n }\n\n // Set up the analytics connector to integrate with the experiment SDK.\n // Send events from the experiment SDK and forward identifies to the\n // identity store.\n const connector = getAnalyticsConnector();\n connector.eventBridge.setEventReceiver((event) => {\n void this.track(event.eventType, event.eventProperties);\n });\n connector.identityStore.setIdentity({\n userId: this.config.userId,\n deviceId: this.config.deviceId,\n });\n\n // Step 4: Install plugins\n // Do not track any events before this\n await this.add(new Context());\n await this.add(new IdentityEventSender());\n await this.add(new Destination());\n\n this.initializing = false;\n\n // Step 5: Set timeline ready for processing events\n // Send existing events, which might be collected by track before init\n this.timeline.isReady = true;\n if (!this.config.optOut) {\n this.timeline.scheduleApply(0);\n }\n\n // Step 6: Track attributions\n await this.runAttributionStrategy(options?.attribution, isNewSession);\n }\n\n async runAttributionStrategy(attributionConfig?: AttributionBrowserOptions, isNewSession = false) {\n const track = this.track.bind(this);\n const onNewCampaign = this.setSessionId.bind(this, Date.now());\n\n const storage = await createFlexibleStorage<Campaign>(this.config);\n const campaignTracker = new CampaignTracker(this.config.apiKey, {\n ...attributionConfig,\n storage,\n track,\n onNewCampaign,\n });\n\n await campaignTracker.send(isNewSession);\n }\n\n getUserId() {\n return this.config?.userId;\n }\n\n setUserId(userId: string | undefined) {\n if (!this.config) {\n this.q.push(this.setUserId.bind(this, userId));\n return;\n }\n this.config.userId = userId;\n }\n\n getDeviceId() {\n return this.config?.deviceId;\n }\n\n setDeviceId(deviceId: string) {\n if (!this.config) {\n this.q.push(this.setDeviceId.bind(this, deviceId));\n return;\n }\n this.config.deviceId = deviceId;\n }\n\n reset() {\n this.setUserId(undefined);\n this.setDeviceId(UUID());\n }\n\n getSessionId() {\n return this.config?.sessionId;\n }\n\n setSessionId(sessionId: number) {\n if (!this.config) {\n this.q.push(this.setSessionId.bind(this, sessionId));\n return;\n }\n this.config.sessionId = sessionId;\n this.config.lastEventTime = undefined;\n }\n\n setTransport(transport: TransportType) {\n if (!this.config) {\n this.q.push(this.setTransport.bind(this, transport));\n return;\n }\n this.config.transportProvider = createTransport(transport);\n }\n\n identify(identify: IIdentify, eventOptions?: EventOptions): Promise<Result> {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return super.identify(identify, eventOptions);\n }\n\n groupIdentify(\n groupType: string,\n groupName: string | string[],\n identify: IIdentify,\n eventOptions?: EventOptions,\n ): Promise<Result> {\n if (isInstanceProxy(identify)) {\n const queue = identify._q;\n identify._q = [];\n identify = convertProxyObjectToRealObject(new Identify(), queue);\n }\n return super.groupIdentify(groupType, groupName, identify, eventOptions);\n }\n\n revenue(revenue: IRevenue, eventOptions?: EventOptions) {\n if (isInstanceProxy(revenue)) {\n const queue = revenue._q;\n revenue._q = [];\n revenue = convertProxyObjectToRealObject(new Revenue(), queue);\n }\n return super.revenue(revenue, eventOptions);\n }\n}\n\nexport const createInstance = (): BrowserClient => {\n const client = new AmplitudeBrowser();\n return {\n init: returnWrapper(client.init.bind(client)),\n add: returnWrapper(client.add.bind(client)),\n remove: returnWrapper(client.remove.bind(client)),\n track: returnWrapper(client.track.bind(client)),\n logEvent: returnWrapper(client.logEvent.bind(client)),\n identify: returnWrapper(client.identify.bind(client)),\n groupIdentify: returnWrapper(client.groupIdentify.bind(client)),\n setGroup: returnWrapper(client.setGroup.bind(client)),\n revenue: returnWrapper(client.revenue.bind(client)),\n flush: returnWrapper(client.flush.bind(client)),\n getUserId: client.getUserId.bind(client),\n setUserId: client.setUserId.bind(client),\n getDeviceId: client.getDeviceId.bind(client),\n setDeviceId: client.setDeviceId.bind(client),\n reset: client.reset.bind(client),\n getSessionId: client.getSessionId.bind(client),\n setSessionId: client.setSessionId.bind(client),\n setOptOut: client.setOptOut.bind(client),\n setTransport: client.setTransport.bind(client),\n };\n};\n\nexport default createInstance();\n"]}
|
package/lib/esm/config.d.ts
CHANGED
|
@@ -14,21 +14,7 @@ export declare const getDefaultConfig: () => {
|
|
|
14
14
|
sessionManager: SessionManager;
|
|
15
15
|
sessionTimeout: number;
|
|
16
16
|
storageProvider: MemoryStorage<Event[]>;
|
|
17
|
-
trackingOptions:
|
|
18
|
-
city: boolean;
|
|
19
|
-
country: boolean;
|
|
20
|
-
carrier: boolean;
|
|
21
|
-
deviceManufacturer: boolean;
|
|
22
|
-
deviceModel: boolean;
|
|
23
|
-
dma: boolean;
|
|
24
|
-
ipAddress: boolean;
|
|
25
|
-
language: boolean;
|
|
26
|
-
osName: boolean;
|
|
27
|
-
osVersion: boolean;
|
|
28
|
-
platform: boolean;
|
|
29
|
-
region: boolean;
|
|
30
|
-
versionName: boolean;
|
|
31
|
-
};
|
|
17
|
+
trackingOptions: Required<TrackingOptions>;
|
|
32
18
|
transportProvider: FetchTransport;
|
|
33
19
|
};
|
|
34
20
|
export declare class BrowserConfig extends Config implements IBrowserConfig {
|
|
@@ -66,21 +52,7 @@ export declare const createCookieStorage: (overrides?: BrowserOptions | undefine
|
|
|
66
52
|
sessionManager: SessionManager;
|
|
67
53
|
sessionTimeout: number;
|
|
68
54
|
storageProvider: MemoryStorage<Event[]>;
|
|
69
|
-
trackingOptions:
|
|
70
|
-
city: boolean;
|
|
71
|
-
country: boolean;
|
|
72
|
-
carrier: boolean;
|
|
73
|
-
deviceManufacturer: boolean;
|
|
74
|
-
deviceModel: boolean;
|
|
75
|
-
dma: boolean;
|
|
76
|
-
ipAddress: boolean;
|
|
77
|
-
language: boolean;
|
|
78
|
-
osName: boolean;
|
|
79
|
-
osVersion: boolean;
|
|
80
|
-
platform: boolean;
|
|
81
|
-
region: boolean;
|
|
82
|
-
versionName: boolean;
|
|
83
|
-
};
|
|
55
|
+
trackingOptions: Required<TrackingOptions>;
|
|
84
56
|
transportProvider: FetchTransport;
|
|
85
57
|
}) => Promise<Storage<UserSession>>;
|
|
86
58
|
export declare const createFlexibleStorage: <T>(options: BrowserOptions) => Promise<Storage<T>>;
|
package/lib/esm/config.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,cAAc,EACd,aAAa,IAAI,cAAc,EAC/B,OAAO,EACP,eAAe,EACf,aAAa,EACb,WAAW,EACX,cAAc,IAAI,eAAe,EAClC,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,MAAM,EAAE,aAAa,EAAQ,MAAM,2BAA2B,CAAC;AAGxE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAIpD,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,eAAO,MAAM,gBAAgB
|
|
1
|
+
{"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,cAAc,EACd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S,EAAE,MAAM,GAAG,SAAS,EAE1C;IAED,IAAI,MAAM,IAIS,OAAO,CAFzB;IAED,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,EAEzB;IAED,IAAI,aAAa,IAIgB,MAAM,GAAG,SAAS,CAFlD;IAED,IAAI,aAAa,CAAC,aAAa,EAAE,MAAM,GAAG,SAAS,EAElD;CACF;AAED,eAAO,MAAM,gBAAgB,WACnB,MAAM,wEAGb,QAAQ,cAAc,CAqBxB,CAAC;AAEF,eAAO,MAAM,mBAAmB;;;;;;;;;;;;MAG7B,QAAQ,QAAQ,WAAW,CAAC,CAO9B,CAAC;AAEF,eAAO,MAAM,qBAAqB,eAAsB,cAAc,wBAcrE,CAAC;AAEF,eAAO,MAAM,mBAAmB,8CAAuC,QAAQ,QAAQ,KAAK,EAAE,CAAC,GAAG,SAAS,CAe1G,CAAC;AAEF,eAAO,MAAM,cAAc,4HAE1B,CAAC;AAEF,eAAO,MAAM,eAAe,gGAQ3B,CAAC;AAEF,eAAO,MAAM,iBAAiB,+CA0B7B,CAAC"}
|
package/lib/esm/config.js
CHANGED
|
@@ -11,6 +11,15 @@ import { SendBeaconTransport } from './transports/send-beacon';
|
|
|
11
11
|
import { SessionManager } from './session-manager';
|
|
12
12
|
export var getDefaultConfig = function () {
|
|
13
13
|
var cookieStorage = new MemoryStorage();
|
|
14
|
+
var trackingOptions = {
|
|
15
|
+
deviceManufacturer: true,
|
|
16
|
+
deviceModel: true,
|
|
17
|
+
ipAddress: true,
|
|
18
|
+
language: true,
|
|
19
|
+
osName: true,
|
|
20
|
+
osVersion: true,
|
|
21
|
+
platform: true,
|
|
22
|
+
};
|
|
14
23
|
return {
|
|
15
24
|
cookieExpiration: 365,
|
|
16
25
|
cookieSameSite: 'Lax',
|
|
@@ -21,21 +30,7 @@ export var getDefaultConfig = function () {
|
|
|
21
30
|
sessionManager: new SessionManager(cookieStorage, ''),
|
|
22
31
|
sessionTimeout: 30 * 60 * 1000,
|
|
23
32
|
storageProvider: new MemoryStorage(),
|
|
24
|
-
trackingOptions:
|
|
25
|
-
city: true,
|
|
26
|
-
country: true,
|
|
27
|
-
carrier: true,
|
|
28
|
-
deviceManufacturer: true,
|
|
29
|
-
deviceModel: true,
|
|
30
|
-
dma: true,
|
|
31
|
-
ipAddress: true,
|
|
32
|
-
language: true,
|
|
33
|
-
osName: true,
|
|
34
|
-
osVersion: true,
|
|
35
|
-
platform: true,
|
|
36
|
-
region: true,
|
|
37
|
-
versionName: true,
|
|
38
|
-
},
|
|
33
|
+
trackingOptions: trackingOptions,
|
|
39
34
|
transportProvider: new FetchTransport(),
|
|
40
35
|
};
|
|
41
36
|
};
|