Skip to content

Commit 405f774

Browse files
Merge pull request bitpay#396 from cnguyen812/feat/upgrade-segment-sdk
Feat/upgrade segment sdk
2 parents b1f446d + 673a201 commit 405f774

File tree

12 files changed

+332
-143
lines changed

12 files changed

+332
-143
lines changed

android/app/build.gradle

-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ dependencies {
231231
exclude group:'com.squareup.okhttp3', module:'okhttp'
232232
}
233233

234-
implementation project(':react-native-advertising-id-bp')
235234
// AppsFlyer
236235
compile project(':react-native-appsflyer')
237236
// Dosh SDK requires updated okhttp version

android/app/src/main/AndroidManifest.xml

-4
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,6 @@
4545
android:name="com.google.android.gms.wallet.api.enabled"
4646
android:value="true" />
4747

48-
<meta-data
49-
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
50-
android:value="true"/>
51-
5248
<activity
5349
android:screenOrientation="portrait"
5450
android:name=".MainActivity"

android/app/src/main/java/com/bitpay/wallet/MainApplication.java

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.List;
1414
import com.facebook.react.bridge.JSIModulePackage;
1515
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
16-
import info.applike.advertisingid.RNAdvertisingIdPackage;
1716

1817
// Register custom font
1918
import com.facebook.react.views.text.ReactFontManager;

android/settings.gradle

-2
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@ include ':react-native-haptic-feedback'
55
project(':react-native-haptic-feedback').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-haptic-feedback/android')
66
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
77
include ':app'
8-
include ':react-native-advertising-id-bp'
9-
project(':react-native-advertising-id-bp').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-advertising-id-bp/android')

declarations.d.ts

-7
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,3 @@ declare module '@env' {
1414
export const SEGMENT_API_KEY: string;
1515
export const GIT_COMMIT_HASH: string;
1616
}
17-
18-
declare module 'react-native-advertising-id-bp' {
19-
export const getAdvertisingId: () => Promise<{
20-
advertisingId: string;
21-
isLimitAdTrackingEnabled: boolean;
22-
}>;
23-
}

index.js

+1-6
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {name as appName} from './app.json';
77
import getStore from './src/store';
88
import {Provider} from 'react-redux';
99
import {PersistGate} from 'redux-persist/integration/react';
10-
import StorybookUIRoot from './storybook';
11-
import {APP_LOAD_STORY_BOOK} from './src/constants/config';
1210
import 'react-native-url-polyfill/auto'; // https://github.com/facebook/react-native/issues/23922#issuecomment-648096619
1311

