@amplitude/analytics-react-native 0.2.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/react-native-client.js +29 -29
- 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/react-native-client.js +29 -28
- 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/react-native-client.d.ts +0 -12
- package/lib/typescript/react-native-client.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +3 -3
- package/src/react-native-client.ts +20 -28
- 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
|
+
```
|
|
@@ -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.reset = exports.remove = 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,13 +36,13 @@ 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
48
|
// Send events from the experiment SDK and forward identifies to the
|
|
@@ -93,10 +93,17 @@ class AmplitudeReactNative extends _analyticsCore.AmplitudeCore {
|
|
|
93
93
|
}
|
|
94
94
|
|
|
95
95
|
getUserId() {
|
|
96
|
-
|
|
96
|
+
var _this$config;
|
|
97
|
+
|
|
98
|
+
return (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.userId;
|
|
97
99
|
}
|
|
98
100
|
|
|
99
101
|
setUserId(userId) {
|
|
102
|
+
if (!this.config) {
|
|
103
|
+
this.q.push(this.setUserId.bind(this, userId));
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
|
|
100
107
|
this.config.userId = userId;
|
|
101
108
|
(0, _analyticsConnector.getAnalyticsConnector)().identityStore.editIdentity() // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
102
109
|
// @ts-ignore
|
|
@@ -104,36 +111,41 @@ class AmplitudeReactNative extends _analyticsCore.AmplitudeCore {
|
|
|
104
111
|
}
|
|
105
112
|
|
|
106
113
|
getDeviceId() {
|
|
107
|
-
|
|
114
|
+
var _this$config2;
|
|
115
|
+
|
|
116
|
+
return (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.deviceId;
|
|
108
117
|
}
|
|
109
118
|
|
|
110
119
|
setDeviceId(deviceId) {
|
|
120
|
+
if (!this.config) {
|
|
121
|
+
this.q.push(this.setDeviceId.bind(this, deviceId));
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
111
125
|
this.config.deviceId = deviceId;
|
|
112
126
|
(0, _analyticsConnector.getAnalyticsConnector)().identityStore.editIdentity() // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
113
127
|
// @ts-ignore
|
|
114
128
|
.setDeviceId(deviceId).commit();
|
|
115
129
|
}
|
|
116
130
|
|
|
117
|
-
regenerateDeviceId() {
|
|
118
|
-
const deviceId = (0, _config.createDeviceId)();
|
|
119
|
-
this.setDeviceId(deviceId);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
131
|
reset() {
|
|
123
132
|
this.setUserId(undefined);
|
|
124
|
-
this.
|
|
133
|
+
this.setDeviceId((0, _analyticsCore.UUID)());
|
|
125
134
|
}
|
|
126
135
|
|
|
127
136
|
getSessionId() {
|
|
128
|
-
|
|
137
|
+
var _this$config3;
|
|
138
|
+
|
|
139
|
+
return (_this$config3 = this.config) === null || _this$config3 === void 0 ? void 0 : _this$config3.sessionId;
|
|
129
140
|
}
|
|
130
141
|
|
|
131
142
|
setSessionId(sessionId) {
|
|
132
|
-
this.config
|
|
133
|
-
|
|
143
|
+
if (!this.config) {
|
|
144
|
+
this.q.push(this.setSessionId.bind(this, sessionId));
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
134
147
|
|
|
135
|
-
|
|
136
|
-
this.config.optOut = optOut;
|
|
148
|
+
this.config.sessionId = sessionId;
|
|
137
149
|
}
|
|
138
150
|
|
|
139
151
|
}
|
|
@@ -300,18 +312,6 @@ const getDeviceId = client.getDeviceId.bind(client);
|
|
|
300
312
|
|
|
301
313
|
exports.getDeviceId = getDeviceId;
|
|
302
314
|
const setDeviceId = client.setDeviceId.bind(client);
|
|
303
|
-
/**
|
|
304
|
-
* Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you
|
|
305
|
-
* are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.
|
|
306
|
-
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
307
|
-
*
|
|
308
|
-
* ```typescript
|
|
309
|
-
* regenerateDeviceId();
|
|
310
|
-
* ```
|
|
311
|
-
*/
|
|
312
|
-
|
|
313
|
-
exports.setDeviceId = setDeviceId;
|
|
314
|
-
const regenerateDeviceId = client.regenerateDeviceId.bind(client);
|
|
315
315
|
/**
|
|
316
316
|
* reset is a shortcut to anonymize users after they log out, by:
|
|
317
317
|
* - setting userId to `undefined`
|
|
@@ -324,7 +324,7 @@ const regenerateDeviceId = client.regenerateDeviceId.bind(client);
|
|
|
324
324
|
* ```
|
|
325
325
|
*/
|
|
326
326
|
|
|
327
|
-
exports.
|
|
327
|
+
exports.setDeviceId = setDeviceId;
|
|
328
328
|
const reset = client.reset.bind(client);
|
|
329
329
|
/**
|
|
330
330
|
* Returns current 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","reset","undefined","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 // 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 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 reset() {\n this.setUserId(undefined);\n this.regenerateDeviceId();\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 `undefined` 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 * 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,OAAO,CAAEM,SAH6C;MAIzFC,MAAM,qBAAEP,OAAF,aAAEA,OAAF,uBAAEA,OAAO,CAAEO,MAAX,6DAAqBN,UAAU,CAACM,MAJmD;MAKzFC,aAAa,EAAEP,UAAU,CAACO;IAL+D,CAA1D,CAAjC;IAOA,MAAM,MAAMC,KAAN,CAAYN,kBAAZ,CAAN,CAZuG,CAcvG;;IACA,IAAIO,YAAY,GAAG,KAAnB;;IACA,IACE,CAAC,KAAKC,MAAL,CAAYL,SAAb,IACC,KAAKK,MAAL,CAAYH,aAAZ,IAA6BI,IAAI,CAACC,GAAL,KAAa,KAAKF,MAAL,CAAYH,aAAzB,GAAyC,KAAKG,MAAL,CAAYG,cAFrF,EAGE;MACA;MACA;MACA;MACA,KAAKH,MAAL,C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AoBlB,IAApB,CAAyBoB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMlB,YAAY,GAAGkB,MAAM,CAAClB,YAAP,CAAoBF,IAApB,CAAyBoB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMD,SAAS,GAAGC,MAAM,CAACD,SAAP,CAAiBnB,IAAjB,CAAsBoB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMQ,KAAK,GAAG,IAAAP,4BAAA,EAAcD,MAAM,CAACQ,KAAP,CAAa5B,IAAb,CAAkBoB,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,MAA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A;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.2.
|
|
1
|
+
{"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.2.2';\n"],"mappings":";;;;;;AAAO,MAAMA,OAAO,GAAG,OAAhB"}
|
|
@@ -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,13 +21,13 @@ 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
33
|
// Send events from the experiment SDK and forward identifies to the
|
|
@@ -78,10 +78,17 @@ export class AmplitudeReactNative extends AmplitudeCore {
|
|
|
78
78
|
}
|
|
79
79
|
|
|
80
80
|
getUserId() {
|
|
81
|
-
|
|
81
|
+
var _this$config;
|
|
82
|
+
|
|
83
|
+
return (_this$config = this.config) === null || _this$config === void 0 ? void 0 : _this$config.userId;
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
setUserId(userId) {
|
|
87
|
+
if (!this.config) {
|
|
88
|
+
this.q.push(this.setUserId.bind(this, userId));
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
85
92
|
this.config.userId = userId;
|
|
86
93
|
getAnalyticsConnector().identityStore.editIdentity() // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
87
94
|
// @ts-ignore
|
|
@@ -89,36 +96,41 @@ export class AmplitudeReactNative extends AmplitudeCore {
|
|
|
89
96
|
}
|
|
90
97
|
|
|
91
98
|
getDeviceId() {
|
|
92
|
-
|
|
99
|
+
var _this$config2;
|
|
100
|
+
|
|
101
|
+
return (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.deviceId;
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
setDeviceId(deviceId) {
|
|
105
|
+
if (!this.config) {
|
|
106
|
+
this.q.push(this.setDeviceId.bind(this, deviceId));
|
|
107
|
+
return;
|
|
108
|
+
}
|
|
109
|
+
|
|
96
110
|
this.config.deviceId = deviceId;
|
|
97
111
|
getAnalyticsConnector().identityStore.editIdentity() // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
98
112
|
// @ts-ignore
|
|
99
113
|
.setDeviceId(deviceId).commit();
|
|
100
114
|
}
|
|
101
115
|
|
|
102
|
-
regenerateDeviceId() {
|
|
103
|
-
const deviceId = createDeviceId();
|
|
104
|
-
this.setDeviceId(deviceId);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
116
|
reset() {
|
|
108
117
|
this.setUserId(undefined);
|
|
109
|
-
this.
|
|
118
|
+
this.setDeviceId(UUID());
|
|
110
119
|
}
|
|
111
120
|
|
|
112
121
|
getSessionId() {
|
|
113
|
-
|
|
122
|
+
var _this$config3;
|
|
123
|
+
|
|
124
|
+
return (_this$config3 = this.config) === null || _this$config3 === void 0 ? void 0 : _this$config3.sessionId;
|
|
114
125
|
}
|
|
115
126
|
|
|
116
127
|
setSessionId(sessionId) {
|
|
117
|
-
this.config
|
|
118
|
-
|
|
128
|
+
if (!this.config) {
|
|
129
|
+
this.q.push(this.setSessionId.bind(this, sessionId));
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
119
132
|
|
|
120
|
-
|
|
121
|
-
this.config.optOut = optOut;
|
|
133
|
+
this.config.sessionId = sessionId;
|
|
122
134
|
}
|
|
123
135
|
|
|
124
136
|
}
|
|
@@ -271,17 +283,6 @@ export const getDeviceId = client.getDeviceId.bind(client);
|
|
|
271
283
|
*/
|
|
272
284
|
|
|
273
285
|
export const setDeviceId = client.setDeviceId.bind(client);
|
|
274
|
-
/**
|
|
275
|
-
* Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you
|
|
276
|
-
* are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.
|
|
277
|
-
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
278
|
-
*
|
|
279
|
-
* ```typescript
|
|
280
|
-
* regenerateDeviceId();
|
|
281
|
-
* ```
|
|
282
|
-
*/
|
|
283
|
-
|
|
284
|
-
export const regenerateDeviceId = client.regenerateDeviceId.bind(client);
|
|
285
286
|
/**
|
|
286
287
|
* reset is a shortcut to anonymize users after they log out, by:
|
|
287
288
|
* - setting userId to `undefined`
|
|
@@ -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","reset","undefined","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 // 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 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 reset() {\n this.setUserId(undefined);\n this.regenerateDeviceId();\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 `undefined` 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 * 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,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,oBAAoB,CAACU,MA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A;AACA;;AACA,OAAO,MAAMV,SAAS,GAAGU,MAAM,CAACV,SAAP,CAAiBP,IAAjB,CAAsBiB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMP,WAAW,GAAGO,MAAM,CAACP,WAAP,CAAmBV,IAAnB,CAAwBiB,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMN,WAAW,GAAGM,MAAM,CAACN,WAAP,CAAmBX,IAAnB,CAAwBiB,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAML,kBAAkB,GAAGK,MAAM,CAACL,kBAAP,CAA0BZ,IAA1B,CAA+BiB,MAA/B,CAA3B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMJ,KAAK,GAAGI,MAAM,CAACJ,KAAP,CAAab,IAAb,CAAkBiB,MAAlB,CAAd;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMF,YAAY,GAAGE,MAAM,CAACF,YAAP,CAAoBf,IAApB,CAAyBiB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMf,YAAY,GAAGe,MAAM,CAACf,YAAP,CAAoBF,IAApB,CAAyBiB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMD,SAAS,GAAGC,MAAM,CAACD,SAAP,CAAiBhB,IAAjB,CAAsBiB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,OAAO,MAAMO,KAAK,GAAGnE,aAAa,CAAC4D,MAAM,CAACO,KAAP,CAAaxB,IAAb,CAAkBiB,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,OAA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AAkBgB,MAAlB,CAAD,CAA3B"}
|
package/lib/module/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const VERSION = '0.2.
|
|
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.2.
|
|
1
|
+
{"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.2.2';\n"],"mappings":"AAAA,OAAO,MAAMA,OAAO,GAAG,OAAhB"}
|
|
@@ -7,11 +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
|
-
regenerateDeviceId(): void;
|
|
11
10
|
reset(): void;
|
|
12
11
|
getSessionId(): number | undefined;
|
|
13
12
|
setSessionId(sessionId: number): void;
|
|
14
|
-
setOptOut(optOut: boolean): void;
|
|
15
13
|
}
|
|
16
14
|
/**
|
|
17
15
|
* Initializes the Amplitude SDK with your apiKey, userId and optional configurations.
|
|
@@ -149,16 +147,6 @@ export declare const getDeviceId: () => string | undefined;
|
|
|
149
147
|
* ```
|
|
150
148
|
*/
|
|
151
149
|
export declare const setDeviceId: (deviceId: string) => void;
|
|
152
|
-
/**
|
|
153
|
-
* Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you
|
|
154
|
-
* are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.
|
|
155
|
-
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
156
|
-
*
|
|
157
|
-
* ```typescript
|
|
158
|
-
* regenerateDeviceId();
|
|
159
|
-
* ```
|
|
160
|
-
*/
|
|
161
|
-
export declare const regenerateDeviceId: () => void;
|
|
162
150
|
/**
|
|
163
151
|
* reset is a shortcut to anonymize users after they log out, by:
|
|
164
152
|
* - setting userId to `undefined`
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-native-client.d.ts","sourceRoot":"","sources":["../../src/react-native-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"react-native-client.d.ts","sourceRoot":"","sources":["../../src/react-native-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAoC,MAAM,2BAA2B,CAAC;AAC5F,OAAO,EACL,iBAAiB,EAEjB,kBAAkB,EAClB,4BAA4B,EAC5B,6BAA6B,EAC9B,MAAM,4BAA4B,CAAC;AASpC,qBAAa,oBAAqB,SAAQ,aAAa,CAAC,iBAAiB,CAAC;IAClE,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,kBAAkB,GAAG,4BAA4B;IAwDjG,sBAAsB,CAAC,iBAAiB,CAAC,EAAE,6BAA6B,EAAE,YAAY,UAAQ;IAkBpG,SAAS;IAIT,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,SAAS;IAcpC,WAAW;IAIX,WAAW,CAAC,QAAQ,EAAE,MAAM;IAc5B,KAAK;IAKL,YAAY;IAIZ,YAAY,CAAC,SAAS,EAAE,MAAM;CAO/B;AAID;;;;;;;GAOG;AACH,eAAO,MAAM,IAAI,iMAA0C,CAAC;AAE5D;;;;;;;GAOG;AACH,eAAO,MAAM,GAAG,8HAAyC,CAAC;AAE1D;;;;;;GAMG;AACH,eAAO,MAAM,MAAM,6FAA4C,CAAC;AAEhE;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,KAAK,sTAA2C,CAAC;AAE9D;;GAEG;AACH,eAAO,MAAM,QAAQ,sTAA8C,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,uPAA8C,CAAC;AAEpE;;;;;;;;;;;;;;;;GAgBG;AACH,eAAO,MAAM,aAAa,wSAAmD,CAAC;AAC9E,eAAO,MAAM,QAAQ,iKAA8C,CAAC;AAEpE;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,OAAO,qPAA6C,CAAC;AAElE;;;;;;GAMG;AACH,eAAO,MAAM,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.2.
|
|
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.2.
|
|
3
|
+
"version": "0.2.2",
|
|
4
4
|
"description": "Official React Native SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analytics",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
60
|
"@amplitude/analytics-connector": "1.4.5",
|
|
61
|
-
"@amplitude/analytics-core": "^0.6.
|
|
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
|
}
|
|
@@ -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,7 +38,7 @@ 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
|
|
|
@@ -90,10 +90,14 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
90
90
|
}
|
|
91
91
|
|
|
92
92
|
getUserId() {
|
|
93
|
-
return this.config
|
|
93
|
+
return this.config?.userId;
|
|
94
94
|
}
|
|
95
95
|
|
|
96
96
|
setUserId(userId: string | undefined) {
|
|
97
|
+
if (!this.config) {
|
|
98
|
+
this.q.push(this.setUserId.bind(this, userId));
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
97
101
|
this.config.userId = userId;
|
|
98
102
|
getAnalyticsConnector()
|
|
99
103
|
.identityStore.editIdentity()
|
|
@@ -104,10 +108,14 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
getDeviceId() {
|
|
107
|
-
return this.config
|
|
111
|
+
return this.config?.deviceId;
|
|
108
112
|
}
|
|
109
113
|
|
|
110
114
|
setDeviceId(deviceId: string) {
|
|
115
|
+
if (!this.config) {
|
|
116
|
+
this.q.push(this.setDeviceId.bind(this, deviceId));
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
111
119
|
this.config.deviceId = deviceId;
|
|
112
120
|
getAnalyticsConnector()
|
|
113
121
|
.identityStore.editIdentity()
|
|
@@ -117,27 +125,22 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
117
125
|
.commit();
|
|
118
126
|
}
|
|
119
127
|
|
|
120
|
-
regenerateDeviceId() {
|
|
121
|
-
const deviceId = createDeviceId();
|
|
122
|
-
this.setDeviceId(deviceId);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
128
|
reset() {
|
|
126
129
|
this.setUserId(undefined);
|
|
127
|
-
this.
|
|
130
|
+
this.setDeviceId(UUID());
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
getSessionId() {
|
|
131
|
-
return this.config
|
|
134
|
+
return this.config?.sessionId;
|
|
132
135
|
}
|
|
133
136
|
|
|
134
137
|
setSessionId(sessionId: number) {
|
|
138
|
+
if (!this.config) {
|
|
139
|
+
this.q.push(this.setSessionId.bind(this, sessionId));
|
|
140
|
+
return;
|
|
141
|
+
}
|
|
135
142
|
this.config.sessionId = sessionId;
|
|
136
143
|
}
|
|
137
|
-
|
|
138
|
-
setOptOut(optOut: boolean) {
|
|
139
|
-
this.config.optOut = optOut;
|
|
140
|
-
}
|
|
141
144
|
}
|
|
142
145
|
|
|
143
146
|
const client = new AmplitudeReactNative();
|
|
@@ -290,17 +293,6 @@ export const getDeviceId = client.getDeviceId.bind(client);
|
|
|
290
293
|
*/
|
|
291
294
|
export const setDeviceId = client.setDeviceId.bind(client);
|
|
292
295
|
|
|
293
|
-
/**
|
|
294
|
-
* Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you
|
|
295
|
-
* are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.
|
|
296
|
-
* With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
|
|
297
|
-
*
|
|
298
|
-
* ```typescript
|
|
299
|
-
* regenerateDeviceId();
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
export const regenerateDeviceId = client.regenerateDeviceId.bind(client);
|
|
303
|
-
|
|
304
296
|
/**
|
|
305
297
|
* reset is a shortcut to anonymize users after they log out, by:
|
|
306
298
|
* - setting userId to `undefined`
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.2.
|
|
1
|
+
export const VERSION = '0.2.2';
|