@amplitude/analytics-react-native 0.7.0 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/config.js +38 -85
- package/lib/commonjs/config.js.map +1 -1
- package/lib/commonjs/cookie-migration/index.js +0 -16
- package/lib/commonjs/cookie-migration/index.js.map +1 -1
- package/lib/commonjs/index.js +1 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/plugins/context.js +4 -24
- package/lib/commonjs/plugins/context.js.map +1 -1
- package/lib/commonjs/react-native-client.js +49 -99
- package/lib/commonjs/react-native-client.js.map +1 -1
- package/lib/commonjs/storage/local-storage.js +8 -20
- package/lib/commonjs/storage/local-storage.js.map +1 -1
- package/lib/commonjs/typings/browser-snippet.d.js.map +1 -1
- package/lib/commonjs/typings/ua-parser.d.js.map +1 -1
- package/lib/commonjs/utils/platform.js +0 -5
- package/lib/commonjs/utils/platform.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/config.js +38 -66
- package/lib/module/config.js.map +1 -1
- package/lib/module/cookie-migration/index.js +0 -8
- package/lib/module/cookie-migration/index.js.map +1 -1
- package/lib/module/index.js +2 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/plugins/context.js +4 -14
- package/lib/module/plugins/context.js.map +1 -1
- package/lib/module/react-native-client.js +49 -83
- package/lib/module/react-native-client.js.map +1 -1
- package/lib/module/storage/local-storage.js +8 -15
- package/lib/module/storage/local-storage.js.map +1 -1
- package/lib/module/typings/browser-snippet.d.js.map +1 -1
- package/lib/module/typings/ua-parser.d.js.map +1 -1
- package/lib/module/utils/platform.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/config.d.ts +5 -5
- package/lib/typescript/config.d.ts.map +1 -1
- package/lib/typescript/cookie-migration/index.d.ts +2 -2
- package/lib/typescript/cookie-migration/index.d.ts.map +1 -1
- package/lib/typescript/plugins/context.d.ts +1 -1
- package/lib/typescript/plugins/context.d.ts.map +1 -1
- package/lib/typescript/react-native-client.d.ts +1 -0
- package/lib/typescript/react-native-client.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +11 -11
- package/src/config.ts +14 -2
- package/src/react-native-client.ts +13 -3
- package/src/version.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@amplitude/analytics-react-native",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.1",
|
|
4
4
|
"description": "Official React Native SDK",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"analytics",
|
|
@@ -57,19 +57,19 @@
|
|
|
57
57
|
"url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
|
|
58
58
|
},
|
|
59
59
|
"dependencies": {
|
|
60
|
-
"@amplitude/analytics-client-common": "^0.5.
|
|
61
|
-
"@amplitude/analytics-core": "^0.11.
|
|
60
|
+
"@amplitude/analytics-client-common": "^0.5.1",
|
|
61
|
+
"@amplitude/analytics-core": "^0.11.1",
|
|
62
62
|
"@amplitude/analytics-types": "^0.14.0",
|
|
63
63
|
"@amplitude/ua-parser-js": "^0.7.31",
|
|
64
|
-
"@react-native-async-storage/async-storage": "^1.17.
|
|
65
|
-
"tslib": "^2.
|
|
64
|
+
"@react-native-async-storage/async-storage": "^1.17.11",
|
|
65
|
+
"tslib": "^2.4.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@types/react": "^
|
|
69
|
-
"@types/react-native": "0.
|
|
70
|
-
"react": "
|
|
71
|
-
"react-native": "0.
|
|
72
|
-
"react-native-builder-bob": "^0.
|
|
68
|
+
"@types/react": "^18.0.26",
|
|
69
|
+
"@types/react-native": "0.70.8",
|
|
70
|
+
"react": "18.2.0",
|
|
71
|
+
"react-native": "0.70.6",
|
|
72
|
+
"react-native-builder-bob": "^0.20.3"
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"react": "*",
|
|
@@ -89,5 +89,5 @@
|
|
|
89
89
|
]
|
|
90
90
|
]
|
|
91
91
|
},
|
|
92
|
-
"gitHead": "
|
|
92
|
+
"gitHead": "bb021b75fd1c48cbdb98d8f328eebb74f85c6fb4"
|
|
93
93
|
}
|
package/src/config.ts
CHANGED
|
@@ -113,6 +113,7 @@ export class ReactNativeConfig extends Config implements IReactNativeConfig {
|
|
|
113
113
|
}
|
|
114
114
|
|
|
115
115
|
set sessionId(sessionId: number | undefined) {
|
|
116
|
+
this.loggerProvider?.log(`Set sessionId to ${sessionId ?? 'undefined'}`);
|
|
116
117
|
this.sessionManager.setSessionId(sessionId);
|
|
117
118
|
}
|
|
118
119
|
|
|
@@ -146,18 +147,29 @@ export const useReactNativeConfig = async (
|
|
|
146
147
|
const queryParams = getQueryParams();
|
|
147
148
|
const sessionManager = await new SessionManager(cookieStorage, apiKey).load();
|
|
148
149
|
|
|
149
|
-
|
|
150
|
+
const restoredSessionId = (await cookieStorage.get(cookieName))?.sessionId;
|
|
151
|
+
const optionsSessionId = options?.sessionId;
|
|
152
|
+
|
|
153
|
+
const config = new ReactNativeConfig(apiKey, userId ?? cookies?.userId, {
|
|
150
154
|
...options,
|
|
151
155
|
cookieStorage,
|
|
152
156
|
sessionManager,
|
|
153
157
|
deviceId: createDeviceId(cookies?.deviceId, options?.deviceId, queryParams.deviceId),
|
|
154
158
|
domain,
|
|
155
159
|
optOut: options?.optOut ?? Boolean(cookies?.optOut),
|
|
156
|
-
sessionId:
|
|
160
|
+
sessionId: restoredSessionId ?? optionsSessionId,
|
|
157
161
|
storageProvider: await createEventsStorage(options),
|
|
158
162
|
trackingOptions: { ...defaultConfig.trackingOptions, ...options?.trackingOptions },
|
|
159
163
|
transportProvider: options?.transportProvider ?? new FetchTransport(),
|
|
160
164
|
});
|
|
165
|
+
|
|
166
|
+
config.loggerProvider?.log(
|
|
167
|
+
`Init: storage=${cookieStorage.constructor.name} restoredSessionId = ${
|
|
168
|
+
restoredSessionId ?? 'undefined'
|
|
169
|
+
}, optionsSessionId = ${optionsSessionId ?? 'undefined'}`,
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
return config;
|
|
161
173
|
};
|
|
162
174
|
|
|
163
175
|
export const createCookieStorage = async (
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AppState, AppStateStatus } from 'react-native';
|
|
1
|
+
import { AppState, AppStateStatus, NativeEventSubscription } from 'react-native';
|
|
2
2
|
import {
|
|
3
3
|
AmplitudeCore,
|
|
4
4
|
Destination,
|
|
@@ -30,6 +30,7 @@ const END_SESSION_EVENT = 'session_end';
|
|
|
30
30
|
|
|
31
31
|
export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
32
32
|
appState: AppStateStatus = 'background';
|
|
33
|
+
private appStateChangeHandler: NativeEventSubscription | undefined;
|
|
33
34
|
explicitSessionId: number | undefined;
|
|
34
35
|
|
|
35
36
|
async init(apiKey = '', userId?: string, options?: ReactNativeOptions) {
|
|
@@ -74,7 +75,12 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
74
75
|
// Step 4: Manage session
|
|
75
76
|
this.appState = AppState.currentState;
|
|
76
77
|
const isNewSession = this.startNewSessionIfNeeded();
|
|
77
|
-
|
|
78
|
+
this.config.loggerProvider?.log(
|
|
79
|
+
`Init: startNewSessionIfNeeded = ${isNewSession ? 'yes' : 'no'}, sessionId = ${
|
|
80
|
+
this.getSessionId() ?? 'undefined'
|
|
81
|
+
}`,
|
|
82
|
+
);
|
|
83
|
+
this.appStateChangeHandler = AppState.addEventListener('change', this.handleAppStateChange);
|
|
78
84
|
|
|
79
85
|
this.initializing = false;
|
|
80
86
|
|
|
@@ -86,7 +92,7 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
86
92
|
}
|
|
87
93
|
|
|
88
94
|
shutdown() {
|
|
89
|
-
|
|
95
|
+
this.appStateChangeHandler?.remove();
|
|
90
96
|
}
|
|
91
97
|
|
|
92
98
|
async runAttributionStrategy(attributionConfig?: AttributionOptions, isNewSession = false) {
|
|
@@ -181,6 +187,8 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
181
187
|
this.config.sessionId = sessionId;
|
|
182
188
|
|
|
183
189
|
if (this.config.trackingSessionEvents) {
|
|
190
|
+
this.config.loggerProvider?.log(`SESSION_END event: previousSessionId = ${previousSessionId ?? 'undefined'}`);
|
|
191
|
+
|
|
184
192
|
if (previousSessionId !== undefined) {
|
|
185
193
|
const sessionEndEvent: Event = {
|
|
186
194
|
event_type: END_SESSION_EVENT,
|
|
@@ -190,6 +198,7 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
190
198
|
void this.track(sessionEndEvent);
|
|
191
199
|
}
|
|
192
200
|
|
|
201
|
+
this.config.loggerProvider?.log(`SESSION_START event: sessionId = ${sessionId}`);
|
|
193
202
|
const sessionStartEvent: Event = {
|
|
194
203
|
event_type: START_SESSION_EVENT,
|
|
195
204
|
time: eventTime,
|
|
@@ -262,6 +271,7 @@ export class AmplitudeReactNative extends AmplitudeCore<ReactNativeConfig> {
|
|
|
262
271
|
const currentAppState = this.appState;
|
|
263
272
|
this.appState = nextAppState;
|
|
264
273
|
if (currentAppState !== nextAppState && nextAppState === 'active') {
|
|
274
|
+
this.config.loggerProvider?.log('App Activated');
|
|
265
275
|
this.startNewSessionIfNeeded();
|
|
266
276
|
}
|
|
267
277
|
};
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const VERSION = '0.7.
|
|
1
|
+
export const VERSION = '0.7.1';
|