@amplitude/analytics-react-native 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAmBA;;AAGA"}
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.remove = exports.regenerateDeviceId = exports.logEvent = exports.init = exports.identify = exports.groupIdentify = exports.getUserId = exports.getSessionId = exports.getDeviceId = exports.flush = exports.add = exports.AmplitudeReactNative = void 0;
6
+ exports.track = exports.setUserId = exports.setSessionId = exports.setOptOut = exports.setGroup = exports.setDeviceId = exports.revenue = exports.reset = exports.remove = exports.regenerateDeviceId = 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
 
@@ -116,6 +116,11 @@ class AmplitudeReactNative extends _analyticsCore.AmplitudeCore {
116
116
  this.setDeviceId(deviceId);
117
117
  }
118
118
 
119
+ reset() {
120
+ this.setUserId(undefined);
121
+ this.regenerateDeviceId();
122
+ }
123
+
119
124
  getSessionId() {
120
125
  return this.config.sessionId;
121
126
  }
@@ -295,7 +300,7 @@ const setDeviceId = client.setDeviceId.bind(client);
295
300
  /**
296
301
  * Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you
297
302
  * are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.
298
- * With an `unefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
303
+ * With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
299
304
  *
300
305
  * ```typescript
301
306
  * regenerateDeviceId();
@@ -304,6 +309,20 @@ const setDeviceId = client.setDeviceId.bind(client);
304
309
 
305
310
  exports.setDeviceId = setDeviceId;
306
311
  const regenerateDeviceId = client.regenerateDeviceId.bind(client);
312
+ /**
313
+ * reset is a shortcut to anonymize users after they log out, by:
314
+ * - setting userId to `undefined`
315
+ * - regenerating a new random deviceId
316
+ *
317
+ * With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
318
+ *
319
+ * ```typescript
320
+ * reset();
321
+ * ```
322
+ */
323
+
324
+ exports.regenerateDeviceId = regenerateDeviceId;
325
+ const reset = client.reset.bind(client);
307
326
  /**
308
327
  * Returns current session ID.
309
328
  *
@@ -312,7 +331,7 @@ const regenerateDeviceId = client.regenerateDeviceId.bind(client);
312
331
  * ```
313
332
  */
314
333
 
315
- exports.regenerateDeviceId = regenerateDeviceId;
334
+ exports.reset = reset;
316
335
  const getSessionId = client.getSessionId.bind(client);
317
336
  /**
318
337
  * 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 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,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AP,CAAiBT,IAAjB,CAAsBkB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMN,WAAW,GAAGM,MAAM,CAACN,WAAP,CAAmBZ,IAAnB,CAAwBkB,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAML,WAAW,GAAGK,MAAM,CAACL,WAAP,CAAmBb,IAAnB,CAAwBkB,MAAxB,CAApB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMJ,kBAAkB,GAAGI,MAAM,CAACJ,kBAAP,CAA0Bd,IAA1B,CAA+BkB,MAA/B,CAA3B;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMF,YAAY,GAAGE,MAAM,CAACF,YAAP,CAAoBhB,IAApB,CAAyBkB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMhB,YAAY,GAAGgB,MAAM,CAAChB,YAAP,CAAoBF,IAApB,CAAyBkB,MAAzB,CAArB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMD,SAAS,GAAGC,MAAM,CAACD,SAAP,CAAiBjB,IAAjB,CAAsBkB,MAAtB,CAAlB;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;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","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 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,KAA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AACA;AACA;AACA;AACA;;;AACO,MAAMJ,KAAK,GAAGI,MAAM,CAACJ,KAAP,CAAahB,IAAb,CAAkBoB,MAAlB,CAAd;AAEP;AACA;AACA;AACA;AACA;AACA;AACA;;;AACO,MAAMF,YAAY,GAAGE,MAAM,CAACF,YAAP,CAAoBlB,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"}
@@ -4,6 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.VERSION = void 0;
7
- const VERSION = '0.1.1';
7
+ const VERSION = '0.2.0';
8
8
  exports.VERSION = VERSION;
9
9
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.1.1';\n"],"mappings":";;;;;;AAAO,MAAMA,OAAO,GAAG,OAAhB"}
1
+ {"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.2.0';\n"],"mappings":";;;;;;AAAO,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'; // Hack - react-native apps have trouble with:
3
3
  // export * as Types from '@amplitude/analytics-types
4
4
 
@@ -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,OAXF,EAYEC,WAZF,EAaEC,QAbF,EAcEC,SAdF,EAeEC,YAfF,EAgBEC,SAhBF,EAiBEC,KAjBF,QAkBO,uBAlBP;AAmBA,SAASC,OAAT,EAAkBC,QAAlB,QAAkC,2BAAlC,C,CACA;AACA;;AACA,OAAO,KAAKC,KAAZ,MAAuB,4BAAvB;AACA,SAASA,KAAT"}
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"}
@@ -101,6 +101,11 @@ export class AmplitudeReactNative extends AmplitudeCore {
101
101
  this.setDeviceId(deviceId);
102
102
  }
103
103
 
104
+ reset() {
105
+ this.setUserId(undefined);
106
+ this.regenerateDeviceId();
107
+ }
108
+
104
109
  getSessionId() {
105
110
  return this.config.sessionId;
106
111
  }
@@ -266,7 +271,7 @@ export const setDeviceId = client.setDeviceId.bind(client);
266
271
  /**
267
272
  * Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you
268
273
  * are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.
269
- * With an `unefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
274
+ * With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
270
275
  *
271
276
  * ```typescript
272
277
  * regenerateDeviceId();
@@ -274,6 +279,19 @@ export const setDeviceId = client.setDeviceId.bind(client);
274
279
  */
275
280
 
