Skip to content

Commit

Permalink
Merge pull request #396 from cnguyen812/feat/upgrade-segment-sdk
Browse files Browse the repository at this point in the history
Feat/upgrade segment sdk
  • Loading branch information
JohnathanWhite authored Sep 12, 2022
2 parents b1f446d + 673a201 commit 405f774
Show file tree
Hide file tree
Showing 12 changed files with 332 additions and 143 deletions.
1 change: 0 additions & 1 deletion android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,6 @@ dependencies {
exclude group:'com.squareup.okhttp3', module:'okhttp'
}

implementation project(':react-native-advertising-id-bp')
// AppsFlyer
compile project(':react-native-appsflyer')
// Dosh SDK requires updated okhttp version
Expand Down
4 changes: 0 additions & 4 deletions android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,6 @@
android:name="com.google.android.gms.wallet.api.enabled"
android:value="true" />

<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true"/>

<activity
android:screenOrientation="portrait"
android:name=".MainActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import java.util.List;
import com.facebook.react.bridge.JSIModulePackage;
import com.swmansion.reanimated.ReanimatedJSIModulePackage;
import info.applike.advertisingid.RNAdvertisingIdPackage;

// Register custom font
import com.facebook.react.views.text.ReactFontManager;
Expand Down
2 changes: 0 additions & 2 deletions android/settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,3 @@ include ':react-native-haptic-feedback'
project(':react-native-haptic-feedback').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-haptic-feedback/android')
apply from: file("../node_modules/@react-native-community/cli-platform-android/native_modules.gradle"); applyNativeModulesSettingsGradle(settings)
include ':app'
include ':react-native-advertising-id-bp'
project(':react-native-advertising-id-bp').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-advertising-id-bp/android')
7 changes: 0 additions & 7 deletions declarations.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,3 @@ declare module '@env' {
export const SEGMENT_API_KEY: string;
export const GIT_COMMIT_HASH: string;
}

declare module 'react-native-advertising-id-bp' {
export const getAdvertisingId: () => Promise<{
advertisingId: string;
isLimitAdTrackingEnabled: boolean;
}>;
}
7 changes: 1 addition & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import {name as appName} from './app.json';
import getStore from './src/store';
import {Provider} from 'react-redux';
import {PersistGate} from 'redux-persist/integration/react';
import StorybookUIRoot from './storybook';
import {APP_LOAD_STORY_BOOK} from './src/constants/config';
import 'react-native-url-polyfill/auto'; // https://github.com/facebook/react-native/issues/23922#issuecomment-648096619

