Skip to content

feat: 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 4 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
2 changes: 1 addition & 1 deletion android/native.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
project.ext.instabug = [
version: '14.3.0.6760192-SNAPSHOT'
version: '15.0.1'
]

dependencies {
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 invocation triggering events for the SDK's user interface
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this should set the app variant name, not trigger invocation events.

*
* @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 @@ -1037,7 +1044,7 @@ public void run() {
}

/**
* @deprecated see {@link #addFeatureFlags(ReadableArray)}
* @deprecated see {@link #addFeatureFlags(ReadableMap)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be reverted to ReadableArray

*/
@ReactMethod
public void addExperiments(final ReadableArray experiments) {
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
2 changes: 1 addition & 1 deletion examples/default/ios/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ target 'InstabugExample' do
rn_maps_path = '../node_modules/react-native-maps'
pod 'react-native-google-maps', :path => rn_maps_path
# add this line
pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec'
# pod 'Instabug', :podspec => 'https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove the unnecessary comments.

# Flags change depending on the env values.
flags = get_default_flags()

Expand Down
10 changes: 4 additions & 6 deletions examples/default/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ PODS:
- hermes-engine (0.75.4):
- hermes-engine/Pre-built (= 0.75.4)
- hermes-engine/Pre-built (0.75.4)
- Instabug (15.0.1)
- Instabug (15.1.1)
- instabug-reactnative-ndk (0.1.0):
- DoubleConversion
- glog
Expand Down Expand Up @@ -1770,7 +1770,6 @@ DEPENDENCIES:
- fmt (from `../node_modules/react-native/third-party-podspecs/fmt.podspec`)
- glog (from `../node_modules/react-native/third-party-podspecs/glog.podspec`)
- hermes-engine (from `../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec`)
- Instabug (from `https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec`)
- instabug-reactnative-ndk (from `../node_modules/instabug-reactnative-ndk`)
- OCMock
- RCT-Folly (from `../node_modules/react-native/third-party-podspecs/RCT-Folly.podspec`)
Expand Down Expand Up @@ -1851,6 +1850,7 @@ SPEC REPOS:
trunk:
- Google-Maps-iOS-Utils
- GoogleMaps
- Instabug
- OCMock
- SocketRocket

Expand All @@ -1868,8 +1868,6 @@ EXTERNAL SOURCES:
hermes-engine:
:podspec: "../node_modules/react-native/sdks/hermes-engine/hermes-engine.podspec"
:tag: hermes-2024-08-15-RNv0.75.1-4b3bf912cc0f705b51b71ce1a5b8bd79b93a451b
Instabug:
:podspec: https://ios-releases.instabug.com/custom/feature-expose_network_limit-expose_body_limit/15.0.1/Instabug.podspec
instabug-reactnative-ndk:
:path: "../node_modules/instabug-reactnative-ndk"
RCT-Folly:
Expand Down Expand Up @@ -2024,7 +2022,7 @@ SPEC CHECKSUMS:
Google-Maps-iOS-Utils: f77eab4c4326d7e6a277f8e23a0232402731913a
GoogleMaps: 032f676450ba0779bd8ce16840690915f84e57ac
hermes-engine: ea92f60f37dba025e293cbe4b4a548fd26b610a0
Instabug: ba6587d15ad5e3ffa265afc8174ff83af4eed29d
Instabug: 3e7af445c14d7823fcdecba223f09b5f7c0c6ce1
instabug-reactnative-ndk: d765ac289d56e8896398d02760d9abf2562fc641
OCMock: 589f2c84dacb1f5aaf6e4cec1f292551fe748e74
RCT-Folly: 4464f4d875961fce86008d45f4ecf6cef6de0740
Expand Down Expand Up @@ -2100,6 +2098,6 @@ SPEC CHECKSUMS:
SocketRocket: abac6f5de4d4d62d24e11868d7a2f427e0ef940d
Yoga: 055f92ad73f8c8600a93f0e25ac0b2344c3b07e6

PODFILE CHECKSUM: f7f8d2b03a0b566cb0f5b4b422469af0a1a278b1
PODFILE CHECKSUM: 42f74b36b91ffedd1a4b69bf9b72165f04090424

COCOAPODS: 1.14.0
Loading