Skip to content

Commit 6e713c8

Browse files
authored
feat: update braze plugin to use braze 2.0 sdk (#766)
Co-authored-by: Alan Charles <[email protected]>
1 parent af21c24 commit 6e713c8

File tree

12 files changed

+83
-33
lines changed

12 files changed

+83
-33
lines changed

example/ios/AnalyticsReactNativeExample/AppDelegate.mm

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,14 @@
55
#import <React/RCTAppSetupUtils.h>
66
#import <segment_analytics_react_native-Swift.h>
77
// #import <Firebase.h>
8+
89
// #import <CleverTap-iOS-SDK/CleverTap.h>
910
// #import <clevertap-react-native/CleverTapReactManager.h>
11+
12+
//#import "BrazeReactUtils.h"
13+
//#import "BrazeReactBridge.h"
14+
//#import <BrazeKit/BrazeKit-Swift.h>
15+
1016
#if RCT_NEW_ARCH_ENABLED
1117
#import <React/CoreModulesPlugins.h>
1218
#import <React/RCTCxxBridgeDelegate.h>
@@ -25,25 +31,42 @@ @interface AppDelegate () <RCTCxxBridgeDelegate, RCTTurboModuleManagerDelegate>
2531
}
2632
@end
2733
#endif
34+
35+
2836
@implementation AppDelegate
37+
38+
//enable for Braze Plugin
39+
//static NSString *const apiKey = @"<YOUR API KEY>";
40+
//static NSString *const endpoint = @"<YOUR ENDPOINT>";
41+
42+
2943
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
3044
{
45+
46+
// enable for Braze Plugin
47+
// id<RCTBridgeDelegate> moduleInitializer = [[BrazeReactBridge alloc] init];
3148
RCTAppSetupPrepareApp(application);
3249
RCTBridge *bridge = [[RCTBridge alloc] initWithDelegate:self launchOptions:launchOptions];
50+
51+
3352
#if RCT_NEW_ARCH_ENABLED
3453
_contextContainer = std::make_shared<facebook::react::ContextContainer const>();
3554
_reactNativeConfig = std::make_shared<facebook::react::EmptyReactNativeConfig const>();
3655
_contextContainer->insert("ReactNativeConfig", _reactNativeConfig);
3756
_bridgeAdapter = [[RCTSurfacePresenterBridgeAdapter alloc] initWithBridge:bridge contextContainer:_contextContainer];
3857
bridge.surfacePresenter = _bridgeAdapter.surfacePresenter;
3958
#endif
59+
4060
NSDictionary *initProps = [self prepareInitialProps];
4161
UIView *rootView = RCTAppSetupDefaultRootView(bridge, @"AnalyticsReactNativeExample", initProps);
4262
if (@available(iOS 13.0, *)) {
4363
rootView.backgroundColor = [UIColor systemBackgroundColor];
4464
} else {
4565
rootView.backgroundColor = [UIColor whiteColor];
4666
}
67+
68+
69+
4770
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
4871
UIViewController *rootViewController = [UIViewController new];
4972
rootViewController.view = rootView;
@@ -55,6 +78,16 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
5578
// integrate CleverTap SDK using the autoIntegrate option
5679
// [CleverTap autoIntegrate];
5780
// [[CleverTapReactManager sharedInstance] applicationDidLaunchWithOptions:launchOptions];
81+
82+
// enable for braze plugin
83+
// BRZConfiguration *configuration = [[BRZConfiguration alloc] initWithApiKey:apiKey
84+
// endpoint:endpoint];
85+
// - Enable logging and customize the configuration here
86+
// configuration.logger.level = BRZLoggerLevelInfo;
87+
// Braze *braze = [BrazeReactBridge initBraze:configuration];
88+
// AppDelegate.braze = braze;
89+
90+
5891
return YES;
5992
}
6093