1412
export const {store, persistor} = getStore();
@@ -17,10 +15,7 @@ const ReduxProvider = () => {
1715
return (
1816
<Provider store={store}>
1917
<PersistGate loading={null} persistor={persistor}>
20-
{storeRehydrated =>
21-
storeRehydrated &&
22-
(__DEV__ && APP_LOAD_STORY_BOOK ? <StorybookUIRoot /> : <Root />)
23-
}
18+
{storeRehydrated => (storeRehydrated ? <Root /> : null)}
2419
</PersistGate>
2520
</Provider>
2621
);

ios/Podfile.lock

+21-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
PODS:
2-
- Analytics (4.1.6)
32
- Appboy-iOS-SDK (4.5.0):
43
- Appboy-iOS-SDK/UI (= 4.5.0)
54
- Appboy-iOS-SDK/ContentCards (4.5.0):
@@ -385,8 +384,6 @@ PODS:
385384
- React-jsinspector (0.67.4)
386385
- React-logger (0.67.4):
387386
- glog
388-
- react-native-advertising-id-bp (1.0.13):
389-
- React
390387
- react-native-appboy-sdk (1.38.0):
391388
- Appboy-iOS-SDK (~> 4.5.0)
392389
- React
@@ -495,12 +492,9 @@ PODS:
495492
- React-jsi (= 0.67.4)
496493
- React-logger (= 0.67.4)
497494
- React-perflogger (= 0.67.4)
498-
- RNAnalytics (1.5.2):
499-
- Analytics
500-
- React-Core
501495
- RNBootSplash (3.2.6):
502496
- React-Core
503-
- RNCAsyncStorage (1.15.14):
497+
- RNCAsyncStorage (1.17.10):
504498
- React-Core
505499
- RNCClipboard (1.5.1):
506500
- React-Core
@@ -568,7 +562,14 @@ PODS:
568562
- SDWebImageWebPCoder (0.8.4):
569563
- libwebp (~> 1.0)
570564
- SDWebImage/Core (~> 5.10)
565+
- segment-analytics-react-native (2.7.1):
566+
- React-Core
567+
- sovran-react-native
568+
- segment-analytics-react-native-plugin-idfa (0.4.1):
569+
- React-Core
571570
- SocketRocket (0.6.0)
571+
- sovran-react-native (0.4.4):
572+
- React-Core
572573
- TouchID (5.0.1):
573574
- React
574575
- Yoga (1.14.0)
@@ -623,7 +624,6 @@ DEPENDENCIES:
623624
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
624625
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
625626
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
626-
- react-native-advertising-id-bp (from `../node_modules/react-native-advertising-id-bp`)
627627
- react-native-appboy-sdk (from `../node_modules/react-native-appboy-sdk`)
628628
- react-native-appsflyer (from `../node_modules/react-native-appsflyer`)
629629
- "react-native-blur (from `../node_modules/@react-native-community/blur`)"
@@ -651,7 +651,6 @@ DEPENDENCIES:
651651
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
652652
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
653653
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
654-
- "RNAnalytics (from `../node_modules/@segment/analytics-react-native`)"
655654
- RNBootSplash (from `../node_modules/react-native-bootsplash`)
656655
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
657656
- "RNCClipboard (from `../node_modules/@react-native-community/clipboard`)"
@@ -670,12 +669,14 @@ DEPENDENCIES:
670669
- RNScreens (from `../node_modules/react-native-screens`)
671670
- RNSharedElement (from `../node_modules/react-native-shared-element`)
672671
- RNSVG (from `../node_modules/react-native-svg`)
672+
- "segment-analytics-react-native (from `../node_modules/@segment/analytics-react-native`)"
673+
- "segment-analytics-react-native-plugin-idfa (from `../node_modules/@segment/analytics-react-native-plugin-idfa`)"
674+
- "sovran-react-native (from `../node_modules/@segment/sovran-react-native`)"
673675
- TouchID (from `../node_modules/react-native-touch-id-ng`)
674676
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)
675677

676678
SPEC REPOS:
677679
trunk:
678-
- Analytics
679680
- Appboy-iOS-SDK
680681
- AppsFlyerFramework
681682
- CocoaAsyncSocket
@@ -754,8 +755,6 @@ EXTERNAL SOURCES:
754755
:path: "../node_modules/react-native/ReactCommon/jsinspector"
755756
React-logger:
756757
:path: "../node_modules/react-native/ReactCommon/logger"
757-
react-native-advertising-id-bp:
758-
:path: "../node_modules/react-native-advertising-id-bp"
759758
react-native-appboy-sdk:
760759
:path: "../node_modules/react-native-appboy-sdk"
761760
react-native-appsflyer:
@@ -810,8 +809,6 @@ EXTERNAL SOURCES:
810809
:path: "../node_modules/react-native/ReactCommon/runtimeexecutor"
811810
ReactCommon:
812811
:path: "../node_modules/react-native/ReactCommon"
813-
RNAnalytics:
814-
:path: "../node_modules/@segment/analytics-react-native"
815812
RNBootSplash:
816813
:path: "../node_modules/react-native-bootsplash"
817814
RNCAsyncStorage:
@@ -848,13 +845,18 @@ EXTERNAL SOURCES:
848845
:path: "../node_modules/react-native-shared-element"
849846
RNSVG:
850847
:path: "../node_modules/react-native-svg"
848+
segment-analytics-react-native:
849+
:path: "../node_modules/@segment/analytics-react-native"
850+
segment-analytics-react-native-plugin-idfa:
851+
:path: "../node_modules/@segment/analytics-react-native-plugin-idfa"
852+
sovran-react-native:
853+
:path: "../node_modules/@segment/sovran-react-native"
851854
TouchID:
852855
:path: "../node_modules/react-native-touch-id-ng"
853856
Yoga:
854857
:path: "../node_modules/react-native/ReactCommon/yoga"
855858

