@amplitude/analytics-react-native 0.1.1 → 0.2.2
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 +10 -0
- package/lib/commonjs/index.js +6 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/react-native-client.js +42 -20
- package/lib/commonjs/react-native-client.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/react-native-client.js +42 -20
- package/lib/module/react-native-client.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/index.d.ts +1 -1
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/react-native-client.d.ts +8 -7
- package/lib/typescript/react-native-client.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +4 -4
- package/src/index.ts +1 -0
- package/src/react-native-client.ts +32 -19
- package/src/version.ts +1 -1
package/README.md
CHANGED
|
@@ -148,3 +148,13 @@ track('Button Clicked').promise.then((result) => {
|
|
|
148
148
|
result.message; // "Event tracked successfully" (The response message)
|
|
149
149
|
});
|
|
150
150
|
```
|
|
151
|
+
|
|
152
|
+
### User Log out
|
|
153
|
+
|
|
154
|
+
This updates user ID and device ID. After calling `reset()` the succeeding events now belong to a new user identity.
|
|
155
|
+
|
|
156
|
+
```typescript
|
|
157
|
+
import { reset } from '@amplitude/analytics-react-native';
|
|
158
|
+
|
|
159
|
+
reset();
|
|
160
|
+
```
|
package/lib/commonjs/index.js
CHANGED
|
@@ -76,6 +76,12 @@ Object.defineProperty(exports, "remove", {
|
|
|
76
76
|
return _reactNativeClient.remove;
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
+
Object.defineProperty(exports, "reset", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () {
|
|
82
|
+
return _reactNativeClient.reset;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
79
85
|
Object.defineProperty(exports, "revenue", {
|
|
80
86
|
enumerable: true,
|
|
81
87
|
get: function () {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export {\n add,\n flush,\n getDeviceId,\n getSessionId,\n getUserId,\n groupIdentify,\n identify,\n init,\n logEvent,\n remove,\n revenue,\n setDeviceId,\n setGroup,\n setOptOut,\n setSessionId,\n setUserId,\n track,\n} from './react-native-client';\nexport { Revenue, Identify } from '@amplitude/analytics-core';\n// Hack - react-native apps have trouble with:\n// export * as Types from '@amplitude/analytics-types\nimport * as Types from '@amplitude/analytics-types';\nexport { Types };\n"],"mappings":"
|
|
1
|
+
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export {\n add,\n flush,\n getDeviceId,\n getSessionId,\n getUserId,\n groupIdentify,\n identify,\n init,\n logEvent,\n remove,\n reset,\n revenue,\n setDeviceId,\n setGroup,\n setOptOut,\n setSessionId,\n setUserId,\n track,\n} from './react-native-client';\nexport { Revenue, Identify } from '@amplitude/analytics-core';\n// Hack - react-native apps have trouble with:\n// export * as Types from '@amplitude/analytics-types\nimport * as Types from '@amplitude/analytics-types';\nexport { Types };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAoBA;;AAGA"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.track = exports.setUserId = exports.setSessionId = exports.setOptOut = exports.setGroup = exports.setDeviceId = exports.revenue = exports.
|
|
6
|
+
exports.track = exports.setUserId = exports.setSessionId = exports.setOptOut = exports.setGroup = exports.setDeviceId = exports.revenue = exports.reset = exports.remove = exports.logEvent = exports.init = exports.identify = exports.groupIdentify = exports.getUserId = exports.getSessionId = exports.getDeviceId = exports.flush = exports.add = exports.AmplitudeReactNative = void 0;
|
|
7
7
|
|
|
8
8
|
var _analyticsCore = require("@amplitude/analytics-core");
|
|
9
9
|
|
|
@@ -36,15 +36,18 @@ class AmplitudeReactNative extends _analyticsCore.AmplitudeCore {
|
|
|
36
36
|
});
|
|
37
37
|
await super._init(reactNativeOptions); // Step 3: Manage session
|
|
38
38
|
|
|
39
|
-
let isNewSession =
|
|
39
|
+
let isNewSession = !this.config.lastEventTime;
|
|
40
40
|
|
|
41
41
|
if (!this.config.sessionId || this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout) {
|
|
42
42
|
// Either
|
|
43
43
|
// 1) No previous session; or
|
|
44
44
|
// 2) Previous session expired
|
|
45
|
-
this.
|
|
45
|
+
this.setSessionId(Date.now());
|
|
46
46
|
isNewSession = true;
|
|
47
|
-
}
|
|
47
|
+
} // Set up the analytics connector to integrate with the experiment SDK.
|
|
48
|
+
// Send events from the experiment SDK and forward identifies to the
|
|
49
|
+
// identity store.
|
|
50
|
+
|
|
48
51
|
|
|
49
52
|
const connector = (0, _analyticsConnector.getAnalyticsConnector)();
|
|
50
53
|
connector.eventBridge.setEventReceiver(event => {
|
|
@@ -90,10 +93,17 @@ class AmplitudeReactNative extends _analyticsCore.AmplitudeCore {
|
|
|
90
93
|
}
|
|
91
94
|
|
|
92
95
|
getUserId() {
|
|
93
|
-
|
|
96
|
+
var _this$config;
|
|
97
|
+
|
|
98
|
+
return (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.userId;
|
|
94
99
|
}
|
|
95
100
|
|
|
96
101
|
setUserId(userId) {
|
|
102
|
+
if (!this.config) {
|
|
103
|
+
this.q.push(this.setUserId.bind(this, userId));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
97
107
|
this.config.userId = userId;
|
|
98
108
|
(0, _analyticsConnector.getAnalyticsConnector)().identityStore.editIdentity() // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
99
109
|
// @ts-ignore
|
|
@@ -101,31 +111,41 @@ class AmplitudeReactNative extends _analyticsCore.AmplitudeCore {
|
|
|
101
111
|
}
|
|
102
112
|
|
|
103
113
|
getDeviceId() {
|
|
104
|
-
|
|
114
|
+
var _this$config2;
|
|
115
|
+
|
|
116
|
+
return (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.deviceId;
|
|
105
117
|
}
|
|
106
118
|
|
|
107
119
|
setDeviceId(deviceId) {
|
|
120
|
+
if (!this.config) {
|
|
121
|
+
this.q.push(this.setDeviceId.bind(this, deviceId));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
108
125
|
this.config.deviceId = deviceId;
|
|
109
126
|
(0, _analyticsConnector.getAnalyticsConnector)().identityStore.editIdentity() // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
110
127
|
// @ts-ignore
|
|
111
128
|
.setDeviceId(deviceId).commit();
|
|
112
129
|
}
|
|
113
130
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
this.setDeviceId(
|
|
131
|
+
reset() {
|
|
132
|
+
this.setUserId(undefined);
|
|
133
|
+
this.setDeviceId((0, _analyticsCore.UUID)());
|
|
117
134
|
}
|
|
118
135
|
|
|
119
136
|
getSessionId() {
|
|
120
|
-
|
|
137
|
+
var _this$config3;
|
|
138
|
+
|
|
139
|
+
return (_this$config3 = this.config) === null || _this$config3 === void 0 ? void 0 : _this$config3.sessionId;
|
|
121
140
|
}
|
|
122
141
|
|
|
123
142
|
setSessionId(sessionId) {
|
|
124
|
-
this.config
|
|
125
|
-
|
|
143
|
+
if (!this.config) {
|
|
144
|
+
this.q.push(this.setSessionId.bind(this, sessionId));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
126
147
|
|
|
127
|
-
|
|
128
|
-
this.config.optOut = optOut;
|
|
148
|
+
this.config.sessionId = sessionId;
|
|
129
149
|
}
|
|
130
150
|
|
|
131
151
|
}
|
|
@@ -293,17 +313,19 @@ const getDeviceId = client.getDeviceId.bind(client);
|
|
|
293
313
|
exports.getDeviceId = getDeviceId;
|
|
294
314
|
const setDeviceId = client.setDeviceId.bind(client);
|
|
295
315
|
/**
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
316
|
+
* reset is a shortcut to anonymize users after they log out, by:
|
|
317
|
+
* - setting userId to `undefined`
|
|
318
|
+
* - regenerating a new random deviceId
|
|
319
|
+
*
|
|
320
|
+
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
299
321
|
*
|
|
300
322
|
* ```typescript
|
|
301
|
-
*
|
|
323
|
+
* reset();
|
|
302
324
|
* ```
|
|
303
325
|
*/
|
|
304
326
|
|
|
305
327
|
exports.setDeviceId = setDeviceId;
|
|
306
|
-
const
|
|
328
|
+
const reset = client.reset.bind(client);
|
|
307
329
|
/**
|
|
308
330
|
* Returns current session ID.
|
|
309
331
|
*
|
|
@@ -312,7 +334,7 @@ const regenerateDeviceId = client.regenerateDeviceId.bind(client);
|
|
|
312
334
|
* ```
|
|
313
335
|
*/
|
|
314
336
|
|
|
315
|
-
exports.
|
|
337
|
+
exports.reset = reset;
|
|
316
338
|
const getSessionId = client.getSessionId.bind(client);
|
|
317
339
|
/**
|
|
318
340
|
* Sets a new session ID.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AmplitudeReactNative","AmplitudeCore","init","apiKey","userId","options","oldCookies","parseOldCookies","reactNativeOptions","useReactNativeConfig","deviceId","sessionId","optOut","lastEventTime","_init","isNewSession","config","Date","now","sessionTimeout","connector","getAnalyticsConnector","eventBridge","setEventReceiver","event","track","eventType","eventProperties","identityStore","setIdentity","add","Context","IdentityEventSender","Destination","timeline","isReady","scheduleApply","runAttributionStrategy","attribution","attributionConfig","isNative","bind","onNewCampaign","setSessionId","storage","createFlexibleStorage","campaignTracker","CampaignTracker","send","getUserId","setUserId","editIdentity","commit","getDeviceId","setDeviceId","regenerateDeviceId","createDeviceId","getSessionId","setOptOut","client","returnWrapper","remove","logEvent","identify","groupIdentify","setGroup","revenue","flush"],"sources":["react-native-client.ts"],"sourcesContent":["import { AmplitudeCore, Destination, returnWrapper } from '@amplitude/analytics-core';\nimport {\n ReactNativeConfig,\n Campaign,\n ReactNativeOptions,\n AdditionalReactNativeOptions,\n AttributionReactNativeOptions,\n} from '@amplitude/analytics-types';\nimport { Context } from './plugins/context';\nimport { useReactNativeConfig, createDeviceId, createFlexibleStorage } from './config';\nimport { parseOldCookies } from './cookie-migration';\nimport { CampaignTracker } from './attribution/campaign-tracker';\nimport { isNative } from './utils/platform';\nimport { IdentityEventSender } from './plugins/identity';\nimport { getAnalyticsConnector } from './utils/analytics-connector';\n\nexport class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {\n async init(apiKey: string, userId?: string, options?: ReactNativeOptions & AdditionalReactNativeOptions) {\n // Step 1: Read cookies stored by old SDK\n const oldCookies = await parseOldCookies(apiKey, options);\n\n // Step 2: Create react native config\n const reactNativeOptions = await useReactNativeConfig(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(reactNativeOptions);\n\n // Step 3: Manage session\n let isNewSession = false;\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.config.sessionId = Date.now();\n isNewSession = true;\n }\n\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?: AttributionReactNativeOptions, isNewSession = false) {\n if (isNative()) {\n return;\n }\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 this.config.userId = userId;\n getAnalyticsConnector()\n .identityStore.editIdentity()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .setUserId(userId)\n .commit();\n }\n\n getDeviceId() {\n return this.config.deviceId;\n }\n\n setDeviceId(deviceId: string) {\n this.config.deviceId = deviceId;\n getAnalyticsConnector()\n .identityStore.editIdentity()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .setDeviceId(deviceId)\n .commit();\n }\n\n regenerateDeviceId() {\n const deviceId = createDeviceId();\n this.setDeviceId(deviceId);\n }\n\n getSessionId() {\n return this.config.sessionId;\n }\n\n setSessionId(sessionId: number) {\n this.config.sessionId = sessionId;\n }\n\n setOptOut(optOut: boolean) {\n this.config.optOut = optOut;\n }\n}\n\nconst client = new AmplitudeReactNative();\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 * Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you\n * are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.\n * With an `unefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.\n *\n * ```typescript\n * regenerateDeviceId();\n * ```\n */\nexport const regenerateDeviceId = client.regenerateDeviceId.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 * 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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;AACO,MAAMQ,KAAK,GAAG,IAAAP,4BAAA,EAAcD,MAAM,CAACQ,KAAP,CAAa1B,IAAb,CAAkBkB,MAAlB,CAAd,CAAd"}
|
|
1
|
+
{"version":3,"names":["AmplitudeReactNative","AmplitudeCore","init","apiKey","userId","options","oldCookies","parseOldCookies","reactNativeOptions","useReactNativeConfig","deviceId","sessionId","optOut","lastEventTime","_init","isNewSession","config","Date","now","sessionTimeout","setSessionId","connector","getAnalyticsConnector","eventBridge","setEventReceiver","event","track","eventType","eventProperties","identityStore","setIdentity","add","Context","IdentityEventSender","Destination","timeline","isReady","scheduleApply","runAttributionStrategy","attribution","attributionConfig","isNative","bind","onNewCampaign","storage","createFlexibleStorage","campaignTracker","CampaignTracker","send","getUserId","setUserId","q","push","editIdentity","commit","getDeviceId","setDeviceId","reset","undefined","UUID","getSessionId","client","returnWrapper","remove","logEvent","identify","groupIdentify","setGroup","revenue","setOptOut","flush"],"sources":["react-native-client.ts"],"sourcesContent":["import { AmplitudeCore, Destination, returnWrapper, UUID } from '@amplitude/analytics-core';\nimport {\n ReactNativeConfig,\n Campaign,\n ReactNativeOptions,\n AdditionalReactNativeOptions,\n AttributionReactNativeOptions,\n} from '@amplitude/analytics-types';\nimport { Context } from './plugins/context';\nimport { useReactNativeConfig, createFlexibleStorage } from './config';\nimport { parseOldCookies } from './cookie-migration';\nimport { CampaignTracker } from './attribution/campaign-tracker';\nimport { isNative } from './utils/platform';\nimport { IdentityEventSender } from './plugins/identity';\nimport { getAnalyticsConnector } from './utils/analytics-connector';\n\nexport class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {\n async init(apiKey: string, userId?: string, options?: ReactNativeOptions & AdditionalReactNativeOptions) {\n // Step 1: Read cookies stored by old SDK\n const oldCookies = await parseOldCookies(apiKey, options);\n\n // Step 2: Create react native config\n const reactNativeOptions = await useReactNativeConfig(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(reactNativeOptions);\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?: AttributionReactNativeOptions, isNewSession = false) {\n if (isNative()) {\n return;\n }\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 getAnalyticsConnector()\n .identityStore.editIdentity()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .setUserId(userId)\n .commit();\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 getAnalyticsConnector()\n .identityStore.editIdentity()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .setDeviceId(deviceId)\n .commit();\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 }\n}\n\nconst client = new AmplitudeReactNative();\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 * 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"],"mappings":";;;;;;;AAAA;;AAQA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEO,MAAMA,oBAAN,SAAmCC,4BAAnC,CAAoE;EAC/D,MAAJC,IAAI,CAACC,MAAD,EAAiBC,MAAjB,EAAkCC,OAAlC,EAA+F;IAAA;;IACvG;IACA,MAAMC,UAAU,GAAG,MAAM,IAAAC,gCAAA,EAAgBJ,MAAhB,EAAwBE,OAAxB,CAAzB,CAFuG,CAIvG;;IACA,MAAMG,kBAAkB,GAAG,MAAM,IAAAC,4BAAA,EAAqBN,MAArB,EAA6BC,MAAM,IAAIE,UAAU,CAACF,MAAlD,EAA0D,EACzF,GAAGC,OADsF;MAEzFK,QAAQ,0BAAEJ,UAAU,CAACI,QAAb,uEAAyBL,OAAzB,aAAyBA,OAAzB,uBAAyBA,OAAO,CAAEK,QAF+C;MAGzFC,SAAS,2BAAEL,UAAU,CAACK,SAAb,yEAA0BN,OAA1B,aAA0BA,OAA1B,uBAA0BA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;AACA;AACA;AACA;;;AACO,MAAMZ,SAAS,GAAGY,MAAM,CAACZ,SAAP,CAAiBP,IAAjB,CAAsBmB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMX,SAAS,GAAGW,MAAM,CAACX,SAAP,CAAiBR,IAAjB,CAAsBmB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMN,WAAW,GAAGM,MAAM,CAACN,WAAP,CAAmBb,IAAnB,CAAwBmB,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAML,WAAW,GAAGK,MAAM,CAACL,WAAP,CAAmBd,IAAnB,CAAwBmB,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMJ,KAAK,GAAGI,MAAM,CAACJ,KAAP,CAAaf,IAAb,CAAkBmB,MAAlB,CAAd;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMD,YAAY,GAAGC,MAAM,CAACD,YAAP,CAAoBlB,IAApB,CAAyBmB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMzC,YAAY,GAAGyC,MAAM,CAACzC,YAAP,CAAoBsB,IAApB,CAAyBmB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMQ,SAAS,GAAGR,MAAM,CAACQ,SAAP,CAAiB3B,IAAjB,CAAsBmB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMS,KAAK,GAAG,IAAAR,4BAAA,EAAcD,MAAM,CAACS,KAAP,CAAa5B,IAAb,CAAkBmB,MAAlB,CAAd,CAAd"}
|
package/lib/commonjs/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.
|
|
1
|
+
{"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.2.2';\n"],"mappings":";;;;;;AAAO,MAAMA,OAAO,GAAG,OAAhB"}
|
package/lib/module/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { add, flush, getDeviceId, getSessionId, getUserId, groupIdentify, identify, init, logEvent, remove, revenue, setDeviceId, setGroup, setOptOut, setSessionId, setUserId, track } from './react-native-client';
|
|
1
|
+
export { add, flush, getDeviceId, getSessionId, getUserId, groupIdentify, identify, init, logEvent, remove, reset, revenue, setDeviceId, setGroup, setOptOut, setSessionId, setUserId, track } from './react-native-client';
|
|
2
2
|
export { Revenue, Identify } from '@amplitude/analytics-core'; // Hack - react-native apps have trouble with:
|
|
3
3
|
// export * as Types from '@amplitude/analytics-types
|
|
4
4
|
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["add","flush","getDeviceId","getSessionId","getUserId","groupIdentify","identify","init","logEvent","remove","revenue","setDeviceId","setGroup","setOptOut","setSessionId","setUserId","track","Revenue","Identify","Types"],"sources":["index.ts"],"sourcesContent":["export {\n add,\n flush,\n getDeviceId,\n getSessionId,\n getUserId,\n groupIdentify,\n identify,\n init,\n logEvent,\n remove,\n revenue,\n setDeviceId,\n setGroup,\n setOptOut,\n setSessionId,\n setUserId,\n track,\n} from './react-native-client';\nexport { Revenue, Identify } from '@amplitude/analytics-core';\n// Hack - react-native apps have trouble with:\n// export * as Types from '@amplitude/analytics-types\nimport * as Types from '@amplitude/analytics-types';\nexport { Types };\n"],"mappings":"AAAA,SACEA,GADF,EAEEC,KAFF,EAGEC,WAHF,EAIEC,YAJF,EAKEC,SALF,EAMEC,aANF,EAOEC,QAPF,EAQEC,IARF,EASEC,QATF,EAUEC,MAVF,EAWEC,
|
|
1
|
+
{"version":3,"names":["add","flush","getDeviceId","getSessionId","getUserId","groupIdentify","identify","init","logEvent","remove","reset","revenue","setDeviceId","setGroup","setOptOut","setSessionId","setUserId","track","Revenue","Identify","Types"],"sources":["index.ts"],"sourcesContent":["export {\n add,\n flush,\n getDeviceId,\n getSessionId,\n getUserId,\n groupIdentify,\n identify,\n init,\n logEvent,\n remove,\n reset,\n revenue,\n setDeviceId,\n setGroup,\n setOptOut,\n setSessionId,\n setUserId,\n track,\n} from './react-native-client';\nexport { Revenue, Identify } from '@amplitude/analytics-core';\n// Hack - react-native apps have trouble with:\n// export * as Types from '@amplitude/analytics-types\nimport * as Types from '@amplitude/analytics-types';\nexport { Types };\n"],"mappings":"AAAA,SACEA,GADF,EAEEC,KAFF,EAGEC,WAHF,EAIEC,YAJF,EAKEC,SALF,EAMEC,aANF,EAOEC,QAPF,EAQEC,IARF,EASEC,QATF,EAUEC,MAVF,EAWEC,KAXF,EAYEC,OAZF,EAaEC,WAbF,EAcEC,QAdF,EAeEC,SAfF,EAgBEC,YAhBF,EAiBEC,SAjBF,EAkBEC,KAlBF,QAmBO,uBAnBP;AAoBA,SAASC,OAAT,EAAkBC,QAAlB,QAAkC,2BAAlC,C,CACA;AACA;;AACA,OAAO,KAAKC,KAAZ,MAAuB,4BAAvB;AACA,SAASA,KAAT"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { AmplitudeCore, Destination, returnWrapper } from '@amplitude/analytics-core';
|
|
1
|
+
import { AmplitudeCore, Destination, returnWrapper, UUID } from '@amplitude/analytics-core';
|
|
2
2
|
import { Context } from './plugins/context';
|
|
3
|
-
import { useReactNativeConfig,
|
|
3
|
+
import { useReactNativeConfig, createFlexibleStorage } from './config';
|
|
4
4
|
import { parseOldCookies } from './cookie-migration';
|
|
5
5
|
import { CampaignTracker } from './attribution/campaign-tracker';
|
|
6
6
|
import { isNative } from './utils/platform';
|
|
@@ -21,15 +21,18 @@ export class AmplitudeReactNative extends AmplitudeCore {
|
|
|
21
21
|
});
|
|
22
22
|
await super._init(reactNativeOptions); // Step 3: Manage session
|
|
23
23
|
|
|
24
|
-
let isNewSession =
|
|
24
|
+
let isNewSession = !this.config.lastEventTime;
|
|
25
25
|
|
|
26
26
|
if (!this.config.sessionId || this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout) {
|
|
27
27
|
// Either
|
|
28
28
|
// 1) No previous session; or
|
|
29
29
|
// 2) Previous session expired
|
|
30
|
-
this.
|
|
30
|
+
this.setSessionId(Date.now());
|
|
31
31
|
isNewSession = true;
|
|
32
|
-
}
|
|
32
|
+
} // Set up the analytics connector to integrate with the experiment SDK.
|
|
33
|
+
// Send events from the experiment SDK and forward identifies to the
|
|
34
|
+
// identity store.
|
|
35
|
+
|
|
33
36
|
|
|
34
37
|
const connector = getAnalyticsConnector();
|
|
35
38
|
connector.eventBridge.setEventReceiver(event => {
|
|
@@ -75,10 +78,17 @@ export class AmplitudeReactNative extends AmplitudeCore {
|
|
|
75
78
|
}
|
|
76
79
|
|
|
77
80
|
getUserId() {
|
|
78
|
-
|
|
81
|
+
var _this$config;
|
|
82
|
+
|
|
83
|
+
return (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.userId;
|
|
79
84
|
}
|
|
80
85
|
|
|
81
86
|
setUserId(userId) {
|
|
87
|
+
if (!this.config) {
|
|
88
|
+
this.q.push(this.setUserId.bind(this, userId));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
82
92
|
this.config.userId = userId;
|
|
83
93
|
getAnalyticsConnector().identityStore.editIdentity() // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
84
94
|
// @ts-ignore
|
|
@@ -86,31 +96,41 @@ export class AmplitudeReactNative extends AmplitudeCore {
|
|
|
86
96
|
}
|
|
87
97
|
|
|
88
98
|
getDeviceId() {
|
|
89
|
-
|
|
99
|
+
var _this$config2;
|
|
100
|
+
|
|
101
|
+
return (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.deviceId;
|
|
90
102
|
}
|
|
91
103
|
|
|
92
104
|
setDeviceId(deviceId) {
|
|
105
|
+
if (!this.config) {
|
|
106
|
+
this.q.push(this.setDeviceId.bind(this, deviceId));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
93
110
|
this.config.deviceId = deviceId;
|
|
94
111
|
getAnalyticsConnector().identityStore.editIdentity() // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
95
112
|
// @ts-ignore
|
|
96
113
|
.setDeviceId(deviceId).commit();
|
|
97
114
|
}
|
|
98
115
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
this.setDeviceId(
|
|
116
|
+
reset() {
|
|
117
|
+
this.setUserId(undefined);
|
|
118
|
+
this.setDeviceId(UUID());
|
|
102
119
|
}
|
|
103
120
|
|
|
104
121
|
getSessionId() {
|
|
105
|
-
|
|
122
|
+
var _this$config3;
|
|
123
|
+
|
|
124
|
+
return (_this$config3 = this.config) === null || _this$config3 === void 0 ? void 0 : _this$config3.sessionId;
|
|
106
125
|
}
|
|
107
126
|
|
|
108
127
|
setSessionId(sessionId) {
|
|
109
|
-
this.config
|
|
110
|
-
|
|
128
|
+
if (!this.config) {
|
|
129
|
+
this.q.push(this.setSessionId.bind(this, sessionId));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
111
132
|
|
|
112
|
-
|
|
113
|
-
this.config.optOut = optOut;
|
|
133
|
+
this.config.sessionId = sessionId;
|
|
114
134
|
}
|
|
115
135
|
|
|
116
136
|
}
|
|
@@ -264,16 +284,18 @@ export const getDeviceId = client.getDeviceId.bind(client);
|
|
|
264
284
|
|
|
265
285
|
export const setDeviceId = client.setDeviceId.bind(client);
|
|
266
286
|
/**
|
|
267
|
-
*
|
|
268
|
-
*
|
|
269
|
-
*
|
|
287
|
+
* reset is a shortcut to anonymize users after they log out, by:
|
|
288
|
+
* - setting userId to `undefined`
|
|
289
|
+
* - regenerating a new random deviceId
|
|
290
|
+
*
|
|
291
|
+
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
270
292
|
*
|
|
271
293
|
* ```typescript
|
|
272
|
-
*
|
|
294
|
+
* reset();
|
|
273
295
|
* ```
|
|
274
296
|
*/
|
|
275
297
|
|
|
276
|
-
export const
|
|
298
|
+
export const reset = client.reset.bind(client);
|
|
277
299
|
/**
|
|
278
300
|
* Returns current session ID.
|
|
279
301
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["AmplitudeCore","Destination","returnWrapper","Context","useReactNativeConfig","createDeviceId","createFlexibleStorage","parseOldCookies","CampaignTracker","isNative","IdentityEventSender","getAnalyticsConnector","AmplitudeReactNative","init","apiKey","userId","options","oldCookies","reactNativeOptions","deviceId","sessionId","optOut","lastEventTime","_init","isNewSession","config","Date","now","sessionTimeout","connector","eventBridge","setEventReceiver","event","track","eventType","eventProperties","identityStore","setIdentity","add","timeline","isReady","scheduleApply","runAttributionStrategy","attribution","attributionConfig","bind","onNewCampaign","setSessionId","storage","campaignTracker","send","getUserId","setUserId","editIdentity","commit","getDeviceId","setDeviceId","regenerateDeviceId","getSessionId","setOptOut","client","remove","logEvent","identify","groupIdentify","setGroup","revenue","flush"],"sources":["react-native-client.ts"],"sourcesContent":["import { AmplitudeCore, Destination, returnWrapper } from '@amplitude/analytics-core';\nimport {\n ReactNativeConfig,\n Campaign,\n ReactNativeOptions,\n AdditionalReactNativeOptions,\n AttributionReactNativeOptions,\n} from '@amplitude/analytics-types';\nimport { Context } from './plugins/context';\nimport { useReactNativeConfig, createDeviceId, createFlexibleStorage } from './config';\nimport { parseOldCookies } from './cookie-migration';\nimport { CampaignTracker } from './attribution/campaign-tracker';\nimport { isNative } from './utils/platform';\nimport { IdentityEventSender } from './plugins/identity';\nimport { getAnalyticsConnector } from './utils/analytics-connector';\n\nexport class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {\n async init(apiKey: string, userId?: string, options?: ReactNativeOptions & AdditionalReactNativeOptions) {\n // Step 1: Read cookies stored by old SDK\n const oldCookies = await parseOldCookies(apiKey, options);\n\n // Step 2: Create react native config\n const reactNativeOptions = await useReactNativeConfig(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(reactNativeOptions);\n\n // Step 3: Manage session\n let isNewSession = false;\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.config.sessionId = Date.now();\n isNewSession = true;\n }\n\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?: AttributionReactNativeOptions, isNewSession = false) {\n if (isNative()) {\n return;\n }\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 this.config.userId = userId;\n getAnalyticsConnector()\n .identityStore.editIdentity()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .setUserId(userId)\n .commit();\n }\n\n getDeviceId() {\n return this.config.deviceId;\n }\n\n setDeviceId(deviceId: string) {\n this.config.deviceId = deviceId;\n getAnalyticsConnector()\n .identityStore.editIdentity()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .setDeviceId(deviceId)\n .commit();\n }\n\n regenerateDeviceId() {\n const deviceId = createDeviceId();\n this.setDeviceId(deviceId);\n }\n\n getSessionId() {\n return this.config.sessionId;\n }\n\n setSessionId(sessionId: number) {\n this.config.sessionId = sessionId;\n }\n\n setOptOut(optOut: boolean) {\n this.config.optOut = optOut;\n }\n}\n\nconst client = new AmplitudeReactNative();\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 * Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you\n * are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.\n * With an `unefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.\n *\n * ```typescript\n * regenerateDeviceId();\n * ```\n */\nexport const regenerateDeviceId = client.regenerateDeviceId.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 * 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"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,WAAxB,EAAqCC,aAArC,QAA0D,2BAA1D;AAQA,SAASC,OAAT,QAAwB,mBAAxB;AACA,SAASC,oBAAT,EAA+BC,cAA/B,EAA+CC,qBAA/C,QAA4E,UAA5E;AACA,SAASC,eAAT,QAAgC,oBAAhC;AACA,SAASC,eAAT,QAAgC,gCAAhC;AACA,SAASC,QAAT,QAAyB,kBAAzB;AACA,SAASC,mBAAT,QAAoC,oBAApC;AACA,SAASC,qBAAT,QAAsC,6BAAtC;AAEA,OAAO,MAAMC,oBAAN,SAAmCZ,aAAnC,CAAoE;EAC/D,MAAJa,IAAI,CAACC,MAAD,EAAiBC,MAAjB,EAAkCC,OAAlC,EAA+F;IAAA;;IACvG;IACA,MAAMC,UAAU,GAAG,MAAMV,eAAe,CAACO,MAAD,EAASE,OAAT,CAAxC,CAFuG,CAIvG;;IACA,MAAME,kBAAkB,GAAG,MAAMd,oB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EP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAML,WAAW,GAAGK,MAAM,CAACL,WAAP,CAAmBV,IAAnB,CAAwBe,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMJ,WAAW,GAAGI,MAAM,CAACJ,WAAP,CAAmBX,IAAnB,CAAwBe,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMH,kBAAkB,GAAGG,MAAM,CAACH,kBAAP,CAA0BZ,IAA1B,CAA+Be,MAA/B,CAA3B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMF,YAAY,GAAGE,MAAM,CAACF,YAAP,CAAoBb,IAApB,CAAyBe,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMb,YAAY,GAAGa,MAAM,CAACb,YAAP,CAAoBF,IAApB,CAAyBe,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMD,SAAS,GAAGC,MAAM,CAACD,SAAP,CAAiBd,IAAjB,CAAsBe,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMO,KAAK,GAAGjE,aAAa,CAAC0D,MAAM,CAACO,KAAP,CAAatB,IAAb,CAAkBe,MAAlB,CAAD,CAA3B"}
|
|
1
|
+
{"version":3,"names":["AmplitudeCore","Destination","returnWrapper","UUID","Context","useReactNativeConfig","createFlexibleStorage","parseOldCookies","CampaignTracker","isNative","IdentityEventSender","getAnalyticsConnector","AmplitudeReactNative","init","apiKey","userId","options","oldCookies","reactNativeOptions","deviceId","sessionId","optOut","lastEventTime","_init","isNewSession","config","Date","now","sessionTimeout","setSessionId","connector","eventBridge","setEventReceiver","event","track","eventType","eventProperties","identityStore","setIdentity","add","timeline","isReady","scheduleApply","runAttributionStrategy","attribution","attributionConfig","bind","onNewCampaign","storage","campaignTracker","send","getUserId","setUserId","q","push","editIdentity","commit","getDeviceId","setDeviceId","reset","undefined","getSessionId","client","remove","logEvent","identify","groupIdentify","setGroup","revenue","setOptOut","flush"],"sources":["react-native-client.ts"],"sourcesContent":["import { AmplitudeCore, Destination, returnWrapper, UUID } from '@amplitude/analytics-core';\nimport {\n ReactNativeConfig,\n Campaign,\n ReactNativeOptions,\n AdditionalReactNativeOptions,\n AttributionReactNativeOptions,\n} from '@amplitude/analytics-types';\nimport { Context } from './plugins/context';\nimport { useReactNativeConfig, createFlexibleStorage } from './config';\nimport { parseOldCookies } from './cookie-migration';\nimport { CampaignTracker } from './attribution/campaign-tracker';\nimport { isNative } from './utils/platform';\nimport { IdentityEventSender } from './plugins/identity';\nimport { getAnalyticsConnector } from './utils/analytics-connector';\n\nexport class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {\n async init(apiKey: string, userId?: string, options?: ReactNativeOptions & AdditionalReactNativeOptions) {\n // Step 1: Read cookies stored by old SDK\n const oldCookies = await parseOldCookies(apiKey, options);\n\n // Step 2: Create react native config\n const reactNativeOptions = await useReactNativeConfig(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(reactNativeOptions);\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?: AttributionReactNativeOptions, isNewSession = false) {\n if (isNative()) {\n return;\n }\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 getAnalyticsConnector()\n .identityStore.editIdentity()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .setUserId(userId)\n .commit();\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 getAnalyticsConnector()\n .identityStore.editIdentity()\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n .setDeviceId(deviceId)\n .commit();\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 }\n}\n\nconst client = new AmplitudeReactNative();\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 * 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"],"mappings":"AAAA,SAASA,aAAT,EAAwBC,WAAxB,EAAqCC,aAArC,EAAoDC,IAApD,QAAgE,2BAAhE;AAQA,SAASC,OAAT,QAAwB,mBAAxB;AACA,SAASC,oBAAT,EAA+BC,qBAA/B,QAA4D,UAA5D;AACA,SAASC,eAAT,QAAgC,oBAAhC;AACA,SAASC,eAAT,QAAgC,gCAAhC;AACA,SAASC,QAAT,QAAyB,kBAAzB;AACA,SAASC,mBAAT,QAAoC,oBAApC;AACA,SAASC,qBAAT,QAAsC,6BAAtC;AAEA,OAAO,MAAMC,oBAAN,SAAmCZ,aAAnC,CAAoE;EAC/D,MAAJa,IAAI,CAACC,MAAD,EAAiBC,MAAjB,EAAkCC,OAAlC,EAA+F;IAAA;;IACvG;IACA,MAAMC,UAAU,GAAG,MAAMV,eAAe,CAACO,MAAD,EAASE,OAAT,CAAxC,CAFuG,CAIvG;;IACA,MAAME,kBAAkB,GAAG,MAAMb,oBAAoB,CAACS,MAAD,EAASC,MAAM,IAAIE,UAAU,CAACF,MAA9B,EAAsC,EACzF,GAAGC,OADsF;MAEzFG,QAAQ,0BAAEF,UAAU,CAACE,QAAb,uEAAyBH,OAAzB,aAAyBA,OAAzB,uBAAyBA,OAAO,CAAEG,QAF+C;MAGzFC,SAAS,2BAAEH,UAAU,CAACG,SAAb,yEAA0BJ,OAA1B,aAA0BA,OAA1B,uBAA0BA,OAAO,CAAEI,SAH6C;MAIzFC,MAAM,qBAAEL,OAAF,aAAEA,OAAF,uBAAEA,OAAO,CAAEK,MAAX,6DAAqBJ,UAAU,CAACI,MAJmD;MAKzFC,aAAa,EAAEL,UAAU,C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AP,CAAiBN,IAAjB,CAAsBgB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAML,WAAW,GAAGK,MAAM,CAACL,WAAP,CAAmBX,IAAnB,CAAwBgB,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMJ,WAAW,GAAGI,MAAM,CAACJ,WAAP,CAAmBZ,IAAnB,CAAwBgB,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMH,KAAK,GAAGG,MAAM,CAACH,KAAP,CAAab,IAAb,CAAkBgB,MAAlB,CAAd;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMD,YAAY,GAAGC,MAAM,CAACD,YAAP,CAAoBf,IAApB,CAAyBgB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMjC,YAAY,GAAGiC,MAAM,CAACjC,YAAP,CAAoBiB,IAApB,CAAyBgB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMO,SAAS,GAAGP,MAAM,CAACO,SAAP,CAAiBvB,IAAjB,CAAsBgB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMQ,KAAK,GAAGpE,aAAa,CAAC4D,MAAM,CAACQ,KAAP,CAAaxB,IAAb,CAAkBgB,MAAlB,CAAD,CAA3B"}
|
package/lib/module/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.2.2';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.
|
|
1
|
+
{"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.2.2';\n"],"mappings":"AAAA,OAAO,MAAMA,OAAO,GAAG,OAAhB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { add, flush, getDeviceId, getSessionId, getUserId, groupIdentify, identify, init, logEvent, remove, revenue, setDeviceId, setGroup, setOptOut, setSessionId, setUserId, track, } from './react-native-client';
|
|
1
|
+
export { add, flush, getDeviceId, getSessionId, getUserId, groupIdentify, identify, init, logEvent, remove, reset, revenue, setDeviceId, setGroup, setOptOut, setSessionId, setUserId, track, } from './react-native-client';
|
|
2
2
|
export { Revenue, Identify } from '@amplitude/analytics-core';
|
|
3
3
|
import * as Types from '@amplitude/analytics-types';
|
|
4
4
|
export { Types };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,KAAK,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,OAAO,EACP,WAAW,EACX,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,SAAS,EACT,KAAK,GACN,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,GAAG,EACH,KAAK,EACL,WAAW,EACX,YAAY,EACZ,SAAS,EACT,aAAa,EACb,QAAQ,EACR,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,KAAK,EACL,OAAO,EACP,WAAW,EACX,QAAQ,EACR,SAAS,EACT,YAAY,EACZ,SAAS,EACT,KAAK,GACN,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAG9D,OAAO,KAAK,KAAK,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAE,KAAK,EAAE,CAAC"}
|
|
@@ -7,10 +7,9 @@ export declare class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfi
|
|
|
7
7
|
setUserId(userId: string | undefined): void;
|
|
8
8
|
getDeviceId(): string | undefined;
|
|
9
9
|
setDeviceId(deviceId: string): void;
|
|
10
|
-
|
|
10
|
+
reset(): void;
|
|
11
11
|
getSessionId(): number | undefined;
|
|
12
12
|
setSessionId(sessionId: number): void;
|
|
13
|
-
setOptOut(optOut: boolean): void;
|
|
14
13
|
}
|
|
15
14
|
/**
|
|
16
15
|
* Initializes the Amplitude SDK with your apiKey, userId and optional configurations.
|
|
@@ -149,15 +148,17 @@ export declare const getDeviceId: () => string | undefined;
|
|
|
149
148
|
*/
|
|
150
149
|
export declare const setDeviceId: (deviceId: string) => void;
|
|
151
150
|
/**
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
*
|
|
151
|
+
* reset is a shortcut to anonymize users after they log out, by:
|
|
152
|
+
* - setting userId to `undefined`
|
|
153
|
+
* - regenerating a new random deviceId
|
|
154
|
+
*
|
|
155
|
+
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
155
156
|
*
|
|
156
157
|
* ```typescript
|
|
157
|
-
*
|
|
158
|
+
* reset();
|
|
158
159
|
* ```
|
|
159
160
|
*/
|
|
160
|
-
export declare const
|
|
161
|
+
export declare const reset: () => void;
|
|
161
162
|
/**
|
|
162
163
|
* Returns current session ID.
|
|
163
164
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-native-client.d.ts","sourceRoot":"","sources":["../../src/react-native-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa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M,SAAS,0BAAgC,CAAC;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,SAAS,WAlLF,MAAM,GAAG,SAAS,SAkLgB,CAAC;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,0BAAkC,CAAC;AAE3D;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,aApLA,MAAM,SAoL4B,CAAC;AAE3D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,YAA4B,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,0BAAmC,CAAC;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,cA7LC,MAAM,SA6L4B,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,2BAAgC,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,2EAA2C,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "0.
|
|
1
|
+
export declare const VERSION = "0.2.2";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Official React Native SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analytics",
|
|
@@ -57,8 +57,8 @@
|
|
|
57
57
|
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@amplitude/analytics-connector": "1.4.
|
|
61
|
-
"@amplitude/analytics-core": "^0.6.
|
|
60
|
+
"@amplitude/analytics-connector": "1.4.5",
|
|
61
|
+
"@amplitude/analytics-core": "^0.6.5",
|
|
62
62
|
"@amplitude/analytics-types": "^0.6.1",
|
|
63
63
|
"@amplitude/ua-parser-js": "^0.7.31",
|
|
64
64
|
"@react-native-async-storage/async-storage": "^1.17.7",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
]
|
|
90
90
|
]
|
|
91
91
|
},
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "196d18de7dd7a3e855073cc01880498e6190b739"
|
|
93
93
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AmplitudeCore, Destination, returnWrapper } from '@amplitude/analytics-core';
|
|
1
|
+
import { AmplitudeCore, Destination, returnWrapper, UUID } from '@amplitude/analytics-core';
|
|
2
2
|
import {
|
|
3
3
|
ReactNativeConfig,
|
|
4
4
|
Campaign,
|
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
AttributionReactNativeOptions,
|
|
8
8
|
} from '@amplitude/analytics-types';
|
|
9
9
|
import { Context } from './plugins/context';
|
|
10
|
-
import { useReactNativeConfig,
|
|
10
|
+
import { useReactNativeConfig, createFlexibleStorage } from './config';
|
|
11
11
|
import { parseOldCookies } from './cookie-migration';
|
|
12
12
|
import { CampaignTracker } from './attribution/campaign-tracker';
|
|
13
13
|
import { isNative } from './utils/platform';
|
|
@@ -30,7 +30,7 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
30
30
|
await super._init(reactNativeOptions);
|
|
31
31
|
|
|
32
32
|
// Step 3: Manage session
|
|
33
|
-
let isNewSession =
|
|
33
|
+
let isNewSession = !this.config.lastEventTime;
|
|
34
34
|
if (
|
|
35
35
|
!this.config.sessionId ||
|
|
36
36
|
(this.config.lastEventTime && Date.now() - this.config.lastEventTime > this.config.sessionTimeout)
|
|
@@ -38,10 +38,13 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
38
38
|
// Either
|
|
39
39
|
// 1) No previous session; or
|
|
40
40
|
// 2) Previous session expired
|
|
41
|
-
this.
|
|
41
|
+
this.setSessionId(Date.now());
|
|
42
42
|
isNewSession = true;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
|
+
// Set up the analytics connector to integrate with the experiment SDK.
|
|
46
|
+
// Send events from the experiment SDK and forward identifies to the
|
|
47
|
+
// identity store.
|
|
45
48
|
const connector = getAnalyticsConnector();
|
|
46
49
|
connector.eventBridge.setEventReceiver((event) => {
|
|
47
50
|
void this.track(event.eventType, event.eventProperties);
|
|
@@ -87,10 +90,14 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
87
90
|
}
|
|
88
91
|
|
|
89
92
|
getUserId() {
|
|
90
|
-
return this.config
|
|
93
|
+
return this.config?.userId;
|
|
91
94
|
}
|
|
92
95
|
|
|
93
96
|
setUserId(userId: string | undefined) {
|
|
97
|
+
if (!this.config) {
|
|
98
|
+
this.q.push(this.setUserId.bind(this, userId));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
94
101
|
this.config.userId = userId;
|
|
95
102
|
getAnalyticsConnector()
|
|
96
103
|
.identityStore.editIdentity()
|
|
@@ -101,10 +108,14 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
101
108
|
}
|
|
102
109
|
|
|
103
110
|
getDeviceId() {
|
|
104
|
-
return this.config
|
|
111
|
+
return this.config?.deviceId;
|
|
105
112
|
}
|
|
106
113
|
|
|
107
114
|
setDeviceId(deviceId: string) {
|
|
115
|
+
if (!this.config) {
|
|
116
|
+
this.q.push(this.setDeviceId.bind(this, deviceId));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
108
119
|
this.config.deviceId = deviceId;
|
|
109
120
|
getAnalyticsConnector()
|
|
110
121
|
.identityStore.editIdentity()
|
|
@@ -114,22 +125,22 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
114
125
|
.commit();
|
|
115
126
|
}
|
|
116
127
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
this.setDeviceId(
|
|
128
|
+
reset() {
|
|
129
|
+
this.setUserId(undefined);
|
|
130
|
+
this.setDeviceId(UUID());
|
|
120
131
|
}
|
|
121
132
|
|
|
122
133
|
getSessionId() {
|
|
123
|
-
return this.config
|
|
134
|
+
return this.config?.sessionId;
|
|
124
135
|
}
|
|
125
136
|
|
|
126
137
|
setSessionId(sessionId: number) {
|
|
138
|
+
if (!this.config) {
|
|
139
|
+
this.q.push(this.setSessionId.bind(this, sessionId));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
127
142
|
this.config.sessionId = sessionId;
|
|
128
143
|
}
|
|
129
|
-
|
|
130
|
-
setOptOut(optOut: boolean) {
|
|
131
|
-
this.config.optOut = optOut;
|
|
132
|
-
}
|
|
133
144
|
}
|
|
134
145
|
|
|
135
146
|
const client = new AmplitudeReactNative();
|
|
@@ -283,15 +294,17 @@ export const getDeviceId = client.getDeviceId.bind(client);
|
|
|
283
294
|
export const setDeviceId = client.setDeviceId.bind(client);
|
|
284
295
|
|
|
285
296
|
/**
|
|
286
|
-
*
|
|
287
|
-
*
|
|
288
|
-
*
|
|
297
|
+
* reset is a shortcut to anonymize users after they log out, by:
|
|
298
|
+
* - setting userId to `undefined`
|
|
299
|
+
* - regenerating a new random deviceId
|
|
300
|
+
*
|
|
301
|
+
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
289
302
|
*
|
|
290
303
|
* ```typescript
|
|
291
|
-
*
|
|
304
|
+
* reset();
|
|
292
305
|
* ```
|
|
293
306
|
*/
|
|
294
|
-
export const
|
|
307
|
+
export const reset = client.reset.bind(client);
|
|
295
308
|
|
|
296
309
|
/**
|
|
297
310
|
* Returns current session ID.
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.
|
|
1
|
+
export const VERSION = '0.2.2';
|