@@ -122,4 +155,19 @@ - (Class)getModuleClassFromName:(const char *)name
122155
return RCTAppSetupDefaultModuleFromClass(moduleClass);
123156
}
124157
#endif
158+
159+
// enable for Braze Plugin
160+
161+
//#pragma mark - AppDelegate.braze
162+
//
163+
//static Braze *_braze = nil;
164+
//
165+
//+ (Braze *)braze {
166+
// return _braze;
167+
//}
168+
//
169+
//+ (void)setBraze:(Braze *)braze {
170+
// _braze = braze;
171+
//}
172+
125173
@end

example/ios/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ PODS:
298298
- React
299299
- RNGestureHandler (2.6.0):
300300
- React-Core
301-
- segment-analytics-react-native (2.12.0):
301+
- segment-analytics-react-native (2.13.0):
302302
- React-Core
303303
- sovran-react-native
304304
- segment-analytics-react-native-plugin-idfa (0.6.0):
@@ -478,7 +478,7 @@ SPEC CHECKSUMS:
478478
RNCAsyncStorage: 0c357f3156fcb16c8589ede67cc036330b6698ca
479479
RNCMaskedView: 0e1bc4bfa8365eba5fbbb71e07fbdc0555249489
480480
RNGestureHandler: 920eb17f5b1e15dae6e5ed1904045f8f90e0b11e
481-
segment-analytics-react-native: f28f404167ef4e2b4f5d5decf9526180393512f4
481+
segment-analytics-react-native: bd1f13ea95bad2313a9c7130da032af0e9a6da60
482482
segment-analytics-react-native-plugin-idfa: c9335ec0327b8f5f35c78bbf0bf7821e9137537e
483483
sovran-react-native: fd3dc8f1a4b14acdc4ad25fc6b4ac4f52a2a2a15
484484
Yoga: 0b84a956f7393ef1f37f3bb213c516184e4a689d

example/src/App.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ import { AmplitudeSessionPlugin } from '@segment/analytics-react-native-plugin-a
3939
//@ts-ignore
4040
// import { ClevertapPlugin } from '@segment/analytics-react-native-plugin-clevertap';
4141

