@amplitude/analytics-browser 1.1.5 → 1.2.0
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/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/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/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/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
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ Alternatively, the package is also distributed through a CDN. Copy and paste the
|
|
|
32
32
|
<!-- README_SNIPPET_BLOCK -->
|
|
33
33
|
```html
|
|
34
34
|
<script type="text/javascript">
|
|
35
|
-
!function(){"use strict";!function(e,t){var
|
|
35
|
+
!function(){"use strict";!function(e,t){var n=e.amplitude||{_q:[],_iq:[]};if(n.invoked)e.console&&console.error&&console.error("Amplitude snippet has been loaded.");else{n.invoked=!0;var r=t.createElement("script");r.type="text/javascript",r.integrity="sha384-Y4XyoQjvRukDBVnBbXqJPNh2s443JCBG79sung/JWWUc5u3w5iWdPqUAY1EL461g",r.crossOrigin="anonymous",r.async=!0,r.src="https://cdn.amplitude.com/libs/analytics-browser-1.2.0-min.js.gz",r.onload=function(){e.amplitude.runQueuedFunctions||console.log("[Amplitude] Error: could not load SDK")};var s=t.getElementsByTagName("script")[0];function v(e,t){e.prototype[t]=function(){return this._q.push({name:t,args:Array.prototype.slice.call(arguments,0)}),this}}s.parentNode.insertBefore(r,s);for(var o=function(){return this._q=[],this},i=["add","append","clearAll","prepend","set","setOnce","unset","preInsert","postInsert","remove","getUserProperties"],u=0;u<i.length;u++)v(o,i[u]);n.Identify=o;for(var a=function(){return this._q=[],this},c=["getEventProperties","setProductId","setQuantity","setPrice","setRevenue","setRevenueType","setEventProperties"],p=0;p<c.length;p++)v(a,c[p]);n.Revenue=a;var d=["getDeviceId","setDeviceId","getSessionId","setSessionId","getUserId","setUserId","setOptOut","setTransport","reset"],l=["init","add","remove","track","logEvent","identify","groupIdentify","setGroup","revenue","flush"];function f(e){function t(t,n){e[t]=function(){var r={promise:new Promise((n=>{e._q.push({name:t,args:Array.prototype.slice.call(arguments,0),resolve:n})}))};if(n)return r}}for(var n=0;n<d.length;n++)t(d[n],!1);for(var r=0;r<l.length;r++)t(l[r],!0)}f(n),n.createInstance=function(){var e=n._iq.push({_q:[]})-1;return f(n._iq[e]),n._iq[e]},e.amplitude=n}}(window,document)}();
|
|
36
36
|
|
|
37
37
|
amplitude.init("YOUR_API_KEY_HERE");
|
|
38
38
|
</script>
|
|
@@ -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[], eventOptions?: EventOptions | undefined) => 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,IAAI,QAAQ,EACnB,aAAa,EACd,MAAM,4BAA4B,CAAC;AASpC,qBAAa,gBAAiB,SAAQ,aAAa,CAAC,aAAa,CAAC;IAC1D,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CA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1
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
-
exports.
|
|
2
|
+
exports.createInstance = exports.AmplitudeBrowser = void 0;
|
|
3
3
|
var tslib_1 = require("tslib");
|
|
4
4
|
var analytics_core_1 = require("@amplitude/analytics-core");
|
|
5
5
|
var snippet_helper_1 = require("./utils/snippet-helper");
|
|
@@ -21,7 +21,13 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
21
21
|
var _this = this;
|
|
22
22
|
return (0, tslib_1.__generator)(this, function (_d) {
|
|
23
23
|
switch (_d.label) {
|
|
24
|
-
case 0:
|
|
24
|
+
case 0:
|
|
25
|
+
// Step 0: Block concurrent initialization
|
|
26
|
+
if (this.initializing) {
|
|
27
|
+
return [2 /*return*/];
|
|
28
|
+
}
|
|
29
|
+
this.initializing = true;
|
|
30
|
+
return [4 /*yield*/, (0, cookie_migration_1.parseOldCookies)(apiKey, options)];
|
|
25
31
|
case 1:
|
|
26
32
|
oldCookies = _d.sent();
|
|
27
33
|
return [4 /*yield*/, (0, config_1.useBrowserConfig)(apiKey, userId || oldCookies.userId, (0, tslib_1.__assign)((0, tslib_1.__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 }))];
|
|
@@ -60,6 +66,7 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
60
66
|
return [4 /*yield*/, this.add(new analytics_core_1.Destination())];
|
|
61
67
|
case 6:
|
|
62
68
|
_d.sent();
|
|
69
|
+
this.initializing = false;
|
|
63
70
|
// Step 5: Set timeline ready for processing events
|
|
64
71
|
// Send existing events, which might be collected by track before init
|
|
65
72
|
this.timeline.isReady = true;
|
|
@@ -169,209 +176,30 @@ var AmplitudeBrowser = /** @class */ (function (_super) {
|
|
|
169
176
|
return AmplitudeBrowser;
|
|
170
177
|
}(analytics_core_1.AmplitudeCore));
|
|
171
178
|
exports.AmplitudeBrowser = AmplitudeBrowser;
|
|
172
|
-
var
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
exports.remove = (0, analytics_core_1.returnWrapper)(client.remove.bind(client));
|
|
199
|
-
/**
|
|
200
|
-
* Tracks user-defined event, with specified type, optional event properties and optional overwrites.
|
|
201
|
-
*
|
|
202
|
-
* ```typescript
|
|
203
|
-
* // event tracking with event type only
|
|
204
|
-
* track('Page Load');
|
|
205
|
-
*
|
|
206
|
-
* // event tracking with event type and additional event properties
|
|
207
|
-
* track('Page Load', { loadTime: 1000 });
|
|
208
|
-
*
|
|
209
|
-
* // event tracking with event type, additional event properties, and overwritten event options
|
|
210
|
-
* track('Page Load', { loadTime: 1000 }, { sessionId: -1 });
|
|
211
|
-
*
|
|
212
|
-
* // alternatively, this tracking method is awaitable
|
|
213
|
-
* const result = await track('Page Load').promise;
|
|
214
|
-
* console.log(result.event); // {...}
|
|
215
|
-
* console.log(result.code); // 200
|
|
216
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
217
|
-
* ```
|
|
218
|
-
*/
|
|
219
|
-
exports.track = (0, analytics_core_1.returnWrapper)(client.track.bind(client));
|
|
220
|
-
/**
|
|
221
|
-
* Alias for track()
|
|
222
|
-
*/
|
|
223
|
-
exports.logEvent = (0, analytics_core_1.returnWrapper)(client.logEvent.bind(client));
|
|
224
|
-
/**
|
|
225
|
-
* Sends an identify event containing user property operations
|
|
226
|
-
*
|
|
227
|
-
* ```typescript
|
|
228
|
-
* const id = new Identify();
|
|
229
|
-
* id.set('colors', ['rose', 'gold']);
|
|
230
|
-
* identify(id);
|
|
231
|
-
*
|
|
232
|
-
* // alternatively, this tracking method is awaitable
|
|
233
|
-
* const result = await identify(id).promise;
|
|
234
|
-
* console.log(result.event); // {...}
|
|
235
|
-
* console.log(result.code); // 200
|
|
236
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
237
|
-
* ```
|
|
238
|
-
*/
|
|
239
|
-
exports.identify = (0, analytics_core_1.returnWrapper)(client.identify.bind(client));
|
|
240
|
-
/**
|
|
241
|
-
* Sends a group identify event containing group property operations.
|
|
242
|
-
*
|
|
243
|
-
* ```typescript
|
|
244
|
-
* const id = new Identify();
|
|
245
|
-
* id.set('skills', ['js', 'ts']);
|
|
246
|
-
* const groupType = 'org';
|
|
247
|
-
* const groupName = 'engineering';
|
|
248
|
-
* groupIdentify(groupType, groupName, id);
|
|
249
|
-
*
|
|
250
|
-
* // alternatively, this tracking method is awaitable
|
|
251
|
-
* const result = await groupIdentify(groupType, groupName, id).promise;
|
|
252
|
-
* console.log(result.event); // {...}
|
|
253
|
-
* console.log(result.code); // 200
|
|
254
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
255
|
-
* ```
|
|
256
|
-
*/
|
|
257
|
-
exports.groupIdentify = (0, analytics_core_1.returnWrapper)(client.groupIdentify.bind(client));
|
|
258
|
-
exports.setGroup = (0, analytics_core_1.returnWrapper)(client.setGroup.bind(client));
|
|
259
|
-
/**
|
|
260
|
-
* Sends a revenue event containing revenue property operations.
|
|
261
|
-
*
|
|
262
|
-
* ```typescript
|
|
263
|
-
* const rev = new Revenue();
|
|
264
|
-
* rev.setRevenue(100);
|
|
265
|
-
* revenue(rev);
|
|
266
|
-
*
|
|
267
|
-
* // alternatively, this tracking method is awaitable
|
|
268
|
-
* const result = await revenue(rev).promise;
|
|
269
|
-
* console.log(result.event); // {...}
|
|
270
|
-
* console.log(result.code); // 200
|
|
271
|
-
* console.log(result.message); // "Event tracked successfully"
|
|
272
|
-
* ```
|
|
273
|
-
*/
|
|
274
|
-
exports.revenue = (0, analytics_core_1.returnWrapper)(client.revenue.bind(client));
|
|
275
|
-
/**
|
|
276
|
-
* Returns current user ID.
|
|
277
|
-
*
|
|
278
|
-
* ```typescript
|
|
279
|
-
* const userId = getUserId();
|
|
280
|
-
* ```
|
|
281
|
-
*/
|
|
282
|
-
exports.getUserId = client.getUserId.bind(client);
|
|
283
|
-
/**
|
|
284
|
-
* Sets a new user ID.
|
|
285
|
-
*
|
|
286
|
-
* ```typescript
|
|
287
|
-
* setUserId('userId');
|
|
288
|
-
* ```
|
|
289
|
-
*/
|
|
290
|
-
exports.setUserId = client.setUserId.bind(client);
|
|
291
|
-
/**
|
|
292
|
-
* Returns current device ID.
|
|
293
|
-
*
|
|
294
|
-
* ```typescript
|
|
295
|
-
* const deviceId = getDeviceId();
|
|
296
|
-
* ```
|
|
297
|
-
*/
|
|
298
|
-
exports.getDeviceId = client.getDeviceId.bind(client);
|
|
299
|
-
/**
|
|
300
|
-
* Sets a new device ID.
|
|
301
|
-
* When setting a custom device ID, make sure the value is sufficiently unique.
|
|
302
|
-
* A uuid is recommended.
|
|
303
|
-
*
|
|
304
|
-
* ```typescript
|
|
305
|
-
* setDeviceId('deviceId');
|
|
306
|
-
* ```
|
|
307
|
-
*/
|
|
308
|
-
exports.setDeviceId = client.setDeviceId.bind(client);
|
|
309
|
-
/**
|
|
310
|
-
* reset is a shortcut to anonymize users after they log out, by:
|
|
311
|
-
* - setting userId to `undefined`
|
|
312
|
-
* - regenerating a new random deviceId
|
|
313
|
-
*
|
|
314
|
-
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
315
|
-
*
|
|
316
|
-
* ```typescript
|
|
317
|
-
* reset();
|
|
318
|
-
* ```
|
|
319
|
-
*/
|
|
320
|
-
exports.reset = client.reset.bind(client);
|
|
321
|
-
/**
|
|
322
|
-
* Returns current session ID.
|
|
323
|
-
*
|
|
324
|
-
* ```typescript
|
|
325
|
-
* const sessionId = getSessionId();
|
|
326
|
-
* ```
|
|
327
|
-
*/
|
|
328
|
-
exports.getSessionId = client.getSessionId.bind(client);
|
|
329
|
-
/**
|
|
330
|
-
* Sets a new session ID.
|
|
331
|
-
* When settign a custom session ID, make sure the value is in milliseconds since epoch (Unix Timestamp).
|
|
332
|
-
*
|
|
333
|
-
* ```typescript
|
|
334
|
-
* setSessionId(Date.now());
|
|
335
|
-
* ```
|
|
336
|
-
*/
|
|
337
|
-
exports.setSessionId = client.setSessionId.bind(client);
|
|
338
|
-
/**
|
|
339
|
-
* Sets a new optOut config value. This toggles event tracking on/off.
|
|
340
|
-
*
|
|
341
|
-
*```typescript
|
|
342
|
-
* // Stops tracking
|
|
343
|
-
* setOptOut(true);
|
|
344
|
-
*
|
|
345
|
-
* // Starts/resumes tracking
|
|
346
|
-
* setOptOut(false);
|
|
347
|
-
* ```
|
|
348
|
-
*/
|
|
349
|
-
exports.setOptOut = client.setOptOut.bind(client);
|
|
350
|
-
/**
|
|
351
|
-
* Sets the network transport type for events.
|
|
352
|
-
*
|
|
353
|
-
* ```typescript
|
|
354
|
-
* // Use Fetch API
|
|
355
|
-
* setTransport('fetch');
|
|
356
|
-
*
|
|
357
|
-
* // Use XMLHttpRequest API
|
|
358
|
-
* setTransport('xhr');
|
|
359
|
-
*
|
|
360
|
-
* // Use navigator.sendBeacon API
|
|
361
|
-
* setTransport('beacon');
|
|
362
|
-
* ```
|
|
363
|
-
*/
|
|
364
|
-
exports.setTransport = client.setTransport.bind(client);
|
|
365
|
-
/**
|
|
366
|
-
* Flush and send all the events which haven't been sent.
|
|
367
|
-
*
|
|
368
|
-
*```typescript
|
|
369
|
-
* // Send all the unsent events
|
|
370
|
-
* flush();
|
|
371
|
-
*
|
|
372
|
-
* // alternatively, this tracking method is awaitable
|
|
373
|
-
* await flush().promise;
|
|
374
|
-
* ```
|
|
375
|
-
*/
|
|
376
|
-
exports.flush = (0, analytics_core_1.returnWrapper)(client.flush.bind(client));
|
|
179
|
+
var createInstance = function () {
|
|
180
|
+
var client = new AmplitudeBrowser();
|
|
181
|
+
return {
|
|
182
|
+
init: (0, analytics_core_1.returnWrapper)(client.init.bind(client)),
|
|
183
|
+
add: (0, analytics_core_1.returnWrapper)(client.add.bind(client)),
|
|
184
|
+
remove: (0, analytics_core_1.returnWrapper)(client.remove.bind(client)),
|
|
185
|
+
track: (0, analytics_core_1.returnWrapper)(client.track.bind(client)),
|
|
186
|
+
logEvent: (0, analytics_core_1.returnWrapper)(client.logEvent.bind(client)),
|
|
187
|
+
identify: (0, analytics_core_1.returnWrapper)(client.identify.bind(client)),
|
|
188
|
+
groupIdentify: (0, analytics_core_1.returnWrapper)(client.groupIdentify.bind(client)),
|
|
189
|
+
setGroup: (0, analytics_core_1.returnWrapper)(client.setGroup.bind(client)),
|
|
190
|
+
revenue: (0, analytics_core_1.returnWrapper)(client.revenue.bind(client)),
|
|
191
|
+
flush: (0, analytics_core_1.returnWrapper)(client.flush.bind(client)),
|
|
192
|
+
getUserId: client.getUserId.bind(client),
|
|
193
|
+
setUserId: client.setUserId.bind(client),
|
|
194
|
+
getDeviceId: client.getDeviceId.bind(client),
|
|
195
|
+
setDeviceId: client.setDeviceId.bind(client),
|
|
196
|
+
reset: client.reset.bind(client),
|
|
197
|
+
getSessionId: client.getSessionId.bind(client),
|
|
198
|
+
setSessionId: client.setSessionId.bind(client),
|
|
199
|
+
setOptOut: client.setOptOut.bind(client),
|
|
200
|
+
setTransport: client.setTransport.bind(client),
|
|
201
|
+
};
|
|
202
|
+
};
|
|
203
|
+
exports.createInstance = createInstance;
|
|
204
|
+
exports.default = (0, exports.createInstance)();
|
|
377
205
|
//# sourceMappingURL=browser-client.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser-client.js","sourceRoot":"","sources":["../../src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,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE/C;;;;;;GAMG;AACU,QAAA,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE7D;;;;;;;GAOG;AACU,QAAA,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE7D;;;;;;;;;;GAUG;AACU,QAAA,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAEvD;;;;;;;;;;;;;GAaG;AACU,QAAA,YAAY,GAAG,MAAM,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;AAE7D;;;;;;;;;;GAUG;AACU,QAAA,KAAK,GAAG,IAAA,8BAAa,EAAC,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.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AAC,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;AAvBW,QAAA,cAAc,kBAuBzB;AAEF,kBAAe,IAAA,sBAAc,GAAE,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/cjs/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/cjs/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,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;;;;;;;;;;;;CAwB5B,CAAC;AAEF,qBAAa,aAAc,SAAQ,MAAO,YAAW,cAAc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