276
281
  export const regenerateDeviceId = client.regenerateDeviceId.bind(client);
282
+ /**
283
+ * reset is a shortcut to anonymize users after they log out, by:
284
+ * - setting userId to `undefined`
285
+ * - regenerating a new random deviceId
286
+ *
287
+ * With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
288
+ *
289
+ * ```typescript
290
+ * reset();
291
+ * ```
292
+ */
293
+
294
+ export const reset = client.reset.bind(client);
277
295
  /**
278
296
  * Returns current session ID.
279
297
  *
@@ -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,oBAAoB,CAACU,MAAD,EAASC,MAAM,IAAIE,UAA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AO,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","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 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,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,6D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A;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,2 +1,2 @@
1
- export const VERSION = '0.1.1';
1
+ export const VERSION = '0.2.0';
2
2
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.1.1';\n"],"mappings":"AAAA,OAAO,MAAMA,OAAO,GAAG,OAAhB"}
1
+ {"version":3,"names":["VERSION"],"sources":["version.ts"],"sourcesContent":["export const VERSION = '0.2.0';\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"}
@@ -8,6 +8,7 @@ export declare class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfi
8
8
  getDeviceId(): string | undefined;
9
9
  setDeviceId(deviceId: string): void;
10
10
  regenerateDeviceId(): void;
11
+ reset(): void;
11
12
  getSessionId(): number | undefined;
12
13
  setSessionId(sessionId: number): void;
13
14
  setOptOut(optOut: boolean): void;
@@ -151,13 +152,25 @@ export declare const setDeviceId: (deviceId: string) => void;
151
152
  /**
152
153
  * Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you
153
154
  * are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.
154
- * With an `unefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
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
  * regenerateDeviceId();
158
159
  * ```
159
160
  */
160
161
  export declare const regenerateDeviceId: () => void;
162
+ /**
163
+ * reset is a shortcut to anonymize users after they log out, by:
164
+ * - setting userId to `undefined`
165
+ * - regenerating a new random deviceId
166
+ *
167
+ * With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
168
+ *
169
+ * ```typescript
170
+ * reset();
171
+ * ```
172
+ */
173
+ export declare const reset: () => void;
161
174
  /**
162
175
  * Returns current session ID.
163
176
  *
@@ -1 +1 @@
1
- {"version":3,"file":"react-native-client.d.ts","sourceRoot":"","sources":["../../src/react-native-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA8B,MAAM,2BAA2B,CAAC;AACtF,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;IAqDjG,sBAAsB,CAAC,iBAAiB,CAAC,EAAE,6BAA6B,EAAE,YAAY,UAAQ;I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AM,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,WA/KF,MAAM,GAAG,SAAS,SA+KgB,CAAC;AAEvD;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,0BAAkC,CAAC;AAE3D;;;;;;;;GAQG;AACH,eAAO,MAAM,WAAW,aArLA,MAAM,SAqL4B,CAAC;AAE3D;;;;;;;;GAQG;AACH,eAAO,MAAM,kBAAkB,YAAyC,CAAC;AAEzE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,YAA4B,CAAC;AAE/C;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,0BAAmC,CAAC;AAE7D;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,cAxMC,MAAM,SAwM4B,CAAC;AAE7D;;;;;;;;;;GAUG;AACH,eAAO,MAAM,SAAS,WAjNF,OAAO,SAiN2B,CAAC;AAEvD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,KAAK,2EAA2C,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "0.1.1";
1
+ export declare const VERSION = "0.2.0";
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.1.1",
3
+ "version": "0.2.0",
4
4
  "description": "Official React Native SDK",
5
5
  "keywords": [
6
6
  "analytics",
@@ -89,5 +89,5 @@
89
89
  ]
90
90
  ]
91
91
  },
92
- "gitHead": "321002ef9a539959373204c3d7b15322b0936752"
92
+ "gitHead": "617299ff3c624cade6e02cc44e82314a15498fc5"
93
93
  }
package/src/index.ts CHANGED
@@ -9,6 +9,7 @@ export {
9
9
  init,
10
10
  logEvent,
11
11
  remove,
12
+ reset,
12
13
  revenue,
13
14
  setDeviceId,
14
15
  setGroup,
@@ -119,6 +119,11 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
119
119
  this.setDeviceId(deviceId);
120
120
  }
121
121
 
122
+ reset() {
123
+ this.setUserId(undefined);
124
+ this.regenerateDeviceId();
125
+ }
126
+
122
127
  getSessionId() {
123
128
  return this.config.sessionId;
124
129
  }
@@ -285,7 +290,7 @@ export const setDeviceId = client.setDeviceId.bind(client);
285
290
  /**
286
291
  * Regenerates a new random deviceId for current user. Note: this is not recommended unless you know what you
287
292
  * are doing. This can be used in conjunction with `setUserId(undefined)` to anonymize users after they log out.
288
- * With an `unefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
293
+ * With an `undefined` userId and a completely new deviceId, the current user would appear as a brand new user in dashboard.
289
294
  *
290
295
  * ```typescript
291
296
  * regenerateDeviceId();
@@ -293,6 +298,19 @@ export const setDeviceId = client.setDeviceId.bind(client);
293
298
  */
294
299
  export const regenerateDeviceId = client.regenerateDeviceId.bind(client);
295
300
 
301
+ /**
302
+ * reset is a shortcut to anonymize users after they log out, by:
303
+ * - setting userId to `undefined`
304
+ * - regenerating a new random deviceId
305
+ *
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
+ * reset();
310
+ * ```
311
+ */
312
+ export const reset = client.reset.bind(client);
313
+
296
314
  /**
297
315
  * Returns current session ID.
298
316
  *
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '0.1.1';
1
+ export const VERSION = '0.2.0';