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

Open
wants to merge 6 commits into
base: dev
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Added

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

- Add support enable/disable screenshot auto masking. ([#1389](https://github.com/Instabug/Instabug-React-Native/pull/1389))

- Add support for BugReporting user consents. ([#1383](https://github.com/Instabug/Instabug-React-Native/pull/1383))
Expand Down
63 changes: 46 additions & 17 deletions android/src/main/java/com/instabug/reactlibrary/RNInstabug.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public class RNInstabug {

private static RNInstabug instance;

private RNInstabug() {}
private RNInstabug() {
}


public static RNInstabug getInstance() {
Expand All @@ -36,14 +37,13 @@ public static RNInstabug getInstance() {
/**
* Initializes the SDK on the native side, which is useful for capturing startup issues specific to the native part of the app.
*
* @param application The application context.
* @param application The application context.
* @param applicationToken The app's identifying token, available on your dashboard.
* @param logLevel The level of detail in logs that you want to print.
* <p>Pick one of the log levels described in {@link LogLevel}.
* default logLevel is {@link LogLevel#ERROR}</p>
* @param InvocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
*
* @param logLevel The level of detail in logs that you want to print.
* <p>Pick one of the log levels described in {@link LogLevel}.
* default logLevel is {@link LogLevel#ERROR}</p>
* @param InvocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
* @example <p>Here's an example usage: </p>
* <blockquote><pre>
* RNInstabug.getInstance().init(
Expand All @@ -59,17 +59,29 @@ public void init(
@NonNull Application application,
@NonNull String applicationToken,
int logLevel,
String codePushVersion,
String appVariant,
@NonNull InstabugInvocationEvent... InvocationEvent


) {
try {

setBaseUrlForDeprecationLogs();
setCurrentPlatform();

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

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


builder.build();

// Temporarily disabling APM hot launches
APM.setHotAppLaunchEnabled(false);
Expand All @@ -80,15 +92,13 @@ public void init(
}



/**
* Initializes the SDK on the native side, which is useful for capturing startup issues specific to the native part of the app.
*
* @param application The application context.
* @param application The application context.
* @param applicationToken The app's identifying token, available on your dashboard.
* @param invocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
*
* @param invocationEvent The events that trigger the SDK's user interface.
* Choose from the available events listed in {@link InstabugInvocationEvent}.
* @example <p>Here's an example usage: </p>
* <blockquote><pre>
* RNInstabug.getInstance().init(
Expand All @@ -102,9 +112,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, invocationEvent);
init(application, applicationToken, LogLevel.ERROR,codePushVersion,appVariant, invocationEvent);
}

@VisibleForTesting
Expand Down Expand Up @@ -160,6 +172,10 @@ 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;


/**
Expand Down Expand Up @@ -221,6 +237,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 @@ -236,6 +262,9 @@ public void build() {
if (codePushVersion != null) {
instabugBuilder.setCodePushVersion(codePushVersion);
}
if(appVariant!=null){
instabugBuilder.setAppVariant(appVariant);
}

instabugBuilder.build();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,9 @@ public void init(
final ReadableArray invocationEventValues,
final String logLevel,
final boolean useNativeNetworkInterception,
@Nullable final String codePushVersion
@Nullable final String codePushVersion,
@Nullable final String appVariant

) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
Expand All @@ -173,6 +175,9 @@ public void run() {
builder.setCodePushVersion(codePushVersion);
}
}
if (appVariant != null) {
builder.setAppVariant(appVariant);
}
builder.build();
}
});
Expand Down Expand Up @@ -500,6 +505,8 @@ public void run() {
});
}



/**
* Removes user attribute if exists.
*
Expand Down Expand Up @@ -1351,4 +1358,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 @@ -65,7 +65,7 @@ public void testInitWithLogLevel() {
when(mock.setInvocationEvents(any())).thenReturn(mock);
});

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

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

Expand All @@ -75,7 +75,6 @@ public void testInitWithLogLevel() {
verify(builder).build();



verify(sut).setBaseUrlForDeprecationLogs();
verify(sut).setCurrentPlatform();
mInstabugBuilder.close();
Expand All @@ -86,16 +85,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, invocationEvents);
verify(sut).init(mContext, token, defaultLogLevel, null, appVariant, invocationEvents);
mInstabugBuilder.close();
}

Expand Down
22 changes: 17 additions & 5 deletions examples/default/ios/InstabugTests/InstabugSampleTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -69,15 +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];
[self.instabugBridge init:appToken invocationEvents:invocationEvents debugLogsLevel:sdkDebugLogsLevel useNativeNetworkInterception:useNativeNetworkInterception codePushVersion:codePushVersion appVariant:appVariant];
OCMVerify([mock setCodePushVersion:codePushVersion]);

XCTAssertEqual(Instabug.appVariant, appVariant);

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

Expand All @@ -99,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 Expand Up @@ -610,18 +622,18 @@ - (void) testIsW3CaughtHeaderEnabled {

- (void)testEnableAutoMasking {
id mock = OCMClassMock([Instabug class]);

NSArray *autoMaskingTypes = [NSArray arrayWithObjects:
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionLabels],
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionTextInputs],
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMedia],
[NSNumber numberWithInteger:IBGAutoMaskScreenshotOptionMaskNothing],
nil];

OCMStub([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);

[self.instabugBridge enableAutoMasking:autoMaskingTypes];

OCMVerify([mock setAutoMaskScreenshots:IBGAutoMaskScreenshotOptionLabels | IBGAutoMaskScreenshotOptionTextInputs | IBGAutoMaskScreenshotOptionMedia | IBGAutoMaskScreenshotOptionMaskNothing]);
}

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 @@ -51,6 +51,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: 4 additions & 1 deletion ios/RNInstabug/InstabugReactBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@

- (void)setEnabled:(BOOL)isEnabled;

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

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

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

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

- (void)setTrackUserSteps:(BOOL)isEnabled;

- (void)setSessionProfilerEnabled:(BOOL)sessionProfilerEnabled;
Expand Down
13 changes: 12 additions & 1 deletion ios/RNInstabug/InstabugReactBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,14 @@ - (dispatch_queue_t)methodQueue {
invocationEvents:(NSArray *)invocationEventsArray
debugLogsLevel:(IBGSDKDebugLogsLevel)sdkDebugLogsLevel
useNativeNetworkInterception:(BOOL)useNativeNetworkInterception
codePushVersion:(NSString *)codePushVersion) {
codePushVersion:(NSString *)codePushVersion
appVariant:(NSString *)appVariant
) {

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

IBGInvocationEvent invocationEvents = 0;

for (NSNumber *boxedValue in invocationEventsArray) {
Expand All @@ -60,6 +67,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 @@ -19,6 +19,11 @@ export interface InstabugConfig {
*/
codePushVersion?: string;

/**
* 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
Loading