856859
SPEC CHECKSUMS:
857-
Analytics: eefe524436f904b8bb3f8c8c3425280e43b34efc
858860
Appboy-iOS-SDK: 640c2d51cec128008da5c4c680df3d76e8c137bc
859861
AppsFlyerFramework: 9f304d91cc80b6579b1206a59220383056b58b47
860862
boost: a7c83b31436843459a1961bfd74b96033dc77234
@@ -907,7 +909,6 @@ SPEC CHECKSUMS:
907909
React-jsiexecutor: cbdf37cebdc4f5d8b3d0bf5ccaa6147fd9de9f3d
908910
React-jsinspector: f4775ea9118cbe1f72b834f0f842baa7a99508d8
909911
React-logger: a1f028f6d8639a3f364ef80419e5e862e1115250
910-
react-native-advertising-id-bp: e14b0f4622895d3db1ecb1041f7eb262f8b53d4b
911912
react-native-appboy-sdk: fda756a8584dcb328be47c76a34d896dea84da91
912913
react-native-appsflyer: fac6d94b40ce52dc69a07c242317b83c7b9e0cc2
913914
react-native-blur: cad4d93b364f91e7b7931b3fa935455487e5c33c
@@ -935,9 +936,8 @@ SPEC CHECKSUMS:
935936
React-RCTVibration: 3b52a7dced19cdb025b4f88ab26ceb2d85f30ba2
936937
React-runtimeexecutor: a9d3c82ddf7ffdad9fbe6a81c6d6f8c06385464d
937938
ReactCommon: 07d0c460b9ba9af3eaf1b8f5abe7daaad28c9c4e
938-
RNAnalytics: fcf308eeac6d34a74c158ec74d733c877f26fb96
939939
RNBootSplash: 51eef7e143faeab63f81ddbb7c1de38b8fba66ed
940-
RNCAsyncStorage: ea6b5c280997b2b32a587793163b1f10e580c4f7
940+
RNCAsyncStorage: 0c357f3156fcb16c8589ede67cc036330b6698ca
941941
RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495
942942
RNCMaskedView: c298b644a10c0c142055b3ae24d83879ecb13ccd
943943
RNDeviceInfo: b32d24c84e40d54b736e62a7d2abd15e1225258d
@@ -956,7 +956,10 @@ SPEC CHECKSUMS:
956956
RNSVG: 302bfc9905bd8122f08966dc2ce2d07b7b52b9f8
957957
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
958958
SDWebImageWebPCoder: f93010f3f6c031e2f8fb3081ca4ee6966c539815
959+
segment-analytics-react-native: d3600ae853119d465d7f5b5884ef1c776796138a
960+
segment-analytics-react-native-plugin-idfa: 68fbc668f277eaf2e1e2673c6a5543ea857a1671
959961
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
962+
sovran-react-native: 5f9715a62b50008d72c0cf904cb08c8377777b62
960963
TouchID: 175fa9c0b2b2651f25aaef4aa6bb42ce4d580c6e
961964
Yoga: d6b6a80659aa3e91aaba01d0012e7edcbedcbecd
962965
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a

package.json