export const {store, persistor} = getStore();
Expand All @@ -17,10 +15,7 @@ const ReduxProvider = () => {
return (
<Provider store={store}>
<PersistGate loading={null} persistor={persistor}>
{storeRehydrated =>
storeRehydrated &&
(__DEV__ && APP_LOAD_STORY_BOOK ? <StorybookUIRoot /> : <Root />)
}
{storeRehydrated => (storeRehydrated ? <Root /> : null)}
</PersistGate>
</Provider>
);
Expand Down
39 changes: 21 additions & 18 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
PODS:
- Analytics (4.1.6)
- Appboy-iOS-SDK (4.5.0):
- Appboy-iOS-SDK/UI (= 4.5.0)
- Appboy-iOS-SDK/ContentCards (4.5.0):
Expand Down Expand Up @@ -385,8 +384,6 @@ PODS:
- React-jsinspector (0.67.4)
- React-logger (0.67.4):
- glog
- react-native-advertising-id-bp (1.0.13):
- React
- react-native-appboy-sdk (1.38.0):
- Appboy-iOS-SDK (~> 4.5.0)
- React
Expand Down Expand Up @@ -495,12 +492,9 @@ PODS:
- React-jsi (= 0.67.4)
- React-logger (= 0.67.4)
- React-perflogger (= 0.67.4)
- RNAnalytics (1.5.2):
- Analytics
- React-Core
- RNBootSplash (3.2.6):
- React-Core
- RNCAsyncStorage (1.15.14):
- RNCAsyncStorage (1.17.10):
- React-Core
- RNCClipboard (1.5.1):
- React-Core
Expand Down Expand Up @@ -568,7 +562,14 @@ PODS:
- SDWebImageWebPCoder (0.8.4):
- libwebp (~> 1.0)
- SDWebImage/Core (~> 5.10)
- segment-analytics-react-native (2.7.1):
- React-Core
- sovran-react-native
- segment-analytics-react-native-plugin-idfa (0.4.1):
- React-Core
- SocketRocket (0.6.0)
- sovran-react-native (0.4.4):
- React-Core
- TouchID (5.0.1):
- React
- Yoga (1.14.0)
Expand Down Expand Up @@ -623,7 +624,6 @@ DEPENDENCIES:
- React-jsiexecutor (from `../node_modules/react-native/ReactCommon/jsiexecutor`)
- React-jsinspector (from `../node_modules/react-native/ReactCommon/jsinspector`)
- React-logger (from `../node_modules/react-native/ReactCommon/logger`)
- react-native-advertising-id-bp (from `../node_modules/react-native-advertising-id-bp`)
- react-native-appboy-sdk (from `../node_modules/react-native-appboy-sdk`)
- react-native-appsflyer (from `../node_modules/react-native-appsflyer`)
- "react-native-blur (from `../node_modules/@react-native-community/blur`)"
Expand Down Expand Up @@ -651,7 +651,6 @@ DEPENDENCIES:
- React-RCTVibration (from `../node_modules/react-native/Libraries/Vibration`)
- React-runtimeexecutor (from `../node_modules/react-native/ReactCommon/runtimeexecutor`)
- ReactCommon/turbomodule/core (from `../node_modules/react-native/ReactCommon`)
- "RNAnalytics (from `../node_modules/@segment/analytics-react-native`)"
- RNBootSplash (from `../node_modules/react-native-bootsplash`)
- "RNCAsyncStorage (from `../node_modules/@react-native-async-storage/async-storage`)"
- "RNCClipboard (from `../node_modules/@react-native-community/clipboard`)"
Expand All @@ -670,12 +669,14 @@ DEPENDENCIES:
- RNScreens (from `../node_modules/react-native-screens`)
- RNSharedElement (from `../node_modules/react-native-shared-element`)
- RNSVG (from `../node_modules/react-native-svg`)
- "segment-analytics-react-native (from `../node_modules/@segment/analytics-react-native`)"
- "segment-analytics-react-native-plugin-idfa (from `../node_modules/@segment/analytics-react-native-plugin-idfa`)"
- "sovran-react-native (from `../node_modules/@segment/sovran-react-native`)"
- TouchID (from `../node_modules/react-native-touch-id-ng`)
- Yoga (from `../node_modules/react-native/ReactCommon/yoga`)

SPEC REPOS:
trunk:
- Analytics
- Appboy-iOS-SDK
- AppsFlyerFramework
- CocoaAsyncSocket
Expand Down Expand Up @@ -754,8 +755,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/jsinspector"
React-logger:
:path: "../node_modules/react-native/ReactCommon/logger"
react-native-advertising-id-bp:
:path: "../node_modules/react-native-advertising-id-bp"
react-native-appboy-sdk:
:path: "../node_modules/react-native-appboy-sdk"
react-native-appsflyer:
Expand Down Expand Up @@ -810,8 +809,6 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native/ReactCommon/runtimeexecutor"
ReactCommon:
:path: "../node_modules/react-native/ReactCommon"
RNAnalytics:
:path: "../node_modules/@segment/analytics-react-native"
RNBootSplash:
:path: "../node_modules/react-native-bootsplash"
RNCAsyncStorage:
Expand Down Expand Up @@ -848,13 +845,18 @@ EXTERNAL SOURCES:
:path: "../node_modules/react-native-shared-element"
RNSVG:
:path: "../node_modules/react-native-svg"
segment-analytics-react-native:
:path: "../node_modules/@segment/analytics-react-native"
segment-analytics-react-native-plugin-idfa:
:path: "../node_modules/@segment/analytics-react-native-plugin-idfa"
sovran-react-native:
:path: "../node_modules/@segment/sovran-react-native"
TouchID:
:path: "../node_modules/react-native-touch-id-ng"
Yoga:
:path: "../node_modules/react-native/ReactCommon/yoga"

SPEC CHECKSUMS:
Analytics: eefe524436f904b8bb3f8c8c3425280e43b34efc
Appboy-iOS-SDK: 640c2d51cec128008da5c4c680df3d76e8c137bc
AppsFlyerFramework: 9f304d91cc80b6579b1206a59220383056b58b47
boost: a7c83b31436843459a1961bfd74b96033dc77234
Expand Down Expand Up @@ -907,7 +909,6 @@ SPEC CHECKSUMS:
React-jsiexecutor: cbdf37cebdc4f5d8b3d0bf5ccaa6147fd9de9f3d
React-jsinspector: f4775ea9118cbe1f72b834f0f842baa7a99508d8
React-logger: a1f028f6d8639a3f364ef80419e5e862e1115250
react-native-advertising-id-bp: e14b0f4622895d3db1ecb1041f7eb262f8b53d4b
react-native-appboy-sdk: fda756a8584dcb328be47c76a34d896dea84da91
react-native-appsflyer: fac6d94b40ce52dc69a07c242317b83c7b9e0cc2
react-native-blur: cad4d93b364f91e7b7931b3fa935455487e5c33c
Expand Down Expand Up @@ -935,9 +936,8 @@ SPEC CHECKSUMS:
React-RCTVibration: 3b52a7dced19cdb025b4f88ab26ceb2d85f30ba2
React-runtimeexecutor: a9d3c82ddf7ffdad9fbe6a81c6d6f8c06385464d
ReactCommon: 07d0c460b9ba9af3eaf1b8f5abe7daaad28c9c4e
RNAnalytics: fcf308eeac6d34a74c158ec74d733c877f26fb96
RNBootSplash: 51eef7e143faeab63f81ddbb7c1de38b8fba66ed
RNCAsyncStorage: ea6b5c280997b2b32a587793163b1f10e580c4f7
RNCAsyncStorage: 0c357f3156fcb16c8589ede67cc036330b6698ca
RNCClipboard: 41d8d918092ae8e676f18adada19104fa3e68495
RNCMaskedView: c298b644a10c0c142055b3ae24d83879ecb13ccd
RNDeviceInfo: b32d24c84e40d54b736e62a7d2abd15e1225258d
Expand All @@ -956,7 +956,10 @@ SPEC CHECKSUMS:
RNSVG: 302bfc9905bd8122f08966dc2ce2d07b7b52b9f8
SDWebImage: a7f831e1a65eb5e285e3fb046a23fcfbf08e696d
SDWebImageWebPCoder: f93010f3f6c031e2f8fb3081ca4ee6966c539815
segment-analytics-react-native: d3600ae853119d465d7f5b5884ef1c776796138a
segment-analytics-react-native-plugin-idfa: 68fbc668f277eaf2e1e2673c6a5543ea857a1671
SocketRocket: fccef3f9c5cedea1353a9ef6ada904fde10d6608
sovran-react-native: 5f9715a62b50008d72c0cf904cb08c8377777b62
TouchID: 175fa9c0b2b2651f25aaef4aa6bb42ce4d580c6e
Yoga: d6b6a80659aa3e91aaba01d0012e7edcbedcbecd
YogaKit: f782866e155069a2cca2517aafea43200b01fd5a
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
"dependencies": {
"@freakycoder/react-native-bounceable": "0.2.5",
"@hookform/resolvers": "2.8.3",
"@react-native-async-storage/async-storage": "1.15.14",
"@react-native-async-storage/async-storage": "1.17.10",
"@react-native-community/blur": "3.6.0",
"@react-native-community/clipboard": "1.5.1",
"@react-native-community/slider": "4.2.4",
Expand All @@ -47,7 +47,10 @@
"@react-navigation/material-top-tabs": "6.0.6",
"@react-navigation/native": "6.0.6",
"@react-navigation/stack": "6.0.11",
"@segment/analytics-react-native": "^1.5.0",
"@segment/analytics-react-native": "2.7.1",
"@segment/analytics-react-native-plugin-appsflyer": "0.4.0",
"@segment/analytics-react-native-plugin-idfa": "0.4.1",
"@segment/sovran-react-native": "0.4.4",
"@tradle/react-native-http": "2.0.1",
"@types/lodash.pickby": "4.6.6",
"@types/lodash.sortby": "4.7.6",
Expand Down Expand Up @@ -80,7 +83,6 @@
"react-hook-form": "7.19.5",
"react-i18next": "11.15.2",
"react-native": "0.67.4",
"react-native-advertising-id-bp": "1.0.13",
"react-native-appboy-sdk": "1.38.0",
"react-native-appsflyer": "6.5.20",
"react-native-bootsplash": "3.2.6",
Expand Down
132 changes: 132 additions & 0 deletions src/lib/segment/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
import {SEGMENT_API_KEY} from '@env';
import {
createClient,
JsonMap,
Plugin,
SegmentClient,
UserTraits,
} from '@segment/analytics-react-native';
import {AppsflyerPlugin} from '@segment/analytics-react-native-plugin-appsflyer';
import {IdfaPlugin} from '@segment/analytics-react-native-plugin-idfa';
import {IS_IOS} from '../../constants';
import {APP_ANALYTICS_ENABLED} from '../../constants/config';

/**
* Client wrapper for the Segment SDK configured for use with the BitPay app.
* Must call `init()` before any other methods.
*/
const lib = (() => {
let _client: SegmentClient | null = null;

const _addPluginsToClient = (client: SegmentClient) => {
const SEGMENT_PLUGINS: Plugin[] = [new AppsflyerPlugin()];

if (IS_IOS) {
SEGMENT_PLUGINS.push(new IdfaPlugin());
}

SEGMENT_PLUGINS.forEach(plugin => {
client.add({plugin});
});
};

/**
* Guard wrapper that checks if analytics are enabled and client has been initialized before executing the provided callback.
* @param cb Function to execute if all guards pass.
* @returns Resolves if analytics disabled, rejects if client uninitialized, else returns the callback's return value;
*/
const guard = <T>(
cb: (client: SegmentClient) => Promise<T>,
): Promise<T | void> => {
if (!APP_ANALYTICS_ENABLED) {
return Promise.resolve();
}

if (!_client) {
return Promise.reject('Uninitialized');
}

return cb(_client);
};

return {
/**
* Returns an instance of the underlying Segment SDK client, or null if not initialized.
* @returns {SegmentClient | null} The Segment SDK client.
*/
client(): SegmentClient | null {
return _client;
},

/**
* Creates and initializes the Segment SDK. Must be called first.
*/
init() {
if (!APP_ANALYTICS_ENABLED) {
return;
}

if (_client) {
return;
}

_client = createClient({
// Required ---------------

/**
* The Segment write key.
*/
writeKey: SEGMENT_API_KEY,

// Optional ---------------

/**
* When set to false, logs don’t generate.
*/
debug: !!__DEV__, // default: true

/**
* Track app lifecycle events, such as application installed, opened, updated, backgrounded.
*/
trackAppLifecycleEvents: true, // default: false
});

_addPluginsToClient(_client);
},

/**
* Ties a user to their actions and records traits about them.
*
* https://segment.com/docs/connections/spec/identify/
* @param userId Unique identifier for the user in your database.
* @param traits Free-form dictionary of traits of the user, like `email` or `name`.
*/
identify(userId?: string | undefined, traits?: UserTraits | undefined) {
return guard(client => client.identify(userId, traits));
},

/**
* Record whenever a user sees a screen, the mobile equivalent of `page`.
*
* https://segment.com/docs/connections/spec/screen/
* @param name Name of the screen.
* @param properties Free-form dictionary of properties of the screen, like `name`.
*/
screen(name: string, properties?: JsonMap | undefined) {
return guard(client => client.screen(name, properties));
},

/**
* Record any actions your users perform, along with any properties that describe the action.
*
* https://segment.com/docs/connections/spec/track/
* @param event Name of the action that a user has performed.
* @param properties Free-form dictionary of properties of the event, like `revenue`.
*/
track(event: string, properties?: JsonMap | undefined) {
return guard(client => client.track(event, properties));
},
};
})();

export default lib;
Loading

0 comments on commit 405f774

Please sign in to comment.