Browse Source

fix(rn,amplitude) update Amplitude SDK on RN

Amplitude has gone back to having a separate package for RN, so switch to it.
master
Saúl Ibarra Corretgé 3 years ago
parent
commit
08177af182
No account linked to committer's email address

+ 1
- 0
android/sdk/build.gradle View File

@@ -56,6 +56,7 @@ dependencies {
56 56
             exclude group: 'com.android.installreferrer'
57 57
         }
58 58
     } else {
59
+        implementation project(':amplitudereactnative')
59 60
         implementation project(':react-native-device-info')
60 61
         implementation(project(":react-native-google-signin")) {
61 62
             exclude group: 'com.google.android.gms'

+ 10
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/ReactInstanceManagerHolder.java View File

@@ -203,6 +203,16 @@ class ReactInstanceManagerHolder {
203 203
                     }
204 204
                 }));
205 205
 
206
+        // AmplitudeReactNativePackage
207
+        try {
208
+            Class<?> amplitudePackageClass = Class.forName("com.amplitude.reactnative.AmplitudeReactNativePackage");
209
+            Constructor constructor = amplitudePackageClass.getConstructor();
210
+            packages.add((ReactPackage)constructor.newInstance());
211
+        } catch (Exception e) {
212
+            // Ignore any error, the module is not compiled when LIBRE_BUILD is enabled.
213
+        }
214
+
215
+        // RNGoogleSigninPackage
206 216
         try {
207 217
             Class<?> googlePackageClass = Class.forName("co.apptailor.googlesignin.RNGoogleSigninPackage");
208 218
             Constructor constructor = googlePackageClass.getConstructor();

+ 2
- 0
android/settings.gradle View File

@@ -1,6 +1,8 @@
1 1
 rootProject.name = 'jitsi-meet'
2 2
 
3 3
 include ':app', ':sdk'
4
+include ':amplitudereactnative'
5
+project(':amplitudereactnative').projectDir = new File(rootProject.projectDir, '../node_modules/@amplitude/react-native//android')
4 6
 include ':react-native-async-storage'
5 7
 project(':react-native-async-storage').projectDir = new File(rootProject.projectDir, '../node_modules/@react-native-async-storage/async-storage/android')
6 8
 include ':react-native-background-timer'

+ 2
- 1
ios/Podfile View File

@@ -29,7 +29,7 @@ target 'JitsiMeetSDK' do
29 29
     'CoreModulesHeaders',
30 30
     'DevSupport',
31 31
     'RCTWebSocket'
32
-  ]
32
+  ], :modular_headers => true
33 33
   pod 'React-CoreModules', :path => '../node_modules/react-native/React/CoreModules'
34 34
   pod 'React-RCTActionSheet', :path => '../node_modules/react-native/Libraries/ActionSheetIOS'
35 35
   pod 'React-RCTAnimation', :path => '../node_modules/react-native/Libraries/NativeAnimation'
@@ -54,6 +54,7 @@ target 'JitsiMeetSDK' do
54 54
   # React Native plugins
55 55
   #
56 56
 
57
+  pod 'amplitude-react-native', :path => '../node_modules/@amplitude/react-native'
57 58
   pod 'react-native-background-timer', :path => '../node_modules/react-native-background-timer'
58 59
   pod 'react-native-calendar-events', :path => '../node_modules/react-native-calendar-events'
59 60
   pod 'react-native-keep-awake', :path => '../node_modules/react-native-keep-awake'

+ 11
- 1
ios/Podfile.lock View File

@@ -1,4 +1,8 @@
1 1
 PODS:
2
+  - Amplitude (8.2.0)
3
+  - amplitude-react-native (2.3.3):
4
+    - Amplitude (= 8.2.0)
5
+    - React-Core
2 6
   - AppAuth (1.4.0):
3 7
     - AppAuth/Core (= 1.4.0)
4 8
     - AppAuth/ExternalUserAgent (= 1.4.0)
@@ -372,6 +376,7 @@ PODS:
372 376
   - Yoga (1.14.0)
373 377
 
374 378
 DEPENDENCIES:
379
+  - "amplitude-react-native (from `../node_modules/@amplitude/react-native`)"
375 380
   - CocoaLumberjack (~> 3.5.3)
376 381
   - DoubleConversion (from `../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec`)
377 382
   - FBLazyVector (from `../node_modules/react-native/Libraries/FBLazyVector/`)
@@ -423,6 +428,7 @@ DEPENDENCIES:
423 428
 
424 429
 SPEC REPOS:
425 430
   trunk:
