Skip to content

[GER-7366] Support App variant #1409

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Aug 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased](https://github.com/Instabug/Instabug-React-Native/compare/v15.0.2...dev)

### Added

- Add support for App variant. ([#1409](https://github.com/Instabug/Instabug-React-Native/pull/1409))

## [15.0.2](https://github.com/Instabug/Instabug-React-Native/compare/v15.2.0...dev)

### Added
Expand Down
36 changes: 34 additions & 2 deletions android/src/main/java/com/instabug/reactlibrary/RNInstabug.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,30 @@ public void init(
@NonNull Application application,
@NonNull String applicationToken,
int logLevel,
String codePushVersion,
String appVariant,
Boolean ignoreSecureFlag,
@NonNull InstabugInvocationEvent... InvocationEvent


) {
try {

setBaseUrlForDeprecationLogs();
setCurrentPlatform();

Instabug.Builder builder = new Instabug.Builder(application, applicationToken)
Instabug.Builder builder= new Instabug.Builder(application, applicationToken)
.setInvocationEvents(InvocationEvent)
.setSdkDebugLogsLevel(logLevel);

if(codePushVersion!=null){
builder.setCodePushVersion(codePushVersion);
}
if(appVariant!=null)
builder.setAppVariant(appVariant);



if (ignoreSecureFlag != null) {
builder.ignoreFlagSecure(ignoreSecureFlag);
}
Expand Down Expand Up @@ -107,9 +119,11 @@ public void init(
public void init(
@NonNull Application application,
@NonNull String applicationToken,
String codePushVersion,
String appVariant,
@NonNull InstabugInvocationEvent... invocationEvent
) {
init(application, applicationToken, LogLevel.ERROR,null, invocationEvent);
init(application, applicationToken, LogLevel.ERROR,codePushVersion,appVariant, null,invocationEvent);
}

@VisibleForTesting
Expand Down Expand Up @@ -165,6 +179,11 @@ public static class Builder {
* The events that trigger the SDK's user interface.
*/
private InstabugInvocationEvent[] invocationEvents;
/**
* The App variant name to be used for all reports.
*/
private String appVariant;

private Boolean ignoreFlagSecure;


Expand Down Expand Up @@ -237,6 +256,16 @@ public Builder setInvocationEvents(InstabugInvocationEvent... invocationEvents)
return this;
}

/**
* Sets the the current App variant
*
* @param appVariant the current App variant to work with.
*/
public Builder setAppVariant(String appVariant) {
this.appVariant = appVariant;
return this;
}

/**
* Builds the Instabug instance with the provided configurations.
*/
Expand All @@ -252,6 +281,9 @@ public void build() {
if (codePushVersion != null) {
instabugBuilder.setCodePushVersion(codePushVersion);
}
if(appVariant!=null){
instabugBuilder.setAppVariant(appVariant);
}

if (ignoreFlagSecure != null) {
instabugBuilder.ignoreFlagSecure(ignoreFlagSecure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ public void init(
final String logLevel,
final boolean useNativeNetworkInterception,
@Nullable final String codePushVersion,
@Nullable final String appVariant,
final ReadableMap map
) {
MainThreadHandler.runOnMainThread(new Runnable() {
Expand Down Expand Up @@ -178,6 +179,9 @@ public void run() {
builder.setCodePushVersion(codePushVersion);
}
}
if (appVariant != null) {
builder.setAppVariant(appVariant);
}
builder.build();
}
});
Expand Down Expand Up @@ -505,6 +509,8 @@ public void run() {
});
}



/**
* Removes user attribute if exists.
*
Expand Down Expand Up @@ -1356,4 +1362,19 @@ public void run() {
}
});
}

/**
* Sets current App variant
*
* @param appVariant The app variant name .
*/
@ReactMethod
public void setAppVariant(@NonNull String appVariant) {
try {
Instabug.setAppVariant(appVariant);

} catch (Exception e) {
e.printStackTrace();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,16 @@ public void testRemoveAllFeatureFlags() {
mockInstabug.verify(() -> Instabug.removeAllFeatureFlags());
}

@Test
public void testSetAppVariant() {
String appVariant="App-variant";
// when
rnModule.setAppVariant(appVariant);

// then
mockInstabug.verify(() -> Instabug.setAppVariant(appVariant));
}

@Test
public void testWillRedirectToStore() {
// when
Expand Down Expand Up @@ -678,7 +688,7 @@ public void testSetNetworkLogBodyDisabled() {

mockInstabug.verify(() -> Instabug.setNetworkLogBodyEnabled(false));
}

@Test
public void testEnableAutoMasking(){

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testInitWithLogLevel() {
when(mock.setInvocationEvents(any())).thenReturn(mock);
});

sut.init(mContext, token, logLevel, true, invocationEvents);
sut.init(mContext, token, logLevel, null, null,true, invocationEvents);

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

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

MockedConstruction<Instabug.Builder> mInstabugBuilder = mockConstruction(
Instabug.Builder.class, (mock, context) -> {
when(mock.setSdkDebugLogsLevel(anyInt())).thenReturn(mock);
when(mock.setInvocationEvents(any())).thenReturn(mock);
when(mock.setAppVariant(any())).thenReturn(mock);

});

sut.init(mContext, token, invocationEvents);
sut.init(mContext, token, null, appVariant, invocationEvents);

verify(sut).init(mContext, token, defaultLogLevel, null,invocationEvents);
verify(sut).init(mContext, token, defaultLogLevel, null, appVariant, null,invocationEvents);
mInstabugBuilder.close();
}

Expand Down
16 changes: 13 additions & 3 deletions examples/default/ios/InstabugTests/InstabugSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,17 +69,19 @@ - (void)testInit {
IBGInvocationEvent floatingButtonInvocationEvent = IBGInvocationEventFloatingButton;
NSString *appToken = @"app_token";
NSString *codePushVersion = @"1.0.0(1)";
NSString *appVariant = @"variant 1";

NSArray *invocationEvents = [NSArray arrayWithObjects:[NSNumber numberWithInteger:floatingButtonInvocationEvent], nil];
BOOL useNativeNetworkInterception = YES;
IBGSDKDebugLogsLevel sdkDebugLogsLevel = IBGSDKDebugLogsLevelDebug;

OCMStub([mock setCodePushVersion:codePushVersion]);

[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception codePushVersion:codePushVersion
options:nil
];
[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception codePushVersion:codePushVersion appVariant:appVariant options:nil ];
OCMVerify([mock setCodePushVersion:codePushVersion]);

XCTAssertEqual(Instabug.appVariant, appVariant);

OCMVerify([self.mRNInstabug initWithToken:appToken invocationEvents:floatingButtonInvocationEvent debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception]);
}

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

- (void)testSetAppVariant {
id mock = OCMClassMock([Instabug class]);
NSString *appVariant = @"appVariant";

[self.instabugBridge setAppVariant: appVariant];
XCTAssertEqual(Instabug.appVariant, appVariant);
}

- (void)testSetTrackUserSteps {
id mock = OCMClassMock([Instabug class]);
BOOL isEnabled = true;
Expand Down
1 change: 1 addition & 0 deletions examples/default/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export const App: React.FC = () => {
invocationEvents: [InvocationEvent.floatingButton],
debugLogsLevel: LogLevel.verbose,
networkInterceptionMode: NetworkInterceptionMode.javascript,
appVariant: 'App variant',
});

CrashReporting.setNDKCrashesEnabled(true);
Expand Down
5 changes: 3 additions & 2 deletions ios/RNInstabug/InstabugReactBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@

- (void)setEnabled:(BOOL)isEnabled;

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

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

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

- (void)setAppVariant:(NSString *)appVariant;

- (void)setTrackUserSteps:(BOOL)isEnabled;

- (void)setSessionProfilerEnabled:(BOOL)sessionProfilerEnabled;
Expand Down
15 changes: 13 additions & 2 deletions ios/RNInstabug/InstabugReactBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@ - (dispatch_queue_t)methodQueue {
debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel
useNativeNetworkInterception:(BOOL)useNativeNetworkInterception
codePushVersion:(NSString *)codePushVersion
options:(nullable NSDictionary *)options
) {
appVariant:(NSString *)appVariant
options:(nullable NSDictionary *)options

) {

if(appVariant != nil){
Instabug.appVariant = appVariant;
}

IBGInvocationEvent invocationEvents = 0;

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

RCT_EXPORT_METHOD(setAppVariant:(NSString *)appVariant) {
Instabug.appVariant = appVariant;
}

RCT_EXPORT_METHOD(setReproStepsConfig:(IBGUserStepsMode)bugMode :(IBGUserStepsMode)crashMode:(IBGUserStepsMode)sessionReplayMode) {
[Instabug setReproStepsFor:IBGIssueTypeBug withMode:bugMode];
[Instabug setReproStepsFor:IBGIssueTypeCrash withMode:crashMode];
Expand Down
5 changes: 5 additions & 0 deletions src/models/InstabugConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export interface InstabugConfig {
*/
ignoreAndroidSecureFlag?: boolean;

/**
* An optional current App variant to be used for filtering data.
*/
appVariant?: string;

/**
* An optional network interception mode, this determines whether network interception
* is done in the JavaScript side or in the native Android and iOS SDK side.
Expand Down
9 changes: 9 additions & 0 deletions src/modules/Instabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,14 @@ export const init = (config: InstabugConfig) => {
}, 1000);
};

/**
* Set Current App Variant.
* @param appVariant the current App variant name
*/
export const setAppVariant = (appVariant: string) => {
NativeInstabug.setAppVariant(appVariant);
};

/**
* Handles app state changes and updates APM network flags if necessary.
*/
Expand Down Expand Up @@ -273,6 +281,7 @@ const initializeNativeInstabug = (config: InstabugConfig) => {
shouldEnableNativeInterception &&
config.networkInterceptionMode === NetworkInterceptionMode.native,
config.codePushVersion,
config.appVariant,
config.ignoreAndroidSecureFlag != null
? {
ignoreAndroidSecureFlag: config.ignoreAndroidSecureFlag,
Expand Down
2 changes: 2 additions & 0 deletions src/native/NativeInstabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export interface InstabugNativeModule extends NativeModule {
debugLogsLevel: LogLevel,
useNativeNetworkInterception: boolean,
codePushVersion?: string,
appVariant?: string,
options?: {
ignoreAndroidSecureFlag?: boolean;
},
Expand All @@ -34,6 +35,7 @@ export interface InstabugNativeModule extends NativeModule {

// Misc APIs //
setCodePushVersion(version: string): void;
setAppVariant(appVariant: string): void;
setIBGLogPrintsToConsole(printsToConsole: boolean): void;
setSessionProfilerEnabled(isEnabled: boolean): void;

Expand Down
1 change: 1 addition & 0 deletions test/mocks/mockInstabug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const mockInstabug: InstabugNativeModule = {
clearAllUserAttributes: jest.fn(),
showWelcomeMessageWithMode: jest.fn(),
setWelcomeMessageMode: jest.fn(),
setAppVariant: jest.fn(),
setFileAttachment: jest.fn(),
addPrivateView: jest.fn(),
removePrivateView: jest.fn(),
Expand Down
Loading