Skip to content

Commit 5920584

Browse files
[GER-7366] Support App variant (#1409)
* feat: add support for app variant * feat: add support for app variant * feat: add support for app variant * feat: add support for app variant * feat: support app variant * fix: change log * fix: change log
1 parent 2716489 commit 5920584

File tree

14 files changed

+148
-13
lines changed

14 files changed

+148
-13
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v15.0.2...dev)
4+
5+
### Added
6+
7+
- Add support for App variant. ([#1409](https://github.com/Instabug/Instabug-React-Native/pull/1409))
8+
39
## [15.0.2](https://github.com/Instabug/Instabug-React-Native/compare/v15.2.0...dev)
410

511
### Added

android/src/main/java/com/instabug/reactlibrary/RNInstabug.java

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,30 @@ public void init(
5959
@NonNull Application application,
6060
@NonNull String applicationToken,
6161
int logLevel,
62+
String codePushVersion,
63+
String appVariant,
6264
Boolean ignoreSecureFlag,
6365
@NonNull InstabugInvocationEvent... InvocationEvent
66+
67+
6468
) {
6569
try {
6670

6771
setBaseUrlForDeprecationLogs();
6872
setCurrentPlatform();
6973

70-
Instabug.Builder builder = new Instabug.Builder(application, applicationToken)
74+
Instabug.Builder builder= new Instabug.Builder(application, applicationToken)
7175
.setInvocationEvents(InvocationEvent)
7276
.setSdkDebugLogsLevel(logLevel);
7377

78+
if(codePushVersion!=null){
79+
builder.setCodePushVersion(codePushVersion);
80+
}
81+
if(appVariant!=null)
82+
builder.setAppVariant(appVariant);
83+
84+
85+
7486
if (ignoreSecureFlag != null) {
7587
builder.ignoreFlagSecure(ignoreSecureFlag);
7688
}
@@ -107,9 +119,11 @@ public void init(
107119
public void init(
108120
@NonNull Application application,
109121
@NonNull String applicationToken,
122+
String codePushVersion,
123+
String appVariant,
110124
@NonNull InstabugInvocationEvent... invocationEvent
111125
) {
112-
init(application, applicationToken, LogLevel.ERROR,null, invocationEvent);
126+
init(application, applicationToken, LogLevel.ERROR,codePushVersion,appVariant, null,invocationEvent);
113127
}
114128

115129
@VisibleForTesting
@@ -165,6 +179,11 @@ public static class Builder {
165179
* The events that trigger the SDK's user interface.
166180
*/
167181
private InstabugInvocationEvent[] invocationEvents;
182+
/**
183+
* The App variant name to be used for all reports.
184+
*/
185+
private String appVariant;
186+
168187
private Boolean ignoreFlagSecure;
169188

170189

@@ -237,6 +256,16 @@ public Builder setInvocationEvents(InstabugInvocationEvent... invocationEvents)
237256
return this;
238257
}
239258

259+
/**
260+
* Sets the the current App variant
261+
*
262+
* @param appVariant the current App variant to work with.
263+
*/
264+
public Builder setAppVariant(String appVariant) {
265+
this.appVariant = appVariant;
266+
return this;
267+
}
268+
240269
/**
241270
* Builds the Instabug instance with the provided configurations.
242271
*/
@@ -252,6 +281,9 @@ public void build() {
252281
if (codePushVersion != null) {
253282
instabugBuilder.setCodePushVersion(codePushVersion);
254283
}
284+
if(appVariant!=null){
285+
instabugBuilder.setAppVariant(appVariant);
286+
}
255287

256288
if (ignoreFlagSecure != null) {
257289
instabugBuilder.ignoreFlagSecure(ignoreFlagSecure);

android/src/main/java/com/instabug/reactlibrary/RNInstabugReactnativeModule.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ public void init(
149149
final String logLevel,
150150
final boolean useNativeNetworkInterception,
151151
@Nullable final String codePushVersion,
152+
@Nullable final String appVariant,
152153
final ReadableMap map
153154
) {
154155
MainThreadHandler.runOnMainThread(new Runnable() {
@@ -178,6 +179,9 @@ public void run() {
178179
builder.setCodePushVersion(codePushVersion);
179180
}
180181
}
182+
if (appVariant != null) {
183+
builder.setAppVariant(appVariant);
184+
}
181185
builder.build();
182186
}
183187
});
@@ -505,6 +509,8 @@ public void run() {
505509
});
506510
}
507511

512+
513+
508514
/**
509515
* Removes user attribute if exists.
510516
*
@@ -1356,4 +1362,19 @@ public void run() {
13561362
}
13571363
});
13581364
}
1365+
1366+
/**
1367+
* Sets current App variant
1368+
*
1369+
* @param appVariant The app variant name .
1370+
*/
1371+
@ReactMethod
1372+
public void setAppVariant(@NonNull String appVariant) {
1373+
try {
1374+
Instabug.setAppVariant(appVariant);
1375+
1376+
} catch (Exception e) {
1377+
e.printStackTrace();
1378+
}
1379+
}
13591380
}

android/src/test/java/com/instabug/reactlibrary/RNInstabugReactnativeModuleTest.java

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,16 @@ public void testRemoveAllFeatureFlags() {
631631
mockInstabug.verify(() -> Instabug.removeAllFeatureFlags());
632632
}
633633

634+
@Test
635+
public void testSetAppVariant() {
636+
String appVariant="App-variant";
637+
// when
638+
rnModule.setAppVariant(appVariant);
639+
640+
// then
641+
mockInstabug.verify(() -> Instabug.setAppVariant(appVariant));
642+
}
643+
634644
@Test
635645
public void testWillRedirectToStore() {
636646
// when
@@ -678,7 +688,7 @@ public void testSetNetworkLogBodyDisabled() {
678688

679689
mockInstabug.verify(() -> Instabug.setNetworkLogBodyEnabled(false));
680690
}
681-
691+
682692
@Test
683693
public void testEnableAutoMasking(){
684694

android/src/test/java/com/instabug/reactlibrary/RNInstabugTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void testInitWithLogLevel() {
6767
when(mock.setInvocationEvents(any())).thenReturn(mock);
6868
});
6969

70-
sut.init(mContext, token, logLevel, true, invocationEvents);
70+
sut.init(mContext, token, logLevel, null, null,true, invocationEvents);
7171

7272
Instabug.Builder builder = mInstabugBuilder.constructed().get(0);
7373

@@ -89,16 +89,19 @@ public void testInitWithoutLogLevel() {
8989
final InstabugInvocationEvent[] invocationEvents = new InstabugInvocationEvent[]{InstabugInvocationEvent.FLOATING_BUTTON};
9090
final String token = "fde....";
9191
final int defaultLogLevel = LogLevel.ERROR;
92+
final String appVariant = "app-variant";
9293

9394
MockedConstruction<Instabug.Builder> mInstabugBuilder = mockConstruction(
9495
Instabug.Builder.class, (mock, context) -> {
9596
when(mock.setSdkDebugLogsLevel(anyInt())).thenReturn(mock);
9697
when(mock.setInvocationEvents(any())).thenReturn(mock);
98+
when(mock.setAppVariant(any())).thenReturn(mock);
99+
97100
});
98101

99-
sut.init(mContext, token, invocationEvents);
102+
sut.init(mContext, token, null, appVariant, invocationEvents);
100103

101-
verify(sut).init(mContext, token, defaultLogLevel, null,invocationEvents);
104+
verify(sut).init(mContext, token, defaultLogLevel, null, appVariant, null,invocationEvents);
102105
mInstabugBuilder.close();
103106
}
104107

examples/default/ios/InstabugTests/InstabugSampleTests.m

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,19 @@ - (void)testInit {
6969
IBGInvocationEvent floatingButtonInvocationEvent = IBGInvocationEventFloatingButton;
7070
NSString *appToken = @"app_token";
7171
NSString *codePushVersion = @"1.0.0(1)";
72+
NSString *appVariant = @"variant 1";
73+
7274
NSArray *invocationEvents = [NSArray arrayWithObjects:[NSNumber numberWithInteger:floatingButtonInvocationEvent], nil];
7375
BOOL useNativeNetworkInterception = YES;
7476
IBGSDKDebugLogsLevel sdkDebugLogsLevel = IBGSDKDebugLogsLevelDebug;
7577

7678
OCMStub([mock setCodePushVersion:codePushVersion]);
7779

78-
[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception codePushVersion:codePushVersion
79-
options:nil
80-
];
80+
[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception codePushVersion:codePushVersion appVariant:appVariant options:nil ];
8181
OCMVerify([mock setCodePushVersion:codePushVersion]);
8282

83+
XCTAssertEqual(Instabug.appVariant, appVariant);
84+
8385
OCMVerify([self.mRNInstabug initWithToken:appToken invocationEvents:floatingButtonInvocationEvent debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception]);
8486
}
8587

@@ -101,6 +103,14 @@ - (void)testSetUserData {
101103
OCMVerify([mock setUserData:userData]);
102104
}
103105

106+
- (void)testSetAppVariant {
107+
id mock = OCMClassMock([Instabug class]);
108+
NSString *appVariant = @"appVariant";
109+
110+
[self.instabugBridge setAppVariant: appVariant];
111+
XCTAssertEqual(Instabug.appVariant, appVariant);
112+
}
113+
104114
- (void)testSetTrackUserSteps {
105115
id mock = OCMClassMock([Instabug class]);
106116
BOOL isEnabled = true;

examples/default/src/App.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ export const App: React.FC = () => {
4949
invocationEvents: [InvocationEvent.floatingButton],
5050
debugLogsLevel: LogLevel.verbose,
5151
networkInterceptionMode: NetworkInterceptionMode.javascript,
52+
appVariant: 'App variant',
5253
});
5354

5455
CrashReporting.setNDKCrashesEnabled(true);

ios/RNInstabug/InstabugReactBridge.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@
2626

2727
- (void)setEnabled:(BOOL)isEnabled;
2828

29-
- (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel useNativeNetworkInterception:(BOOL)useNativeNetworkInterception codePushVersion:(NSString *)codePushVersion
30-
options:(nullable NSDictionary *)options;
29+
- (void)init:(NSString *)token invocationEvents:(NSArray *)invocationEventsArray debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel useNativeNetworkInterception:(BOOL)useNativeNetworkInterception codePushVersion:(NSString *)codePushVersion appVariant:(NSString *)appVariant options:(nullable NSDictionary *)options;
3130

3231
- (void)setCodePushVersion:(NSString *)version;
3332

3433
- (void)setUserData:(NSString *)userData;
3534

35+
- (void)setAppVariant:(NSString *)appVariant;
36+
3637
- (void)setTrackUserSteps:(BOOL)isEnabled;
3738

3839
- (void)setSessionProfilerEnabled:(BOOL)sessionProfilerEnabled;

ios/RNInstabug/InstabugReactBridge.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,15 @@ - (dispatch_queue_t)methodQueue {
4242
debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel
4343
useNativeNetworkInterception:(BOOL)useNativeNetworkInterception
4444
codePushVersion:(NSString *)codePushVersion
45-
options:(nullable NSDictionary *)options
46-
) {
45+
appVariant:(NSString *)appVariant
46+
options:(nullable NSDictionary *)options
47+
48+
) {
49+
50+
if(appVariant != nil){
51+
Instabug.appVariant = appVariant;
52+
}
53+
4754
IBGInvocationEvent invocationEvents = 0;
4855

4956
for (NSNumber *boxedValue in invocationEventsArray) {
@@ -62,6 +69,10 @@ - (dispatch_queue_t)methodQueue {
6269
[Instabug setCodePushVersion:version];
6370
}
6471

72+
RCT_EXPORT_METHOD(setAppVariant:(NSString *)appVariant) {
73+
Instabug.appVariant = appVariant;
74+
}
75+
6576
RCT_EXPORT_METHOD(setReproStepsConfig:(IBGUserStepsMode)bugMode :(IBGUserStepsMode)crashMode:(IBGUserStepsMode)sessionReplayMode) {
6677
[Instabug setReproStepsFor:IBGIssueTypeBug withMode:bugMode];
6778
[Instabug setReproStepsFor:IBGIssueTypeCrash withMode:crashMode];

src/models/InstabugConfig.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ export interface InstabugConfig {
2424
*/
2525
ignoreAndroidSecureFlag?: boolean;
2626

27+
/**
28+
* An optional current App variant to be used for filtering data.
29+
*/
30+
appVariant?: string;
31+
2732
/**
2833
* An optional network interception mode, this determines whether network interception
2934
* is done in the JavaScript side or in the native Android and iOS SDK side.

0 commit comments

Comments
 (0)