431
+    - Amplitude
426 432
     - AppAuth
427 433
     - boost-for-react-native
428 434
     - CocoaLumberjack
@@ -444,6 +450,8 @@ SPEC REPOS:
444 450
     - PromisesObjC
445 451
 
446 452
 EXTERNAL SOURCES:
453
+  amplitude-react-native:
454
+    :path: "../node_modules/@amplitude/react-native"
447 455
   DoubleConversion:
448 456
     :podspec: "../node_modules/react-native/third-party-podspecs/DoubleConversion.podspec"
449 457
   FBLazyVector:
@@ -528,6 +536,8 @@ EXTERNAL SOURCES:
528 536
     :path: "../node_modules/react-native/ReactCommon/yoga"
529 537
 
530 538
 SPEC CHECKSUMS:
539
+  Amplitude: 263118b9e691e73a1c864b05bb08a3aff3636d16
540
+  amplitude-react-native: 833a4bd7f656f826bda1de01a7b8593b58842209
531 541
   AppAuth: 31bcec809a638d7bd2f86ea8a52bd45f6e81e7c7
532 542
   boost-for-react-native: 39c7adb57c4e60d6c5479dd8623128eb5b3f0f2c
533 543
   CocoaLumberjack: 2f44e60eb91c176d471fdba43b9e3eae6a721947
@@ -589,6 +599,6 @@ SPEC CHECKSUMS:
589 599
   RNWatch: a5320c959c75e72845c07985f3e935e58998f1d3
590 600
   Yoga: 96b469c5e81ff51b917b92e8c3390642d4ded30c
591 601
 
592
-PODFILE CHECKSUM: f4db44d934caeae7212dbaa33abe62ed164363e8
602
+PODFILE CHECKSUM: 1ae1a9823f3eab0b6e735b9637ba7588e0890d08
593 603
 
594 604
 COCOAPODS: 1.10.1

+ 2
- 0
ios/sdk/sdk.xcodeproj/project.pbxproj View File

@@ -437,10 +437,12 @@
437 437
 			);
438 438
 			inputPaths = (
439 439
 				"${PODS_ROOT}/Target Support Files/Pods-JitsiMeetSDK/Pods-JitsiMeetSDK-resources.sh",
440
+				"${PODS_ROOT}/Amplitude/Sources/Amplitude/Resources/ComodoRsaDomainValidationCA.der",
440 441
 				"${PODS_ROOT}/GoogleSignIn/Resources/GoogleSignIn.bundle",
441 442
 			);
442 443
 			name = "[CP] Copy Pods Resources";
443 444
 			outputPaths = (
445
+				"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/ComodoRsaDomainValidationCA.der",
444 446
 				"${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/GoogleSignIn.bundle",
445 447
 			);
446 448
 			runOnlyForDeploymentPostprocessing = 0;

+ 5
- 0
package-lock.json View File

@@ -4,6 +4,11 @@
4 4
   "lockfileVersion": 1,
5 5
   "requires": true,