42+
//@ts-ignore
43+
// import { BrazePlugin } from '@segment/analytics-react-native-plugin-braze';
44+
4245
const segmentClient = createClient({
4346
writeKey: 'WRITE_KEY',
4447
trackAppLifecycleEvents: true,
@@ -66,6 +69,8 @@ segmentClient.add({ plugin: LoggerPlugin });
6669

6770
segmentClient.add({ plugin: new AmplitudeSessionPlugin() });
6871

72+
// segmentClient.add({ plugin: new BrazePlugin() });
73+
6974
// segmentClient.add({ plugin: new ClevertapPlugin() });
7075

7176
// segmentClient.add({

packages/plugins/plugin-braze/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"@segment/analytics-react-native": "*"
5151
},
5252
"dependencies": {
53-
"react-native-appboy-sdk": "^1.32.0"
53+
"@braze/react-native-sdk": "^2.0.2"
5454
},
5555
"devDependencies": {
5656
"@semantic-release/changelog": "^6.0.1",

packages/plugins/plugin-braze/src/BrazePlugin.tsx

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@ import {
55
TrackEventType,
66
UserInfoState,
77
} from '@segment/analytics-react-native';
8-
import ReactAppboy, {
9-
GenderTypes,
10-
MonthsAsNumber,
11-
} from 'react-native-appboy-sdk';
8+
import Braze, { GenderTypes, MonthsAsNumber } from '@braze/react-native-sdk';
129
import flush from './methods/flush';
1310
import track from './methods/track';
1411

@@ -28,7 +25,7 @@ export class BrazePlugin extends DestinationPlugin {
2825
return;
2926
} else {
3027
if (event.userId) {
31-
ReactAppboy.changeUser(event.userId);
28+
Braze.changeUser(event.userId);
3229
}
3330

3431
if (event.traits?.birthday !== undefined) {
@@ -39,7 +36,7 @@ export class BrazePlugin extends DestinationPlugin {
3936
!isNaN(birthday.getTime())
4037
) {
4138
const data = new Date(event.traits.birthday);
42-
ReactAppboy.setDateOfBirth(
39+
Braze.setDateOfBirth(
4340
data.getFullYear(),
4441
// getMonth is zero indexed
4542
(data.getMonth() + 1) as MonthsAsNumber,
@@ -53,37 +50,37 @@ export class BrazePlugin extends DestinationPlugin {
5350
}
5451

5552
if (event.traits?.email !== undefined) {
56-
ReactAppboy.setEmail(event.traits.email);
53+
Braze.setEmail(event.traits.email);
5754
}
5855

5956
if (event.traits?.firstName !== undefined) {
60-
ReactAppboy.setFirstName(event.traits.firstName);
57+
Braze.setFirstName(event.traits.firstName);
6158
}
6259

6360
if (event.traits?.lastName !== undefined) {
64-
ReactAppboy.setLastName(event.traits.lastName);
61+
Braze.setLastName(event.traits.lastName);
6562
}
6663

6764
if (event.traits?.gender !== undefined) {
6865
const validGenders = ['m', 'f', 'n', 'o', 'p', 'u'];
6966
const isValidGender = validGenders.indexOf(event.traits.gender) > -1;
7067
if (isValidGender) {
71-
ReactAppboy.setGender(
68+
Braze.setGender(
7269
event.traits.gender as GenderTypes[keyof GenderTypes]
7370
);
7471
}
7572
}
7673

7774
if (event.traits?.phone !== undefined) {
78-
ReactAppboy.setPhoneNumber(event.traits.phone);
75+
Braze.setPhoneNumber(event.traits.phone);
7976
}
8077

8178
if (event.traits?.address !== undefined) {
8279
if (event.traits.address.city !== undefined) {
83-
ReactAppboy.setHomeCity(event.traits.address.city);
80+
Braze.setHomeCity(event.traits.address.city);
8481
}
8582
if (event.traits?.address.country !== undefined) {
86-
ReactAppboy.setCountry(event.traits.address.country);
83+
Braze.setCountry(event.traits.address.country);
8784
}
8885
}
8986

@@ -99,7 +96,7 @@ export class BrazePlugin extends DestinationPlugin {
9996

10097
Object.entries(event.traits ?? {}).forEach(([key, value]) => {
10198
if (appBoyTraits.indexOf(key) < 0) {
102-
ReactAppboy.setCustomUserAttribute(key, value as any);
99+
Braze.setCustomUserAttribute(key, value as any);
103100
}
104101
});
105102

packages/plugins/plugin-braze/src/methods/__tests__/flush.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import flush from '../flush';
2-
import { requestImmediateDataFlush } from '../__mocks__/react-native-appboy-sdk';
2+
import { requestImmediateDataFlush } from '../__mocks__/@braze/react-native-sdk';
33

44
describe('#flush', () => {
55
beforeEach(() => {

packages/plugins/plugin-braze/src/methods/__tests__/identify.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
setGender,
1010
setHomeCity,
1111
setCustomUserAttribute,
12-
} from '../__mocks__/react-native-appboy-sdk';
12+
} from '../__mocks__/@braze/react-native-sdk';
1313
import type { IdentifyEventType } from '@segment/analytics-react-native';
1414
import { BrazePlugin } from '../../BrazePlugin';
1515

packages/plugins/plugin-braze/src/methods/__tests__/track.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
logCustomEvent,
55
logPurchase,
66
setAttributionData,
7-
} from '../__mocks__/react-native-appboy-sdk';
7+
} from '../__mocks__/@braze/react-native-sdk';
88

99
describe('#track', () => {
1010
beforeEach(() => {
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import ReactAppboy from 'react-native-appboy-sdk';
1+
import Braze from '@braze/react-native-sdk';
22

33
export default () => {
4-
ReactAppboy.requestImmediateDataFlush();
4+
Braze.requestImmediateDataFlush();
55
};

packages/plugins/plugin-braze/src/methods/track.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import ReactAppboy from 'react-native-appboy-sdk';
1+
import Braze from '@braze/react-native-sdk';
22
import type { TrackEventType, JsonMap } from '@segment/analytics-react-native';
33

44
const attributionProperties = {
@@ -17,7 +17,7 @@ export default (payload: TrackEventType) => {
1717
const adGroup = attributionData.ad_group ?? attributionProperties.adGroup;
1818
const creative =
1919
attributionData.ad_creative ?? attributionProperties.creative;
20-
ReactAppboy.setAttributionData(network, campaign, adGroup, creative);
20+
Braze.setAttributionData(network, campaign, adGroup, creative);
2121
}
2222
}
2323

@@ -53,7 +53,7 @@ export default (payload: TrackEventType) => {
5353
appBoyProperties,
5454
productDict
5555
);
56-
ReactAppboy.logPurchase(
56+
Braze.logPurchase(
5757
productId,
5858
String(productRevenue),
5959
currency,
@@ -62,7 +62,7 @@ export default (payload: TrackEventType) => {
6262
);
6363
});
6464
} else {
65-
ReactAppboy.logPurchase(
65+
Braze.logPurchase(
6666
payload.event,
6767
String(revenue),
6868
currency,
@@ -71,10 +71,10 @@ export default (payload: TrackEventType) => {
7171
);
7272
}
7373
} else {
74-
ReactAppboy.logPurchase(payload.event, String(revenue), currency, 1);
74+
Braze.logPurchase(payload.event, String(revenue), currency, 1);
7575
}
7676
} else {
77-
ReactAppboy.logCustomEvent(payload.event, payload.properties);
77+
Braze.logCustomEvent(payload.event, payload.properties);
7878
}
7979

8080
return payload;

yarn.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,6 +1091,11 @@
10911091
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
10921092
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
10931093

1094+
"@braze/react-native-sdk@^2.0.2":
1095+
version "2.0.2"
1096+
resolved "https://registry.yarnpkg.com/@braze/react-native-sdk/-/react-native-sdk-2.0.2.tgz#6d0576dd6c69c9ddd77de3b8f43a67c8235613b8"
1097+
integrity sha512-rY1GQdlFfxmYpJhMMw5c0arbyWZG4K8dbV7mEZTC8uxB+vWnwyULy4uuHejbtM3p/AF2vF9wbnlyZhzVQYY1vw==
1098+
10941099
"@changesets/apply-release-plan@^6.0.2":
10951100
version "6.0.2"
10961101
resolved "https://registry.yarnpkg.com/@changesets/apply-release-plan/-/apply-release-plan-6.0.2.tgz#6937f39425c93a70b1e155d76cfa06bf7255c992"
@@ -10560,11 +10565,6 @@ react-native-adjust@^4.29.4:
1056010565
resolved "https://registry.yarnpkg.com/react-native-adjust/-/react-native-adjust-4.29.6.tgz#cf7cc4fdfe516f10a4f42b9df73826c0898fd0c3"
1056110566
integrity sha512-6XShRFrqx/kif0iPutaS4gj6LhZtzPIpH3MAxxKOoqwWWX0UPVQ9boQC4j2BtFjmerVQG1p2LGwsdylsGOiJ2g==
1056210567

10563-
react-native-appboy-sdk@^1.32.0:
10564-
version "1.36.0"
10565-
resolved "https://registry.yarnpkg.com/react-native-appboy-sdk/-/react-native-appboy-sdk-1.36.0.tgz#fdda158ba8e6fb87dda7ab8c89510686fe13c02c"
10566-
integrity sha512-ZveH33LRxJNVEc5ym/tYVpKEEeQwMShV/5Afdum5NZjeTi2Mh/ghTVlCp3t+Icb1BWDnMjke3myiqISYyFXMFw==
10567-
1056810568
react-native-appsflyer@^6.9.4:
1056910569
version "6.9.4"
1057010570
resolved "https://registry.yarnpkg.com/react-native-appsflyer/-/react-native-appsflyer-6.9.4.tgz#35d8adbee93d169a7af3770739e8fe04de2d2680"

0 commit comments

Comments
 (0)