+5-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"dependencies": {
3939
"@freakycoder/react-native-bounceable": "0.2.5",
4040
"@hookform/resolvers": "2.8.3",
41-
"@react-native-async-storage/async-storage": "1.15.14",
41+
"@react-native-async-storage/async-storage": "1.17.10",
4242
"@react-native-community/blur": "3.6.0",
4343
"@react-native-community/clipboard": "1.5.1",
4444
"@react-native-community/slider": "4.2.4",
@@ -47,7 +47,10 @@
4747
"@react-navigation/material-top-tabs": "6.0.6",
4848
"@react-navigation/native": "6.0.6",
4949
"@react-navigation/stack": "6.0.11",
50-
"@segment/analytics-react-native": "^1.5.0",
50+
"@segment/analytics-react-native": "2.7.1",
51+
"@segment/analytics-react-native-plugin-appsflyer": "0.4.0",
52+
"@segment/analytics-react-native-plugin-idfa": "0.4.1",
53+
"@segment/sovran-react-native": "0.4.4",
5154
"@tradle/react-native-http": "2.0.1",
5255
"@types/lodash.pickby": "4.6.6",
5356
"@types/lodash.sortby": "4.7.6",
@@ -80,7 +83,6 @@
8083
"react-hook-form": "7.19.5",
8184
"react-i18next": "11.15.2",
8285
"react-native": "0.67.4",
83-
"react-native-advertising-id-bp": "1.0.13",
8486
"react-native-appboy-sdk": "1.38.0",
8587
"react-native-appsflyer": "6.5.20",
8688
"react-native-bootsplash": "3.2.6",

src/lib/segment/index.ts

+132
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
import {SEGMENT_API_KEY} from '@env';
2+
import {
3+
createClient,
4+
JsonMap,
5+
Plugin,
6+
SegmentClient,
7+
UserTraits,
8+
} from '@segment/analytics-react-native';
9+
import {AppsflyerPlugin} from '@segment/analytics-react-native-plugin-appsflyer';
10+
import {IdfaPlugin} from '@segment/analytics-react-native-plugin-idfa';
11+
import {IS_IOS} from '../../constants';
12+
import {APP_ANALYTICS_ENABLED} from '../../constants/config';
13+
14+
/**
15+
* Client wrapper for the Segment SDK configured for use with the BitPay app.
16+
* Must call `init()` before any other methods.
17+
*/
18+
const lib = (() => {
19+
let _client: SegmentClient | null = null;
20+
21+
const _addPluginsToClient = (client: SegmentClient) => {
22+
const SEGMENT_PLUGINS: Plugin[] = [new AppsflyerPlugin()];
23+
24+
if (IS_IOS) {
25+
SEGMENT_PLUGINS.push(new IdfaPlugin());
26+
}
27+
28+
SEGMENT_PLUGINS.forEach(plugin => {
29+
client.add({plugin});
30+
});
31+
};
32+
33+
/**
34+
* Guard wrapper that checks if analytics are enabled and client has been initialized before executing the provided callback.
35+
* @param cb Function to execute if all guards pass.
36+
* @returns Resolves if analytics disabled, rejects if client uninitialized, else returns the callback's return value;
37+
*/
38+
const guard = <T>(
39+
cb: (client: SegmentClient) => Promise<T>,
40+
): Promise<T | void> => {
41+
if (!APP_ANALYTICS_ENABLED) {
42+
return Promise.resolve();
43+
}
44+
45+
if (!_client) {
46+
return Promise.reject('Uninitialized');
47+
}
48+
49+
return cb(_client);
50+
};
51+
52+
return {
53+
/**
54+
* Returns an instance of the underlying Segment SDK client, or null if not initialized.
55+
* @returns {SegmentClient | null} The Segment SDK client.
56+
*/
57+
client(): SegmentClient | null {
58+
return _client;
59+
},
60+
61+
/**
62+
* Creates and initializes the Segment SDK. Must be called first.
63+
*/
64+
init() {
65+
if (!APP_ANALYTICS_ENABLED) {
66+
return;
67+
}
68+
69+
if (_client) {
70+
return;
71+
}
72+
73+
_client = createClient({
74+
// Required ---------------
75+
76+
/**
77+
* The Segment write key.
78+
*/
79+
writeKey: SEGMENT_API_KEY,
80+
81+
// Optional ---------------
82+
83+
/**
84+
* When set to false, logs don’t generate.
85+
*/
86+
debug: !!__DEV__, // default: true
87+
88+
/**
89+
* Track app lifecycle events, such as application installed, opened, updated, backgrounded.
90+
*/
91+
trackAppLifecycleEvents: true, // default: false
92+
});
93+
94+
_addPluginsToClient(_client);
95+
},
96+
97+
/**
98+
* Ties a user to their actions and records traits about them.
99+
*
100+
* https://segment.com/docs/connections/spec/identify/
101+
* @param userId Unique identifier for the user in your database.
102+
* @param traits Free-form dictionary of traits of the user, like `email` or `name`.
103+
*/
104+
identify(userId?: string | undefined, traits?: UserTraits | undefined) {
105+
return guard(client => client.identify(userId, traits));
106+
},
107+
108+
/**
109+
* Record whenever a user sees a screen, the mobile equivalent of `page`.
110+
*
111+
* https://segment.com/docs/connections/spec/screen/
112+
* @param name Name of the screen.
113+
* @param properties Free-form dictionary of properties of the screen, like `name`.
114+
*/
115+
screen(name: string, properties?: JsonMap | undefined) {
116+
return guard(client => client.screen(name, properties));
117+
},
118+
119+
/**
120+
* Record any actions your users perform, along with any properties that describe the action.
121+
*
122+
* https://segment.com/docs/connections/spec/track/
123+
* @param event Name of the action that a user has performed.
124+
* @param properties Free-form dictionary of properties of the event, like `revenue`.
125+
*/
126+
track(event: string, properties?: JsonMap | undefined) {
127+
return guard(client => client.track(event, properties));
128+
},
129+
};
130+
})();
131+
132+
export default lib;

0 commit comments

Comments
 (0)