6 6
   "dependencies": {
7
+    "@amplitude/react-native": {
8
+      "version": "2.3.3",
9
+      "resolved": "https://registry.npmjs.org/@amplitude/react-native/-/react-native-2.3.3.tgz",
10
+      "integrity": "sha512-QTpwy4lKy9kpBjB2334HCEIU7QwGFAkGRfp21aeDA87D6pkiUMAvyDYbz58CnB5HCXuqcvws3GN8d60RO9KF9A=="
11
+    },
7 12
     "@amplitude/types": {
8 13
       "version": "1.5.5",
9 14
       "resolved": "https://registry.npmjs.org/@amplitude/types/-/types-1.5.5.tgz",

+ 1
- 0
package.json View File

@@ -15,6 +15,7 @@
15 15
   "author": "",
16 16
   "readmeFilename": "README.md",
17 17
   "dependencies": {
18
+    "@amplitude/react-native": "2.3.3",
18 19
     "@atlaskit/button": "15.1.4",
19 20
     "@atlaskit/checkbox": "12.0.0",
20 21
     "@atlaskit/dropdown-menu": "10.1.2",

+ 33
- 29
react/features/analytics/handlers/AmplitudeHandler.js View File

@@ -1,9 +1,8 @@
1
-import amplitude from 'amplitude-js';
2
-
3 1
 import logger from '../logger';
4 2
 
5 3
 import AbstractHandler from './AbstractHandler';
6
-import { fixDeviceID } from './amplitude';
4
+import { fixDeviceID } from './amplitude/fixDeviceID';
5
+import amplitude from './amplitude/lib';
7 6
 
8 7
 /**
9 8
  * Analytics handler for Amplitude.
@@ -19,41 +18,39 @@ export default class AmplitudeHandler extends AbstractHandler {
19 18
     constructor(options) {
20 19
         super(options);
21 20
 
22
-        const { amplitudeAPPKey, host, user } = options;
21
+        const { amplitudeAPPKey, user } = options;
23 22
 
24 23
         this._enabled = true;
25
-        this._host = host; // Only used on React Native.
26 24
 
27 25
         const onError = e => {
28 26
             logger.error('Error initializing Amplitude', e);
29 27
             this._enabled = false;
30 28
         };
31 29
 
32
-        const amplitudeOptions = {
33
-            domain: navigator.product === 'ReactNative' ? host : undefined,
34
-            includeReferrer: true,
35
-            onError
36
-        };
30
+        if (navigator.product === 'ReactNative') {
31
+            amplitude.getInstance().init(amplitudeAPPKey);
32
+            fixDeviceID(amplitude.getInstance()).then(() => {
33
+                amplitude.getInstance().getDeviceId()
34
+                    .then(deviceId => {
35
+                        this._deviceId = deviceId;
36
+                    });
37
+            });
38
+        } else {
39
+            const amplitudeOptions = {
40
+                includeReferrer: true,
41
+                onError
42
+            };
37 43
 
38
-        this._getInstance().init(amplitudeAPPKey, undefined, amplitudeOptions);
39
-        fixDeviceID(this._getInstance());
44
+            amplitude.getInstance().init(amplitudeAPPKey, undefined, amplitudeOptions);
45
+            fixDeviceID(amplitude.getInstance());
46
+        }
40 47
 
41 48
         if (user) {
42
-            this._getInstance().setUserId(user);
49
+            this._userId = user;
50
+            amplitude.getInstance().setUserId(user);
43 51
         }
44 52
     }
45 53
 
46
-    /**
47
-     * Returns the AmplitudeClient instance.
48
-     *
49
-     * @returns {AmplitudeClient}
50
-     */
51
-    _getInstance() {
52
-        const name = navigator.product === 'ReactNative' ? this._host : undefined;
53
-
54
-        return amplitude.getInstance(name);
55
-    }
56
-
57 54
     /**
58 55
      * Sets the Amplitude user properties.
59 56
      *
@@ -62,7 +59,7 @@ export default class AmplitudeHandler extends AbstractHandler {
62 59
      */
63 60
     setUserProperties(userProps) {
64 61
         if (this._enabled) {
65
-            this._getInstance().setUserProperties(userProps);
62
+            amplitude.getInstance().setUserProperties(userProps);
66 63
         }
67 64
     }
68 65
 
@@ -79,7 +76,7 @@ export default class AmplitudeHandler extends AbstractHandler {
79 76
             return;
80 77
         }
81 78
 
82
-        this._getInstance().logEvent(this._extractName(event), event);
79
+        amplitude.getInstance().logEvent(this._extractName(event), event);
83 80
     }
84 81
 
85 82
     /**
@@ -88,10 +85,17 @@ export default class AmplitudeHandler extends AbstractHandler {
88 85
      * @returns {Object}
89 86
      */
90 87
     getIdentityProps() {
88
+        if (navigator.product === 'ReactNative') {
89
+            return {
90
+                deviceId: this._deviceId,
91
+                userId: this._userId
92
+            };
93
+        }
94
+
91 95
         return {
92
-            sessionId: this._getInstance().getSessionId(),
93
-            deviceId: this._getInstance().options.deviceId,
94
-            userId: this._getInstance().options.userId
96
+            sessionId: amplitude.getInstance().getSessionId(),
97
+            deviceId: amplitude.getInstance().options.deviceId,
98
+            userId: amplitude.getInstance().options.userId
95 99
         };
96 100
     }
97 101
 }

+ 0
- 1
react/features/analytics/handlers/amplitude/index.js View File

@@ -1 +0,0 @@
1
-export * from './fixDeviceID';

+ 3
- 0
react/features/analytics/handlers/amplitude/lib.native.js View File

@@ -0,0 +1,3 @@
1
+import { Amplitude } from '@amplitude/react-native';
2
+
3
+export default Amplitude;

+ 3
- 0
react/features/analytics/handlers/amplitude/lib.web.js View File

@@ -0,0 +1,3 @@
1
+import amplitude from 'amplitude-js';
2
+
3
+export default amplitude;

Loading…
Cancel
Save