@amplitude/unified-react-native 1.0.0-beta.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.
Files changed (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +84 -0
  3. package/lib/commonjs/index.js +92 -0
  4. package/lib/commonjs/index.js.map +1 -0
  5. package/lib/commonjs/library.js +18 -0
  6. package/lib/commonjs/library.js.map +1 -0
  7. package/lib/commonjs/types.js +6 -0
  8. package/lib/commonjs/types.js.map +1 -0
  9. package/lib/commonjs/unified-client-factory.js +158 -0
  10. package/lib/commonjs/unified-client-factory.js.map +1 -0
  11. package/lib/commonjs/version.js +9 -0
  12. package/lib/commonjs/version.js.map +1 -0
  13. package/lib/module/index.js +32 -0
  14. package/lib/module/index.js.map +1 -0
  15. package/lib/module/library.js +11 -0
  16. package/lib/module/library.js.map +1 -0
  17. package/lib/module/types.js +2 -0
  18. package/lib/module/types.js.map +1 -0
  19. package/lib/module/unified-client-factory.js +151 -0
  20. package/lib/module/unified-client-factory.js.map +1 -0
  21. package/lib/module/version.js +3 -0
  22. package/lib/module/version.js.map +1 -0
  23. package/lib/typescript/index.d.ts +6 -0
  24. package/lib/typescript/index.d.ts.map +1 -0
  25. package/lib/typescript/library.d.ts +3 -0
  26. package/lib/typescript/library.d.ts.map +1 -0
  27. package/lib/typescript/types.d.ts +37 -0
  28. package/lib/typescript/types.d.ts.map +1 -0
  29. package/lib/typescript/unified-client-factory.d.ts +9 -0
  30. package/lib/typescript/unified-client-factory.d.ts.map +1 -0
  31. package/lib/typescript/version.d.ts +2 -0
  32. package/lib/typescript/version.d.ts.map +1 -0
  33. package/package.json +90 -0
  34. package/react-native.config.js +20 -0
  35. package/src/index.ts +36 -0
  36. package/src/library.ts +13 -0
  37. package/src/types.ts +47 -0
  38. package/src/unified-client-factory.ts +152 -0
  39. package/src/version.ts +2 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Amplitude Analytics
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,84 @@
1
+ # @amplitude/unified-react-native
2
+
3
+ Official Amplitude SDK wrapper for React Native Analytics, Experiment, Session Replay, and Guides and Surveys.
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install @amplitude/unified-react-native
9
+ ```
10
+
11
+ For a bare React Native application, load the package's autolinking preset from your application-level `react-native.config.js`:
12
+
13
+ ```javascript
14
+ module.exports = require('@amplitude/unified-react-native/react-native.config');
15
+ ```
16
+
17
+ If your application already has a React Native configuration, merge the preset's `dependencies` with your existing configuration:
18
+
19
+ ```javascript
20
+ const amplitude = require('@amplitude/unified-react-native/react-native.config');
21
+
22
+ module.exports = {
23
+ // Your existing configuration
24
+ dependencies: {
25
+ ...amplitude.dependencies,
26
+ // Your existing dependency overrides
27
+ },
28
+ };
29
+ ```
30
+
31
+ The preset lets React Native autolink the native blade modules installed transitively by the unified SDK. No blade package needs to be installed directly by the application.
32
+
33
+ The unified SDK requires React Native 0.76 or newer. Guides and Surveys uses React Native's typed native event emitters, so enable the React Native New Architecture before rebuilding. For Android, set `newArchEnabled=true` in `android/gradle.properties`; use your React Native version's corresponding New Architecture setup for iOS.
34
+
35
+ Install iOS pods after adding the package:
36
+
37
+ ```sh
38
+ cd ios && pod install
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ ```typescript
44
+ import {
45
+ experiment,
46
+ init,
47
+ track,
48
+ Types,
49
+ } from '@amplitude/unified-react-native';
50
+
51
+ await init('YOUR_API_KEY', {
52
+ // Shared defaults for every blade SDK
53
+ serverZone: 'US',
54
+ instanceName: 'app',
55
+ logLevel: Types.LogLevel.Warn,
56
+
57
+ analytics: {
58
+ userId: 'user-id',
59
+ },
60
+ sessionReplay: {
61
+ sampleRate: 1,
62
+ },
63
+ experiment: {
64
+ deploymentKey: 'YOUR_DEPLOYMENT_KEY',
65
+ },
66
+ engagement: {
67
+ locale: 'en-US',
68
+ },
69
+ });
70
+
71
+ track('App Opened');
72
+ const variant = experiment()?.variant('experiment-key');
73
+ ```
74
+
75
+ Options in `analytics`, `experiment`, `sessionReplay`, and `engagement` override the corresponding shared defaults.
76
+ Initialization is one-shot and idempotent: subsequent `init()` calls return the first initialization promise and do not reconfigure or retry the SDKs. Public SDK APIs do not throw initialization errors. Each error is reported through the Analytics `loggerProvider`; when Analytics is available, a blade failure does not prevent the remaining blades from initializing. After correcting the underlying configuration or native setup, restart the application before initializing again.
77
+
78
+ ### Multiple instances
79
+
80
+ The unified React Native SDK does not support isolated multiple instances. The React Native Engagement plugin is a process-wide singleton, so every unified client created with `createInstance()` shares the same Engagement plugin and native Engagement instance. The first initialization supplies its API key and Engagement configuration; later clients cannot configure an independent Engagement instance and may update the same shared identity through subsequent boot operations.
81
+
82
+ Use the package-level `init()`, `track()`, and other singleton exports for normal applications. If you create clients explicitly, treat their Engagement state as shared rather than independent.
83
+
84
+ The package also exports the React Native Analytics helpers `Identify`, `Revenue`, and `Types`, plus `AmpMaskView` for Session Replay masking.
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "AmpMaskView", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _pluginSessionReplayReactNative.AmpMaskView;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Identify", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _analyticsReactNative.Identify;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "Revenue", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _analyticsReactNative.Revenue;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "Types", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _analyticsReactNative.Types;
28
+ }
29
+ });
30
+ exports.add = void 0;
31
+ Object.defineProperty(exports, "createInstance", {
32
+ enumerable: true,
33
+ get: function () {
34
+ return _unifiedClientFactory.createInstance;
35
+ }
36
+ });
37
+ exports.trackScreenViewOnNavigationStateChange = exports.trackScreenView = exports.track = exports.setUserId = exports.setSessionId = exports.setOptOut = exports.setGroup = exports.setDeviceId = exports.sessionReplay = exports.revenue = exports.reset = exports.remove = exports.logEvent = exports.init = exports.identify = exports.groupIdentify = exports.getUserId = exports.getSessionId = exports.getDeviceId = exports.flush = exports.extendSession = exports.experiment = void 0;
38
+ var _unifiedClientFactory = require("./unified-client-factory");
39
+ var _pluginSessionReplayReactNative = require("@amplitude/plugin-session-replay-react-native");
40
+ var _analyticsReactNative = require("@amplitude/analytics-react-native");
41
+ /* eslint-disable @typescript-eslint/unbound-method */
42
+
43
+ const client = (0, _unifiedClientFactory.createInstance)();
44
+ const {
45
+ add,
46
+ experiment,
47
+ extendSession,
48
+ flush,
49
+ getDeviceId,
50
+ getSessionId,
51
+ getUserId,
52
+ groupIdentify,
53
+ identify,
54
+ init,
55
+ logEvent,
56
+ remove,
57
+ reset,
58
+ revenue,
59
+ sessionReplay,
60
+ setDeviceId,
61
+ setGroup,
62
+ setOptOut,
63
+ setSessionId,
64
+ setUserId,
65
+ track,
66
+ trackScreenView,
67
+ trackScreenViewOnNavigationStateChange
68
+ } = client;
69
+ exports.trackScreenViewOnNavigationStateChange = trackScreenViewOnNavigationStateChange;
70
+ exports.trackScreenView = trackScreenView;
71
+ exports.track = track;
72
+ exports.setUserId = setUserId;
73
+ exports.setSessionId = setSessionId;
74
+ exports.setOptOut = setOptOut;
75
+ exports.setGroup = setGroup;
76
+ exports.setDeviceId = setDeviceId;
77
+ exports.sessionReplay = sessionReplay;
78
+ exports.revenue = revenue;
79
+ exports.reset = reset;
80
+ exports.remove = remove;
81
+ exports.logEvent = logEvent;
82
+ exports.init = init;
83
+ exports.identify = identify;
84
+ exports.groupIdentify = groupIdentify;
85
+ exports.getUserId = getUserId;
86
+ exports.getSessionId = getSessionId;
87
+ exports.getDeviceId = getDeviceId;
88
+ exports.flush = flush;
89
+ exports.extendSession = extendSession;
90
+ exports.experiment = experiment;
91
+ exports.add = add;
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_unifiedClientFactory","require","_pluginSessionReplayReactNative","_analyticsReactNative","client","createInstance","add","experiment","extendSession","flush","getDeviceId","getSessionId","getUserId","groupIdentify","identify","init","logEvent","remove","reset","revenue","sessionReplay","setDeviceId","setGroup","setOptOut","setSessionId","setUserId","track","trackScreenView","trackScreenViewOnNavigationStateChange","exports"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,qBAAA,GAAAC,OAAA;AAiCA,IAAAC,+BAAA,GAAAD,OAAA;AACA,IAAAE,qBAAA,GAAAF,OAAA;AAnCA;;AAGA,MAAMG,MAAM,GAAG,IAAAC,oCAAc,EAAC,CAAC;AAKxB,MAAM;EACXC,GAAG;EACHC,UAAU;EACVC,aAAa;EACbC,KAAK;EACLC,WAAW;EACX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ty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.libraryPlugin = void 0;
7
+ var _version = require("./version");
8
+ const LIBRARY_PREFIX = 'amplitude-ts-unified-react-native';
9
+ const libraryPlugin = () => ({
10
+ type: 'enrichment',
11
+ name: '@amplitude/unified-react-native-library-plugin',
12
+ async execute(event) {
13
+ event.library = `${LIBRARY_PREFIX}/${_version.VERSION}-${event.library ?? ''}`;
14
+ return event;
15
+ }
16
+ });
17
+ exports.libraryPlugin = libraryPlugin;
18
+ //# sourceMappingURL=library.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_version","require","LIBRARY_PREFIX","libraryPlugin","type","name","execute","event","library","VERSION","exports"],"sourceRoot":"../../src","sources":["library.ts"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AAEA,MAAMC,cAAc,GAAG,mCAAmC;AAEnD,MAAMC,aAAa,GAAGA,CAAA,MAAyB;EACpDC,IAAI,EAAE,YAAY;EAClBC,IAAI,EAAE,gDAAgD;EACtD,MAAMC,OAAOA,CAACC,KAAY,EAAkB;IAC1CA,KAAK,CAACC,OAAO,GAAG,GAAGN,cAAc,IAAIO,gBAAO,IAAIF,KAAK,CAACC,OAAO,IAAI,EAAE,EAAE;IACrE,OAAOD,KAAK;EACd;AACF,CAAC,CAAC;AAACG,OAAA,CAAAP,aAAA,GAAAA,aAAA","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createInstance = void 0;
7
+ var _analyticsReactNative = require("@amplitude/analytics-react-native");
8
+ var _analyticsCore = require("@amplitude/analytics-core");
9
+ var _pluginEngagementReactNative = require("@amplitude/plugin-engagement-react-native");
10
+ var _pluginExperimentReactNative = require("@amplitude/plugin-experiment-react-native");
11
+ var _pluginSessionReplayReactNative = require("@amplitude/plugin-session-replay-react-native");
12
+ var _library = require("./library");
13
+ const toEngagementLogLevel = logLevel => {
14
+ switch (logLevel) {
15
+ case _analyticsCore.LogLevel.None:
16
+ return 'none';
17
+ case _analyticsCore.LogLevel.Error:
18
+ return 'error';
19
+ case _analyticsCore.LogLevel.Warn:
20
+ return 'warn';
21
+ case _analyticsCore.LogLevel.Verbose:
22
+ return 'verbose';
23
+ case _analyticsCore.LogLevel.Debug:
24
+ return 'debug';
25
+ }
26
+ };
27
+ const getSharedAnalyticsOptions = options => ({
28
+ ...((options === null || options === void 0 ? void 0 : options.serverZone) === undefined ? {} : {
29
+ serverZone: options.serverZone
30
+ }),
31
+ ...((options === null || options === void 0 ? void 0 : options.instanceName) === undefined ? {} : {
32
+ instanceName: options.instanceName
33
+ }),
34
+ ...((options === null || options === void 0 ? void 0 : options.logLevel) === undefined ? {} : {
35
+ logLevel: options.logLevel
36
+ })
37
+ });
38
+ const getSharedExperimentOptions = options => ({
39
+ ...((options === null || options === void 0 ? void 0 : options.serverZone) === undefined ? {} : {
40
+ serverZone: options.serverZone
41
+ }),
42
+ ...((options === null || options === void 0 ? void 0 : options.instanceName) === undefined ? {} : {
43
+ instanceName: options.instanceName
44
+ })
45
+ });
46
+ const getSharedSessionReplayOptions = options => ({
47
+ ...((options === null || options === void 0 ? void 0 : options.logLevel) === undefined ? {} : {
48
+ logLevel: options.logLevel
49
+ })
50
+ });
51
+ const getSharedEngagementOptions = options => ({
52
+ ...((options === null || options === void 0 ? void 0 : options.serverZone) === undefined ? {} : {
53
+ serverZone: options.serverZone
54
+ }),
55
+ ...((options === null || options === void 0 ? void 0 : options.logLevel) === undefined ? {} : {
56
+ logLevel: toEngagementLogLevel(options.logLevel)
57
+ })
58
+ });
59
+ const logInitializationError = (loggerProvider, blade, error) => {
60
+ try {
61
+ loggerProvider.error(`Failed to initialize ${blade}.`, error);
62
+ } catch {
63
+ // A customer-provided logger must not make a public SDK API throw.
64
+ }
65
+ };
66
+
67
+ /**
68
+ * Creates a unified client.
69
+ *
70
+ * Multiple unified clients are not isolated because the React Native Engagement plugin is a process-wide singleton.
71
+ * All clients share the first initialized Engagement plugin and its configuration.
72
+ */
73
+ const createInstance = () => {
74
+ const analyticsClient = (0, _analyticsReactNative.createInstance)();
75
+ let experiment;
76
+ let sessionReplay;
77
+ let initPromise;
78
+ const init = (apiKey, unifiedOptions) => {
79
+ if (initPromise) {
80
+ return initPromise;
81
+ }
82
+ initPromise = (async () => {
83
+ let loggerProvider = new _analyticsCore.Logger();
84
+ try {
85
+ const analyticsOptions = {
86
+ ...getSharedAnalyticsOptions(unifiedOptions),
87
+ ...(unifiedOptions === null || unifiedOptions === void 0 ? void 0 : unifiedOptions.analytics)
88
+ };
89
+ loggerProvider = analyticsOptions.loggerProvider ?? loggerProvider;
90
+ if (analyticsOptions.loggerProvider === undefined) {
91
+ loggerProvider.enable(analyticsOptions.logLevel ?? _analyticsCore.LogLevel.Warn);
92
+ }
93
+ analyticsOptions.loggerProvider = loggerProvider;
94
+ analyticsClient.add((0, _library.libraryPlugin)());
95
+ await analyticsClient.init(apiKey, analyticsOptions.userId, analyticsOptions).promise;
96
+ } catch (error) {
97
+ logInitializationError(loggerProvider, 'Analytics', error);
98
+ return;
99
+ }
100
+ const initExperiment = async () => {
101
+ try {
102
+ const initializedExperiment = (0, _pluginExperimentReactNative.experimentPlugin)({
103
+ ...getSharedExperimentOptions(unifiedOptions),
104
+ ...(unifiedOptions === null || unifiedOptions === void 0 ? void 0 : unifiedOptions.experiment)
105
+ });
106
+ await analyticsClient.add(initializedExperiment).promise;
107
+ experiment = initializedExperiment;
108
+ const experimentClient = initializedExperiment.experiment;
109
+ if (experimentClient === undefined) {
110
+ loggerProvider.debug(`${initializedExperiment.name} plugin is not initialized.`);
111
+ } else {
112
+ await experimentClient.start();
113
+ }
114
+ } catch (error) {
115
+ logInitializationError(loggerProvider, 'Experiment', error);
116
+ }
117
+ };
118
+ const initSessionReplay = async () => {
119
+ try {
120
+ const initializedSessionReplay = new _pluginSessionReplayReactNative.SessionReplayPlugin({
121
+ ...getSharedSessionReplayOptions(unifiedOptions),
122
+ ...(unifiedOptions === null || unifiedOptions === void 0 ? void 0 : unifiedOptions.sessionReplay)
123
+ });
124
+ await analyticsClient.add(initializedSessionReplay).promise;
125
+ sessionReplay = initializedSessionReplay;
126
+ } catch (error) {
127
+ logInitializationError(loggerProvider, 'Session Replay', error);
128
+ }
129
+ };
130
+ const initEngagement = async () => {
131
+ try {
132
+ // Engagement intentionally returns a process-wide singleton. Independent unified client instances are unsupported.
133
+ const engagement = (0, _pluginEngagementReactNative.getPlugin)({
134
+ ...getSharedEngagementOptions(unifiedOptions),
135
+ ...(unifiedOptions === null || unifiedOptions === void 0 ? void 0 : unifiedOptions.engagement)
136
+ });
137
+ await analyticsClient.add(engagement).promise;
138
+ await (0, _pluginEngagementReactNative.boot)(analyticsClient.getUserId(), analyticsClient.getDeviceId());
139
+ } catch (error) {
140
+ logInitializationError(loggerProvider, 'Guides and Surveys', error);
141
+ }
142
+ };
143
+ await Promise.all([initExperiment(), initSessionReplay(), initEngagement()]);
144
+ })();
145
+ return initPromise;
146
+ };
147
+ return {
148
+ ...analyticsClient,
149
+ init,
150
+ experiment: () => {
151
+ var _experiment;
152
+ return (_experiment = experiment) === null || _experiment === void 0 ? void 0 : _experiment.experiment;
153
+ },
154
+ sessionReplay: () => sessionReplay
155
+ };
156
+ };
157
+ exports.createInstance = createInstance;
158
+ //# sourceMappingURL=unified-client-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_analyticsReactNative","require","_analyticsCore","_pluginEngagementReactNative","_pluginExperimentReactNative","_pluginSessionReplayReactNative","_library","toEngagementLogLevel","logLevel","LogLevel","None","Error","Warn","Verbose","Debug","getSharedAnalyticsOptions","options","serverZone","undefined","instanceName","getSharedExperimentOptions","getSharedSessionReplayOptions","getSharedEngagementOptions","logInitializationError","loggerProvider","blade","error","createInstance","analyticsClient","createAnalyticsInstance","experiment","sessionReplay","initPromise","init","apiKey","unifiedOptions","Logger","analyticsOptions","analytics","enable","add","libraryPlugin","userId","promise","initExperiment","initializedExperiment","experimentPlugin","experimentClient","debug","name","start","initSessionReplay","initializedSessionReplay","SessionReplayPlugin","initEngagement","engagement","getPlugin","bootEngagement","getUserId","getDeviceId","Promise","all","_experiment","exports"],"sourceRoot":"../../src","sources":["unified-client-factory.ts"],"mappings":";;;;;;AAAA,IAAAA,qBAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AACA,IAAAE,4BAAA,GAAAF,OAAA;AACA,IAAAG,4BAAA,GAAAH,OAAA;AAEA,IAAAI,+BAAA,GAAAJ,OAAA;AACA,IAAAK,QAAA,GAAAL,OAAA;AAKA,MAAMM,oBAAoB,GAAIC,QAAkB,IAAyB;EACvE,QAAQA,QAAQ;IACd,KAAKC,uBAAQ,CAACC,IAAI;MAChB,OAAO,MAAM;IACf,KAAKD,uBAAQ,CAACE,KAAK;MACjB,OAAO,OAAO;IAChB,KAAKF,uBAAQ,CAACG,IAAI;MAChB,OAAO,MAAM;IACf,KAAKH,uBAAQ,CAACI,OAAO;MACnB,OAAO,SAAS;IAClB,KAAKJ,uBAAQ,CAACK,KAAK;MACjB,OAAO,OAAO;EAClB;AACF,CAAC;AAED,MAAMC,yBAAyB,GAAIC,OAAwB,KAA0B;EACnF,IAAI,CAAAA,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEC,UAAU,MAAKC,SAAS,GAAG,CAAC,CAAC,GAAG;IAAED,UAAU,EAAED,OAAO,CAACC;EAAW,CAAC,CAAC;EAChF,IAAI,CAAAD,OAAO,aAAPA,OAAO,uBAAPA,OAAO,CAAEG,YAAY,MAAKD,SAAS,GAAG,CAAC,CAAC,GAAG;IAAEC,YAAY,EAAEH,OAAO,CAACG;EAAa,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,uBAAdA,cAAc,CAAEoB,UAAU;UAC/B,CAAC,CAAC;UACF,MAAM3B,eAAe,CAACY,GAAG,CAACe,UAAU,CAAC,CAACZ,OAAO;UAC7C,MAAM,IAAAc,iCAAc,EAAC7B,eAAe,CAAC8B,SAAS,CAAC,CAAC,EAAE9B,eAAe,CAAC+B,WAAW,CAAC,CAAC,CAAC;QAClF,CAAC,CAAC,OAAOjC,KAAK,EAAE;UACdH,sBAAsB,CAACC,cAAc,EAAE,oBAAoB,EAAEE,KAAK,CAAC;QACrE;MACF,CAAC;MAED,MAAMkC,OAAO,CAACC,GAAG,CAAC,CAACjB,cAAc,CAAC,CAAC,EAAEO,iBAAiB,CAAC,CAAC,EAAEG,cAAc,CAAC,CAAC,CAAC,CAAC;IAC9E,CAAC,EAAE,CAAC;IAEJ,OAAOtB,WAAW;EACpB,CAAC;EAED,OAAO;IACL,GAAGJ,eAAe;IAClBK,IAAI;IACJH,UAAU,EAAEA,CAAA;MAAA,IAAAgC,WAAA;MAAA,QAAAA,WAAA,GAAMhC,UAAU,cAAAgC,WAAA,uBAAVA,WAAA,CAAYhC,UAAU;IAAA;IACxCC,aAAa,EAAEA,CAAA,KAAMA;EACvB,CAAC;AACH,CAAC;AAACgC,OAAA,CAAApC,cAAA,GAAAA,cAAA","ignoreList":[]}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.VERSION = void 0;
7
+ // Autogenerated by `pnpm version-file`. DO NOT EDIT
8
+ const VERSION = exports.VERSION = '1.0.0-beta.0';
9
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["VERSION","exports"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":";;;;;;AAAA;AACO,MAAMA,OAAO,GAAAC,OAAA,CAAAD,OAAA,GAAG,cAAc","ignoreList":[]}
@@ -0,0 +1,32 @@
1
+ /* eslint-disable @typescript-eslint/unbound-method */
2
+ import { createInstance } from './unified-client-factory';
3
+ const client = createInstance();
4
+ export { createInstance } from './unified-client-factory';
5
+ export const {
6
+ add,
7
+ experiment,
8
+ extendSession,
9
+ flush,
10
+ getDeviceId,
11
+ getSessionId,
12
+ getUserId,
13
+ groupIdentify,
14
+ identify,
15
+ init,
16
+ logEvent,
17
+ remove,
18
+ reset,
19
+ revenue,
20
+ sessionReplay,
21
+ setDeviceId,
22
+ setGroup,
23
+ setOptOut,
24
+ setSessionId,
25
+ setUserId,
26
+ track,
27
+ trackScreenView,
28
+ trackScreenViewOnNavigationStateChange
29
+ } = client;
30
+ export { AmpMaskView } from '@amplitude/plugin-session-replay-react-native';
31
+ export { Identify, Revenue, Types } from '@amplitude/analytics-react-native';
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createInstance","client","add","experiment","extendSession","flush","getDeviceId","getSessionId","getUserId","groupIdentify","identify","init","logEvent","remove","reset","revenue","sessionReplay","setDeviceId","setGroup","setOptOut","setSessionId","setUserId","track","trackScreenView","trackScreenViewOnNavigationStateChange","AmpMaskView","Identify","Revenue","Types"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA;AACA,SAASA,cAAc,QAAQ,0BAA0B;AAEzD,MAAMC,MAAM,GAAGD,cAAc,CAAC,CAAC;AAE/B,SAASA,cAAc,QAAQ,0BAA0B;AAGzD,OAAO,MAAM;EACXE,GAAG;EACHC,UAAU;EACVC,aAAa;EACbC,KAAK;EACLC,WAAW;EACXC,YAAY;EACZC,SAAS;EACTC,aAAa;EACbC,QAAQ;EACRC,IAAI;EACJC,QAAQ;EACRC,MAAM;EACNC,KAAK;EACLC,OAAO;EACPC,aAAa;EACbC,WAAW;EACXC,QAAQ;EACRC,SAAS;EACTC,YAAY;EACZC,SAAS;EACTC,KAAK;EACLC,eAAe;EACfC;AACF,CAAC,GAAGvB,MAAM;AAEV,SAASwB,WAAW,QAAQ,+CAA+C;AAC3E,SAASC,QAAQ,EAAEC,OAAO,EAAEC,KAAK,QAAQ,mCAAmC","ignoreList":[]}
@@ -0,0 +1,11 @@
1
+ import { VERSION } from './version';
2
+ const LIBRARY_PREFIX = 'amplitude-ts-unified-react-native';
3
+ export const libraryPlugin = () => ({
4
+ type: 'enrichment',
5
+ name: '@amplitude/unified-react-native-library-plugin',
6
+ async execute(event) {
7
+ event.library = `${LIBRARY_PREFIX}/${VERSION}-${event.library ?? ''}`;
8
+ return event;
9
+ }
10
+ });
11
+ //# sourceMappingURL=library.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["VERSION","LIBRARY_PREFIX","libraryPlugin","type","name","execute","event","library"],"sourceRoot":"../../src","sources":["library.ts"],"mappings":"AACA,SAASA,OAAO,QAAQ,WAAW;AAEnC,MAAMC,cAAc,GAAG,mCAAmC;AAE1D,OAAO,MAAMC,aAAa,GAAGA,CAAA,MAAyB;EACpDC,IAAI,EAAE,YAAY;EAClBC,IAAI,EAAE,gDAAgD;EACtD,MAAMC,OAAOA,CAACC,KAAY,EAAkB;IAC1CA,KAAK,CAACC,OAAO,GAAG,GAAGN,cAAc,IAAID,OAAO,IAAIM,KAAK,CAACC,OAAO,IAAI,EAAE,EAAE;IACrE,OAAOD,KAAK;EACd;AACF,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["types.ts"],"mappings":"","ignoreList":[]}
@@ -0,0 +1,151 @@
1
+ import { createInstance as createAnalyticsInstance } from '@amplitude/analytics-react-native';
2
+ import { Logger, LogLevel } from '@amplitude/analytics-core';
3
+ import { boot as bootEngagement, getPlugin } from '@amplitude/plugin-engagement-react-native';
4
+ import { experimentPlugin } from '@amplitude/plugin-experiment-react-native';
5
+ import { SessionReplayPlugin } from '@amplitude/plugin-session-replay-react-native';
6
+ import { libraryPlugin } from './library';
7
+ const toEngagementLogLevel = logLevel => {
8
+ switch (logLevel) {
9
+ case LogLevel.None:
10
+ return 'none';
11
+ case LogLevel.Error:
12
+ return 'error';
13
+ case LogLevel.Warn:
14
+ return 'warn';
15
+ case LogLevel.Verbose:
16
+ return 'verbose';
17
+ case LogLevel.Debug:
18
+ return 'debug';
19
+ }
20
+ };
21
+ const getSharedAnalyticsOptions = options => ({
22
+ ...((options === null || options === void 0 ? void 0 : options.serverZone) === undefined ? {} : {
23
+ serverZone: options.serverZone
24
+ }),
25
+ ...((options === null || options === void 0 ? void 0 : options.instanceName) === undefined ? {} : {
26
+ instanceName: options.instanceName
27
+ }),
28
+ ...((options === null || options === void 0 ? void 0 : options.logLevel) === undefined ? {} : {
29
+ logLevel: options.logLevel
30
+ })
31
+ });
32
+ const getSharedExperimentOptions = options => ({
33
+ ...((options === null || options === void 0 ? void 0 : options.serverZone) === undefined ? {} : {
34
+ serverZone: options.serverZone
35
+ }),
36
+ ...((options === null || options === void 0 ? void 0 : options.instanceName) === undefined ? {} : {
37
+ instanceName: options.instanceName
38
+ })
39
+ });
40
+ const getSharedSessionReplayOptions = options => ({
41
+ ...((options === null || options === void 0 ? void 0 : options.logLevel) === undefined ? {} : {
42
+ logLevel: options.logLevel
43
+ })
44
+ });
45
+ const getSharedEngagementOptions = options => ({
46
+ ...((options === null || options === void 0 ? void 0 : options.serverZone) === undefined ? {} : {
47
+ serverZone: options.serverZone
48
+ }),
49
+ ...((options === null || options === void 0 ? void 0 : options.logLevel) === undefined ? {} : {
50
+ logLevel: toEngagementLogLevel(options.logLevel)
51
+ })
52
+ });
53
+ const logInitializationError = (loggerProvider, blade, error) => {
54
+ try {
55
+ loggerProvider.error(`Failed to initialize ${blade}.`, error);
56
+ } catch {
57
+ // A customer-provided logger must not make a public SDK API throw.
58
+ }
59
+ };
60
+
61
+ /**
62
+ * Creates a unified client.
63
+ *
64
+ * Multiple unified clients are not isolated because the React Native Engagement plugin is a process-wide singleton.
65
+ * All clients share the first initialized Engagement plugin and its configuration.
66
+ */
67
+ export const createInstance = () => {
68
+ const analyticsClient = createAnalyticsInstance();
69
+ let experiment;
70
+ let sessionReplay;
71
+ let initPromise;
72
+ const init = (apiKey, unifiedOptions) => {
73
+ if (initPromise) {
74
+ return initPromise;
75
+ }
76
+ initPromise = (async () => {
77
+ let loggerProvider = new Logger();
78
+ try {
79
+ const analyticsOptions = {
80
+ ...getSharedAnalyticsOptions(unifiedOptions),
81
+ ...(unifiedOptions === null || unifiedOptions === void 0 ? void 0 : unifiedOptions.analytics)
82
+ };
83
+ loggerProvider = analyticsOptions.loggerProvider ?? loggerProvider;
84
+ if (analyticsOptions.loggerProvider === undefined) {
85
+ loggerProvider.enable(analyticsOptions.logLevel ?? LogLevel.Warn);
86
+ }
87
+ analyticsOptions.loggerProvider = loggerProvider;
88
+ analyticsClient.add(libraryPlugin());
89
+ await analyticsClient.init(apiKey, analyticsOptions.userId, analyticsOptions).promise;
90
+ } catch (error) {
91
+ logInitializationError(loggerProvider, 'Analytics', error);
92
+ return;
93
+ }
94
+ const initExperiment = async () => {
95
+ try {
96
+ const initializedExperiment = experimentPlugin({
97
+ ...getSharedExperimentOptions(unifiedOptions),
98
+ ...(unifiedOptions === null || unifiedOptions === void 0 ? void 0 : unifiedOptions.experiment)
99
+ });
100
+ await analyticsClient.add(initializedExperiment).promise;
101
+ experiment = initializedExperiment;
102
+ const experimentClient = initializedExperiment.experiment;
103
+ if (experimentClient === undefined) {
104
+ loggerProvider.debug(`${initializedExperiment.name} plugin is not initialized.`);
105
+ } else {
106
+ await experimentClient.start();
107
+ }
108
+ } catch (error) {
109
+ logInitializationError(loggerProvider, 'Experiment', error);
110
+ }
111
+ };
112
+ const initSessionReplay = async () => {
113
+ try {
114
+ const initializedSessionReplay = new SessionReplayPlugin({
115
+ ...getSharedSessionReplayOptions(unifiedOptions),
116
+ ...(unifiedOptions === null || unifiedOptions === void 0 ? void 0 : unifiedOptions.sessionReplay)
117
+ });
118
+ await analyticsClient.add(initializedSessionReplay).promise;
119
+ sessionReplay = initializedSessionReplay;
120
+ } catch (error) {
121
+ logInitializationError(loggerProvider, 'Session Replay', error);
122
+ }
123
+ };
124
+ const initEngagement = async () => {
125
+ try {
126
+ // Engagement intentionally returns a process-wide singleton. Independent unified client instances are unsupported.
127
+ const engagement = getPlugin({
128
+ ...getSharedEngagementOptions(unifiedOptions),
129
+ ...(unifiedOptions === null || unifiedOptions === void 0 ? void 0 : unifiedOptions.engagement)
130
+ });
131
+ await analyticsClient.add(engagement).promise;
132
+ await bootEngagement(analyticsClient.getUserId(), analyticsClient.getDeviceId());
133
+ } catch (error) {
134
+ logInitializationError(loggerProvider, 'Guides and Surveys', error);
135
+ }
136
+ };
137
+ await Promise.all([initExperiment(), initSessionReplay(), initEngagement()]);
138
+ })();
139
+ return initPromise;
140
+ };
141
+ return {
142
+ ...analyticsClient,
143
+ init,
144
+ experiment: () => {
145
+ var _experiment;
146
+ return (_experiment = experiment) === null || _experiment === void 0 ? void 0 : _experiment.experiment;
147
+ },
148
+ sessionReplay: () => sessionReplay
149
+ };
150
+ };
151
+ //# sourceMappingURL=unified-client-factory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createInstance","createAnalyticsInstance","Logger","LogLevel","boot","bootEngagement","getPlugin","experimentPlugin","SessionReplayPlugin","libraryPlugin","toEngagementLogLevel","logLevel","None","Error","Warn","Verbose","Debug","getSharedAnalyticsOptions","options","serverZone","undefined","instanceName","getSharedExperimentOptions","getSharedSessionReplayOptions","getSharedEngagementOptions","logInitializationError","loggerProvider","blade","error","analyticsClient","experiment","sessionReplay","initPromise","init","apiKey","unifiedOptions","analyticsOptions","analytics","enable","add","userId","promise","initExperiment","initializedExperiment","experimentClient","debug","name","start","initSessionReplay","initializedSessionReplay","initEngagement","engagement","getUserId","getDeviceId","Promise","all","_experiment"],"sourceRoot":"../../src","sources":["unified-client-factory.ts"],"mappings":"AAAA,SAASA,cAAc,IAAIC,uBAAuB,QAAQ,mCAAmC;AAC7F,SAAkBC,MAAM,EAAEC,QAAQ,QAA4B,2B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B,CAAC,CAAC,EAAEE,cAAc,CAAC,CAAC,CAAC,CAAC;IAC9E,CAAC,EAAE,CAAC;IAEJ,OAAOlB,WAAW;EACpB,CAAC;EAED,OAAO;IACL,GAAGH,eAAe;IAClBI,IAAI;IACJH,UAAU,EAAEA,CAAA;MAAA,IAAA0B,WAAA;MAAA,QAAAA,WAAA,GAAM1B,UAAU,cAAA0B,WAAA,uBAAVA,WAAA,CAAY1B,UAAU;IAAA;IACxCC,aAAa,EAAEA,CAAA,KAAMA;EACvB,CAAC;AACH,CAAC","ignoreList":[]}
@@ -0,0 +1,3 @@
1
+ // Autogenerated by `pnpm version-file`. DO NOT EDIT
2
+ export const VERSION = '1.0.0-beta.0';
3
+ //# sourceMappingURL=version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["VERSION"],"sourceRoot":"../../src","sources":["version.ts"],"mappings":"AAAA;AACA,OAAO,MAAMA,OAAO,GAAG,cAAc","ignoreList":[]}
@@ -0,0 +1,6 @@
1
+ export { createInstance } from './unified-client-factory';
2
+ export type { UnifiedClient, UnifiedOptions, UnifiedSharedOptions } from './types';
3
+ export declare const add: (plugin: import("@amplitude/analytics-core").Plugin<import("@amplitude/analytics-core").ReactNativeClient, import("@amplitude/analytics-core").ReactNativeConfig>) => import("@amplitude/analytics-core").AmplitudeReturn<void>, experiment: () => import("@amplitude/plugin-experiment-react-native").IExperimentClient | undefined, extendSession: () => void, flush: () => import("@amplitude/analytics-core").AmplitudeReturn<void>, getDeviceId: () => string | undefined, getSessionId: () => number | undefined, getUserId: () => string | undefined, groupIdentify: (groupType: string, groupName: string | string[], identify: import("@amplitude/analytics-core").IIdentify, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, identify: (identify: import("@amplitude/analytics-core").IIdentify, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, init: (apiKey: string, unifiedOptions?: import("./types").UnifiedOptions | undefined) => Promise<void>, logEvent: (eventInput: string | import("@amplitude/analytics-core").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, remove: (pluginName: string) => import("@amplitude/analytics-core").AmplitudeReturn<void>, reset: () => void, revenue: (revenue: import("@amplitude/analytics-core").IRevenue, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, sessionReplay: () => import("@amplitude/plugin-session-replay-react-native").SessionReplayPlugin | undefined, setDeviceId: (deviceId: string) => void, setGroup: (groupType: string, groupName: string | string[], eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, setOptOut: (optOut: boolean) => void, setSessionId: (sessionId: number) => void, setUserId: (userId: string | undefined) => void, track: (eventInput: string | import("@amplitude/analytics-core").BaseEvent, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result>, trackScreenView: (screenName: string, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result | undefined>, trackScreenViewOnNavigationStateChange: (navigationState: import("@amplitude/analytics-core").NavigationState | undefined, eventProperties?: Record<string, any> | undefined, eventOptions?: import("@amplitude/analytics-core").EventOptions | undefined) => import("@amplitude/analytics-core").AmplitudeReturn<import("@amplitude/analytics-core").Result | undefined>;
4
+ export { AmpMaskView } from '@amplitude/plugin-session-replay-react-native';
5
+ export { Identify, Revenue, Types } from '@amplitude/analytics-react-native';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC1D,YAAY,EAAE,aAAa,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAC;AAEnF,eAAO,MACL,GAAG,mOACH,UAAU,2FACV,aAAa,cACb,KAAK,mEACL,WAAW,4BACX,YAAY,4BACZ,SAAS,4BACT,aAAa,8RACb,QAAQ,6OACR,IAAI,oGACJ,QAAQ,2SACR,MAAM,qFACN,KAAK,cACL,OAAO,2OACP,aAAa,iGACb,WAAW,8BACX,QAAQ,qOACR,SAAS,6BACT,YAAY,+BACZ,SAAS,wCACT,KAAK,2SACL,eAAe,uQACf,sCAAsC,mUAC9B,CAAC;AAEX,OAAO,EAAE,WAAW,EAAE,MAAM,+CAA+C,CAAC;AAC5E,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,mCAAmC,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { EnrichmentPlugin } from '@amplitude/analytics-core';
2
+ export declare const libraryPlugin: () => EnrichmentPlugin;
3
+ //# sourceMappingURL=library.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"library.d.ts","sourceRoot":"","sources":["../../src/library.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAS,MAAM,2BAA2B,CAAC;AAKzE,eAAO,MAAM,aAAa,QAAO,gBAO/B,CAAC"}
@@ -0,0 +1,37 @@
1
+ import type { LogLevel, ReactNativeClient, ReactNativeOptions } from '@amplitude/analytics-core';
2
+ import type { getPlugin } from '@amplitude/plugin-engagement-react-native';
3
+ import type { ExperimentPluginConfig, IExperimentClient } from '@amplitude/plugin-experiment-react-native';
4
+ import type { SessionReplayConfig, SessionReplayPlugin } from '@amplitude/plugin-session-replay-react-native';
5
+ /** @internal */
6
+ export type EngagementOptions = NonNullable<Parameters<typeof getPlugin>[0]>;
7
+ export interface UnifiedSharedOptions {
8
+ /** Data residency zone used by every blade SDK. */
9
+ serverZone?: 'US' | 'EU';
10
+ /** Named Analytics instance shared with SDKs that integrate through the Analytics connector. */
11
+ instanceName?: string;
12
+ /** Log verbosity translated to each blade SDK's representation. */
13
+ logLevel?: LogLevel;
14
+ }
15
+ export type UnifiedOptions = UnifiedSharedOptions & {
16
+ /** Analytics-specific options. These override shared options when both are set. */
17
+ analytics?: ReactNativeOptions;
18
+ /** Session Replay-specific options. These override shared options when both are set. */
19
+ sessionReplay?: SessionReplayConfig;
20
+ /** Experiment-specific options. These override shared options when both are set. */
21
+ experiment?: ExperimentPluginConfig;
22
+ /** Guides and Surveys-specific options. These override shared options when both are set. */
23
+ engagement?: EngagementOptions;
24
+ };
25
+ export interface UnifiedClient extends Omit<ReactNativeClient, 'init'> {
26
+ /**
27
+ * Initialize Analytics, Experiment, Session Replay, and Guides and Surveys.
28
+ * Initialization errors are logged and are not thrown. Subsequent calls return the first initialization promise
29
+ * without reconfiguring or retrying the SDKs.
30
+ */
31
+ init(apiKey: string, unifiedOptions?: UnifiedOptions): Promise<void>;
32
+ /** Return the Experiment client after init() has installed its plugin. */
33
+ experiment(): IExperimentClient | undefined;
34
+ /** Return the Session Replay plugin after init() has installed it. */
35
+ sessionReplay(): SessionReplayPlugin | undefined;
36
+ }
37
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AACjG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2CAA2C,CAAC;AAC3E,OAAO,KAAK,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC3G,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AAE9G,gBAAgB;AAChB,MAAM,MAAM,iBAAiB,GAAG,WAAW,CAAC,UAAU,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAE7E,MAAM,WAAW,oBAAoB;IACnC,mDAAmD;IACnD,UAAU,CAAC,EAAE,IAAI,GAAG,IAAI,CAAC;IAEzB,gGAAgG;IAChG,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,mEAAmE;IACnE,QAAQ,CAAC,EAAE,QAAQ,CAAC;CACrB;AAED,MAAM,MAAM,cAAc,GAAG,oBAAoB,GAAG;IAClD,mFAAmF;IACnF,SAAS,CAAC,EAAE,kBAAkB,CAAC;IAE/B,wFAAwF;IACxF,aAAa,CAAC,EAAE,mBAAmB,CAAC;IAEpC,oFAAoF;IACpF,UAAU,CAAC,EAAE,sBAAsB,CAAC;IAEpC,4FAA4F;IAC5F,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC,CAAC;AAEF,MAAM,WAAW,aAAc,SAAQ,IAAI,CAAC,iBAAiB,EAAE,MAAM,CAAC;IACpE;;;;OAIG;IACH,IAAI,CAAC,MAAM,EAAE,MAAM,EAAE,cAAc,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAErE,0EAA0E;IAC1E,UAAU,IAAI,iBAAiB,GAAG,SAAS,CAAC;IAE5C,sEAAsE;IACtE,aAAa,IAAI,mBAAmB,GAAG,SAAS,CAAC;CAClD"}
@@ -0,0 +1,9 @@
1
+ import type { UnifiedClient } from './types';
2
+ /**
3
+ * Creates a unified client.
4
+ *
5
+ * Multiple unified clients are not isolated because the React Native Engagement plugin is a process-wide singleton.
6
+ * All clients share the first initialized Engagement plugin and its configuration.
7
+ */
8
+ export declare const createInstance: () => UnifiedClient;
9
+ //# sourceMappingURL=unified-client-factory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"unified-client-factory.d.ts","sourceRoot":"","sources":["../../src/unified-client-factory.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAqB,aAAa,EAAkB,MAAM,SAAS,CAAC;AA+ChF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,QAAO,aA2FjC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const VERSION = "1.0.0-beta.0";
2
+ //# sourceMappingURL=version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,OAAO,iBAAiB,CAAC"}
package/package.json ADDED
@@ -0,0 +1,90 @@
1
+ {
2
+ "name": "@amplitude/unified-react-native",
3
+ "version": "1.0.0-beta.0",
4
+ "description": "Official Amplitude SDK for React Native analytics, Experiment, session replay, Guides and Surveys, and more.",
5
+ "keywords": [
6
+ "amplitude",
7
+ "analytics",
8
+ "experiment",
9
+ "react-native",
10
+ "session replay",
11
+ "guides and surveys"
12
+ ],
13
+ "author": "Amplitude Inc",
14
+ "homepage": "https://github.com/amplitude/Amplitude-TypeScript",
15
+ "license": "MIT",
16
+ "main": "lib/commonjs/index",
17
+ "module": "lib/module/index",
18
+ "types": "lib/typescript/index.d.ts",
19
+ "react-native": "src/index",
20
+ "source": "src/index",
21
+ "publishConfig": {
22
+ "access": "public",
23
+ "tag": "beta"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/amplitude/Amplitude-TypeScript.git"
28
+ },
29
+ "files": [
30
+ "src",
31
+ "lib",
32
+ "react-native.config.js",
33
+ "!test",
34
+ "!**/__tests__",
35
+ "!**/__fixtures__",
36
+ "!**/__mocks__",
37
+ "!**/.*"
38
+ ],
39
+ "bugs": {
40
+ "url": "https://github.com/amplitude/Amplitude-TypeScript/issues"
41
+ },
42
+ "dependencies": {
43
+ "@amplitude/experiment-react-native-client": "^1.8.0",
44
+ "@amplitude/plugin-engagement-react-native": "^3.11.0",
45
+ "@react-native-async-storage/async-storage": "^2.1.2",
46
+ "tslib": "^2.4.1",
47
+ "@amplitude/analytics-core": "2.55.0",
48
+ "@amplitude/analytics-react-native": "1.8.0",
49
+ "@amplitude/plugin-experiment-react-native": "1.0.0-beta.1",
50
+ "@amplitude/plugin-session-replay-react-native": "0.5.1"
51
+ },
52
+ "devDependencies": {
53
+ "react": "18.3.1",
54
+ "react-native": "0.76.9",
55
+ "react-native-builder-bob": "^0.20.3"
56
+ },
57
+ "peerDependencies": {
58
+ "react": "*",
59
+ "react-native": ">=0.76.0"
60
+ },
61
+ "react-native-builder-bob": {
62
+ "source": "src",
63
+ "output": "lib",
64
+ "targets": [
65
+ "commonjs",
66
+ "module",
67
+ [
68
+ "typescript",
69
+ {
70
+ "project": "tsconfig.build.json"
71
+ }
72
+ ]
73
+ ]
74
+ },
75
+ "scripts": {
76
+ "build": "bob build",
77
+ "clean": "rimraf node_modules lib coverage",
78
+ "fix": "pnpm fix:eslint & pnpm fix:prettier",
79
+ "fix:eslint": "eslint '{src,test}/**/*.ts' --fix",
80
+ "fix:prettier": "prettier --write \"{src,test}/**/*.ts\"",
81
+ "lint": "pnpm lint:eslint & pnpm lint:prettier",
82
+ "lint:eslint": "eslint '{src,test}/**/*.ts'",
83
+ "lint:prettier": "prettier --check \"{src,test}/**/*.ts\"",
84
+ "test": "jest",
85
+ "typecheck": "tsc --noEmit -p ./tsconfig.json",
86
+ "version": "pnpm version-file && pnpm build",
87
+ "version-file": "node -p \"'// Autogenerated by `pnpm version-file`. DO NOT EDIT\\nexport const VERSION = \\'' + require('./package.json').version + '\\';'\" > src/version.ts",
88
+ "typescript": "tsc --noEmit"
89
+ }
90
+ }
@@ -0,0 +1,20 @@
1
+ const path = require('path');
2
+
3
+ const nativePackages = [
4
+ '@amplitude/analytics-react-native',
5
+ '@amplitude/experiment-react-native-client',
6
+ '@amplitude/plugin-engagement-react-native',
7
+ '@amplitude/plugin-session-replay-react-native',
8
+ '@react-native-async-storage/async-storage',
9
+ ];
10
+
11
+ const dependencies = Object.fromEntries(
12
+ nativePackages.map((packageName) => [
13
+ packageName,
14
+ {
15
+ root: path.dirname(require.resolve(`${packageName}/package.json`)),
16
+ },
17
+ ]),
18
+ );
19
+
20
+ module.exports = { dependencies };
package/src/index.ts ADDED
@@ -0,0 +1,36 @@
1
+ /* eslint-disable @typescript-eslint/unbound-method */
2
+ import { createInstance } from './unified-client-factory';
3
+
4
+ const client = createInstance();
5
+
6
+ export { createInstance } from './unified-client-factory';
7
+ export type { UnifiedClient, UnifiedOptions, UnifiedSharedOptions } from './types';
8
+
9
+ export const {
10
+ add,
11
+ experiment,
12
+ extendSession,
13
+ flush,
14
+ getDeviceId,
15
+ getSessionId,
16
+ getUserId,
17
+ groupIdentify,
18
+ identify,
19
+ init,
20
+ logEvent,
21
+ remove,
22
+ reset,
23
+ revenue,
24
+ sessionReplay,
25
+ setDeviceId,
26
+ setGroup,
27
+ setOptOut,
28
+ setSessionId,
29
+ setUserId,
30
+ track,
31
+ trackScreenView,
32
+ trackScreenViewOnNavigationStateChange,
33
+ } = client;
34
+
35
+ export { AmpMaskView } from '@amplitude/plugin-session-replay-react-native';
36
+ export { Identify, Revenue, Types } from '@amplitude/analytics-react-native';
package/src/library.ts ADDED
@@ -0,0 +1,13 @@
1
+ import type { EnrichmentPlugin, Event } from '@amplitude/analytics-core';
2
+ import { VERSION } from './version';
3
+
4
+ const LIBRARY_PREFIX = 'amplitude-ts-unified-react-native';
5
+
6
+ export const libraryPlugin = (): EnrichmentPlugin => ({
7
+ type: 'enrichment',
8
+ name: '@amplitude/unified-react-native-library-plugin',
9
+ async execute(event: Event): Promise<Event> {
10
+ event.library = `${LIBRARY_PREFIX}/${VERSION}-${event.library ?? ''}`;
11
+ return event;
12
+ },
13
+ });
package/src/types.ts ADDED
@@ -0,0 +1,47 @@
1
+ import type { LogLevel, ReactNativeClient, ReactNativeOptions } from '@amplitude/analytics-core';
2
+ import type { getPlugin } from '@amplitude/plugin-engagement-react-native';
3
+ import type { ExperimentPluginConfig, IExperimentClient } from '@amplitude/plugin-experiment-react-native';
4
+ import type { SessionReplayConfig, SessionReplayPlugin } from '@amplitude/plugin-session-replay-react-native';
5
+
6
+ /** @internal */
7
+ export type EngagementOptions = NonNullable<Parameters<typeof getPlugin>[0]>;
8
+
9
+ export interface UnifiedSharedOptions {
10
+ /** Data residency zone used by every blade SDK. */
11
+ serverZone?: 'US' | 'EU';
12
+
13
+ /** Named Analytics instance shared with SDKs that integrate through the Analytics connector. */
14
+ instanceName?: string;
15
+
16
+ /** Log verbosity translated to each blade SDK's representation. */
17
+ logLevel?: LogLevel;
18
+ }
19
+
20
+ export type UnifiedOptions = UnifiedSharedOptions & {
21
+ /** Analytics-specific options. These override shared options when both are set. */
22
+ analytics?: ReactNativeOptions;
23
+
24
+ /** Session Replay-specific options. These override shared options when both are set. */
25
+ sessionReplay?: SessionReplayConfig;
26
+
27
+ /** Experiment-specific options. These override shared options when both are set. */
28
+ experiment?: ExperimentPluginConfig;
29
+
30
+ /** Guides and Surveys-specific options. These override shared options when both are set. */
31
+ engagement?: EngagementOptions;
32
+ };
33
+
34
+ export interface UnifiedClient extends Omit<ReactNativeClient, 'init'> {
35
+ /**
36
+ * Initialize Analytics, Experiment, Session Replay, and Guides and Surveys.
37
+ * Initialization errors are logged and are not thrown. Subsequent calls return the first initialization promise
38
+ * without reconfiguring or retrying the SDKs.
39
+ */
40
+ init(apiKey: string, unifiedOptions?: UnifiedOptions): Promise<void>;
41
+
42
+ /** Return the Experiment client after init() has installed its plugin. */
43
+ experiment(): IExperimentClient | undefined;
44
+
45
+ /** Return the Session Replay plugin after init() has installed it. */
46
+ sessionReplay(): SessionReplayPlugin | undefined;
47
+ }
@@ -0,0 +1,152 @@
1
+ import { createInstance as createAnalyticsInstance } from '@amplitude/analytics-react-native';
2
+ import { ILogger, Logger, LogLevel, ReactNativeOptions } from '@amplitude/analytics-core';
3
+ import { boot as bootEngagement, getPlugin } from '@amplitude/plugin-engagement-react-native';
4
+ import { experimentPlugin } from '@amplitude/plugin-experiment-react-native';
5
+ import type { ExperimentPlugin, ExperimentPluginConfig } from '@amplitude/plugin-experiment-react-native';
6
+ import { SessionReplayConfig, SessionReplayPlugin } from '@amplitude/plugin-session-replay-react-native';
7
+ import { libraryPlugin } from './library';
8
+ import type { EngagementOptions, UnifiedClient, UnifiedOptions } from './types';
9
+
10
+ type EngagementLogLevel = NonNullable<EngagementOptions['logLevel']>;
11
+
12
+ const toEngagementLogLevel = (logLevel: LogLevel): EngagementLogLevel => {
13
+ switch (logLevel) {
14
+ case LogLevel.None:
15
+ return 'none';
16
+ case LogLevel.Error:
17
+ return 'error';
18
+ case LogLevel.Warn:
19
+ return 'warn';
20
+ case LogLevel.Verbose:
21
+ return 'verbose';
22
+ case LogLevel.Debug:
23
+ return 'debug';
24
+ }
25
+ };
26
+
27
+ const getSharedAnalyticsOptions = (options?: UnifiedOptions): ReactNativeOptions => ({
28
+ ...(options?.serverZone === undefined ? {} : { serverZone: options.serverZone }),
29
+ ...(options?.instanceName === undefined ? {} : { instanceName: options.instanceName }),
30
+ ...(options?.logLevel === undefined ? {} : { logLevel: options.logLevel }),
31
+ });
32
+
33
+ const getSharedExperimentOptions = (options?: UnifiedOptions): ExperimentPluginConfig => ({
34
+ ...(options?.serverZone === undefined ? {} : { serverZone: options.serverZone }),
35
+ ...(options?.instanceName === undefined ? {} : { instanceName: options.instanceName }),
36
+ });
37
+
38
+ const getSharedSessionReplayOptions = (options?: UnifiedOptions): SessionReplayConfig => ({
39
+ ...(options?.logLevel === undefined ? {} : { logLevel: options.logLevel as SessionReplayConfig['logLevel'] }),
40
+ });
41
+
42
+ const getSharedEngagementOptions = (options?: UnifiedOptions): EngagementOptions => ({
43
+ ...(options?.serverZone === undefined ? {} : { serverZone: options.serverZone }),
44
+ ...(options?.logLevel === undefined ? {} : { logLevel: toEngagementLogLevel(options.logLevel) }),
45
+ });
46
+
47
+ const logInitializationError = (loggerProvider: ILogger, blade: string, error: unknown): void => {
48
+ try {
49
+ loggerProvider.error(`Failed to initialize ${blade}.`, error);
50
+ } catch {
51
+ // A customer-provided logger must not make a public SDK API throw.
52
+ }
53
+ };
54
+
55
+ /**
56
+ * Creates a unified client.
57
+ *
58
+ * Multiple unified clients are not isolated because the React Native Engagement plugin is a process-wide singleton.
59
+ * All clients share the first initialized Engagement plugin and its configuration.
60
+ */
61
+ export const createInstance = (): UnifiedClient => {
62
+ const analyticsClient = createAnalyticsInstance();
63
+ let experiment: ExperimentPlugin | undefined;
64
+ let sessionReplay: SessionReplayPlugin | undefined;
65
+ let initPromise: Promise<void> | undefined;
66
+
67
+ const init = (apiKey: string, unifiedOptions?: UnifiedOptions): Promise<void> => {
68
+ if (initPromise) {
69
+ return initPromise;
70
+ }
71
+
72
+ initPromise = (async () => {
73
+ let loggerProvider: ILogger = new Logger();
74
+
75
+ try {
76
+ const analyticsOptions: ReactNativeOptions = {
77
+ ...getSharedAnalyticsOptions(unifiedOptions),
78
+ ...unifiedOptions?.analytics,
79
+ };
80
+ loggerProvider = analyticsOptions.loggerProvider ?? loggerProvider;
81
+ if (analyticsOptions.loggerProvider === undefined) {
82
+ loggerProvider.enable(analyticsOptions.logLevel ?? LogLevel.Warn);
83
+ }
84
+ analyticsOptions.loggerProvider = loggerProvider;
85
+
86
+ analyticsClient.add(libraryPlugin());
87
+ await analyticsClient.init(apiKey, analyticsOptions.userId, analyticsOptions).promise;
88
+ } catch (error) {
89
+ logInitializationError(loggerProvider, 'Analytics', error);
90
+ return;
91
+ }
92
+
93
+ const initExperiment = async (): Promise<void> => {
94
+ try {
95
+ const initializedExperiment = experimentPlugin({
96
+ ...getSharedExperimentOptions(unifiedOptions),
97
+ ...unifiedOptions?.experiment,
98
+ });
99
+ await analyticsClient.add(initializedExperiment).promise;
100
+ experiment = initializedExperiment;
101
+
102
+ const experimentClient = initializedExperiment.experiment;
103
+ if (experimentClient === undefined) {
104
+ loggerProvider.debug(`${initializedExperiment.name} plugin is not initialized.`);
105
+ } else {
106
+ await experimentClient.start();
107
+ }
108
+ } catch (error) {
109
+ logInitializationError(loggerProvider, 'Experiment', error);
110
+ }
111
+ };
112
+
113
+ const initSessionReplay = async (): Promise<void> => {
114
+ try {
115
+ const initializedSessionReplay = new SessionReplayPlugin({
116
+ ...getSharedSessionReplayOptions(unifiedOptions),
117
+ ...unifiedOptions?.sessionReplay,
118
+ });
119
+ await analyticsClient.add(initializedSessionReplay).promise;
120
+ sessionReplay = initializedSessionReplay;
121
+ } catch (error) {
122
+ logInitializationError(loggerProvider, 'Session Replay', error);
123
+ }
124
+ };
125
+
126
+ const initEngagement = async (): Promise<void> => {
127
+ try {
128
+ // Engagement intentionally returns a process-wide singleton. Independent unified client instances are unsupported.
129
+ const engagement = getPlugin({
130
+ ...getSharedEngagementOptions(unifiedOptions),
131
+ ...unifiedOptions?.engagement,
132
+ });
133
+ await analyticsClient.add(engagement).promise;
134
+ await bootEngagement(analyticsClient.getUserId(), analyticsClient.getDeviceId());
135
+ } catch (error) {
136
+ logInitializationError(loggerProvider, 'Guides and Surveys', error);
137
+ }
138
+ };
139
+
140
+ await Promise.all([initExperiment(), initSessionReplay(), initEngagement()]);
141
+ })();
142
+
143
+ return initPromise;
144
+ };
145
+
146
+ return {
147
+ ...analyticsClient,
148
+ init,
149
+ experiment: () => experiment?.experiment,
150
+ sessionReplay: () => sessionReplay,
151
+ };
152
+ };
package/src/version.ts ADDED
@@ -0,0 +1,2 @@
1
+ // Autogenerated by `pnpm version-file`. DO NOT EDIT
2
+ export const VERSION = '1.0.0-beta.0';