Skip to content

feat: support bug reporting user consents #1383

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 6 commits into from
May 20, 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]

### Added

- Add support for BugReporting user consents. ([#1383](https://github.com/Instabug/Instabug-React-Native/pull/1383))

## [14.3.0](https://github.com/Instabug/Instabug-React-Native/compare/v14.1.0...14.3.0)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static Map<String, Object> getAll() {
putAll(locales);
putAll(placeholders);
putAll(launchType);
putAll(userConsentActionType);
}};
}

Expand Down Expand Up @@ -142,6 +143,12 @@ static Map<String, Object> getAll() {
put("reproStepsDisabled", ReproMode.Disable);
}};

static final ArgsMap<String> userConsentActionType = new ArgsMap<String>() {{
put("dropAutoCapturedMedia", com.instabug.bug.userConsent.ActionType.DROP_AUTO_CAPTURED_MEDIA);
put("dropLogs", com.instabug.bug.userConsent.ActionType.DROP_LOGS);
put("noChat", com.instabug.bug.userConsent.ActionType.NO_CHAT);
}};

static final ArgsMap<Integer> sdkLogLevels = new ArgsMap<Integer>() {{
put("sdkDebugLogsLevelNone", com.instabug.library.LogLevel.NONE);
put("sdkDebugLogsLevelError", com.instabug.library.LogLevel.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import androidx.annotation.Nullable;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
Expand All @@ -21,6 +22,7 @@
import com.instabug.reactlibrary.utils.ArrayUtil;
import com.instabug.reactlibrary.utils.EventEmitterModule;
import com.instabug.reactlibrary.utils.MainThreadHandler;
import com.instabug.bug.userConsent.ActionType;

import java.util.ArrayList;

Expand Down Expand Up @@ -415,4 +417,30 @@ public void run() {
}
});
}

/**
* Adds a user consent item to the bug reporting
* @param key A unique identifier string for the consent item.
* @param description The text shown to the user describing the consent item.
* @param mandatory Whether the user must agree to this item before submitting a report.
* @param checked Whether the consent checkbox is pre-selected.
* @param actionType A string representing the action type to map to SDK behavior.
*/
@ReactMethod
public void addUserConsent(String key, String description, boolean mandatory, boolean checked, @Nullable String actionType) {
MainThreadHandler.runOnMainThread(new Runnable() {
@Override
public void run() {
try {
String mappedActionType = ArgsRegistry.userConsentActionType.get(actionType);
BugReporting.addUserConsent(key, description, mandatory, checked, mappedActionType);
} catch (Exception e) {
e.printStackTrace();
}
}
});

}


}
Original file line number Diff line number Diff line change
Expand Up @@ -362,4 +362,22 @@ public Object answer(InvocationOnMock invocation) {

BugReporting.setCommentMinimumCharacterCount(count, type1);
}
@Test
public void TestAddUserConsent() {
final Map<String, String> args = ArgsRegistry.userConsentActionType;
final String[] keysArray = args.keySet().toArray(new String[0]);

final String key = "testKey";
final String description = "Consent description";
final boolean mandatory = true;
final boolean checked = true;
final String inputAction = keysArray[0];

final String expectedMappedAction = args.get(inputAction);

bugReportingModule.addUserConsent(key, description, mandatory, checked, inputAction);

verify(BugReporting.class, VerificationModeFactory.times(1));
BugReporting.addUserConsent(key, description, mandatory, checked, expectedMappedAction);
}
}
21 changes: 21 additions & 0 deletions examples/default/ios/InstabugTests/InstabugBugReportingTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@ - (void) testSetCommentMinimumCharacterCount {
[self.instabugBridge setCommentMinimumCharacterCount:limit reportTypes:reportTypesArr];
OCMVerify([mock setCommentMinimumCharacterCountForReportTypes:reportTypes withLimit:limit.intValue]);
}
- (void)testAddUserConsentWithKey {
id mock = OCMClassMock([IBGBugReporting class]);

NSString *key = @"testKey";
NSString *description = @"Consent description";
BOOL mandatory = YES;
BOOL checked = NO;
NSNumber *actionType = @2;
IBGActionType mappedActionType = (IBGActionType)[actionType integerValue];

[self.instabugBridge addUserConsent:key
description:description
mandatory:mandatory
checked:checked
actionType:actionType];

OCMVerify([mock addUserConsentWithKey:key
description:description
mandatory:mandatory
checked:checked
actionType:mappedActionType]);
}
@end

1 change: 1 addition & 0 deletions ios/RNInstabug/ArgsRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ typedef NSDictionary<NSString*, NSNumber*> ArgsDictionary;
+ (ArgsDictionary *) locales;
+ (ArgsDictionary *)nonFatalExceptionLevel;
+ (ArgsDictionary *) launchType;
+ (ArgsDictionary *) userConsentActionTypes;

+ (NSDictionary<NSString *, NSString *> *) placeholders;

Expand Down
11 changes: 9 additions & 2 deletions ios/RNInstabug/ArgsRegistry.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ + (NSMutableDictionary *) getAll {
[all addEntriesFromDictionary:ArgsRegistry.nonFatalExceptionLevel];
[all addEntriesFromDictionary:ArgsRegistry.placeholders];
[all addEntriesFromDictionary:ArgsRegistry.launchType];

[all addEntriesFromDictionary:ArgsRegistry.userConsentActionTypes];

return all;
}

Expand Down Expand Up @@ -110,7 +111,13 @@ + (ArgsDictionary *) actionTypes {
@"addCommentToFeature": @(IBGActionAddCommentToFeature),
};
}

+ (ArgsDictionary *) userConsentActionTypes {
return @{
@"dropAutoCapturedMedia": @(IBGActionTypeDropAutoCapturedMedia),
@"dropLogs": @(IBGActionTypeDropLogs),
@"noChat": @(IBGActionTypeNoChat)
};
}
+ (ArgsDictionary *) extendedBugReportStates {
return @{
@"enabledWithRequiredFields": @(IBGExtendedBugReportModeEnabledWithRequiredFields),
Expand Down
6 changes: 6 additions & 0 deletions ios/RNInstabug/InstabugBugReportingBridge.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,10 @@

- (void)setCommentMinimumCharacterCount:(NSNumber *)limit reportTypes:(NSArray *)reportTypes;

- (void)addUserConsent:(NSString *)key
description:(NSString *)description
mandatory:(BOOL)mandatory
checked:(BOOL)checked
actionType:(id)actionType;

@end
15 changes: 15 additions & 0 deletions ios/RNInstabug/InstabugBugReportingBridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,21 @@ - (void) showBugReportingWithReportTypeAndOptionsHelper:(NSArray*)args {
[IBGBugReporting setCommentMinimumCharacterCountForReportTypes:parsedReportTypes withLimit:limit.intValue];
}

RCT_EXPORT_METHOD(addUserConsent:(NSString *)key
description:(NSString *)description
mandatory:(BOOL)mandatory
checked:(BOOL)checked
actionType:(id)actionType) {
IBGActionType mappedActionType = (IBGActionType)[actionType integerValue];

[IBGBugReporting addUserConsentWithKey:key
description:description
mandatory:mandatory
checked:checked
actionType:mappedActionType];
}


@synthesize description;

@synthesize hash;
Expand Down
7 changes: 7 additions & 0 deletions ios/RNInstabug/RCTConvert+InstabugEnums.m
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,11 @@ @implementation RCTConvert (InstabugEnums)
integerValue
);

RCT_ENUM_CONVERTER(
IBGActionType,
ArgsRegistry.userConsentActionTypes,
IBGActionTypeNoChat,
integerValue
);

@end
18 changes: 18 additions & 0 deletions src/modules/BugReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import type {
InvocationOption,
RecordingButtonPosition,
ReportType,
userConsentActionType,
} from '../utils/Enums';

/**
Expand Down Expand Up @@ -169,6 +170,23 @@ export const setViewHierarchyEnabled = (isEnabled: boolean) => {
NativeBugReporting.setViewHierarchyEnabled(isEnabled);
};

/**
* Adds a user consent item to the bug reporting form.
* @param key A unique identifier string for the consent item.
* @param description The text shown to the user describing the consent item.
* @param mandatory Whether the user must agree to this item before submitting a report.
* @param checked Whether the consent checkbox is pre-selected.
* @param actionType A string representing the action type to map to SDK behavior.
*/
export const addUserConsent = (
key: string,
description: string,
mandatory: boolean,
checked: boolean,
actionType?: userConsentActionType,
) => {
NativeBugReporting.addUserConsent(key, description, mandatory, checked, actionType);
};
/**
* Sets a block of code to be executed when a prompt option is selected.
* @param handler - A callback that gets executed when a prompt option is selected.
Expand Down
9 changes: 9 additions & 0 deletions src/native/NativeBugReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
InvocationOption,
RecordingButtonPosition,
ReportType,
userConsentActionType,
} from '../utils/Enums';
import { NativeModules } from './NativePackage';

Expand Down Expand Up @@ -48,6 +49,14 @@ export interface BugReportingNativeModule extends NativeModule {
setOnSDKDismissedHandler(
handler: (dismissType: DismissType, reportType: ReportType) => void,
): void;

addUserConsent(
key: string,
description: string,
mandatory: boolean,
checked: boolean,
actionType?: userConsentActionType,
): void;
}

export const NativeBugReporting = NativeModules.IBGBugReporting;
Expand Down
9 changes: 7 additions & 2 deletions src/native/NativeConstants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,20 @@ export type NativeConstants = NativeSdkDebugLogsLevel &
NativeLocale &
NativeNonFatalErrorLevel &
NativeStringKey &
NativeLaunchType;
NativeLaunchType &
NativeUserConsentActionType;

interface NativeSdkDebugLogsLevel {
sdkDebugLogsLevelVerbose: any;
sdkDebugLogsLevelDebug: any;
sdkDebugLogsLevelError: any;
sdkDebugLogsLevelNone: any;
}

interface NativeUserConsentActionType {
dropAutoCapturedMedia: any;
dropLogs: any;
noChat: any;
}
interface NativeInvocationEvent {
invocationEventNone: any;
invocationEventShake: any;
Expand Down
9 changes: 9 additions & 0 deletions src/utils/Enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ export enum LogLevel {
error = constants.sdkDebugLogsLevelError,
none = constants.sdkDebugLogsLevelNone,
}
/**
* Enum representing the available user consent action types.
*
*/
export enum userConsentActionType {
dropAutoCapturedMedia = constants.dropAutoCapturedMedia,
dropLogs = constants.dropLogs,
noChat = constants.noChat,
}

/**
* The event used to invoke the feedback form.
Expand Down
1 change: 1 addition & 0 deletions test/mocks/mockBugReporting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const mockBugReporting: BugReportingNativeModule = {
setVideoRecordingFloatingButtonPosition: jest.fn(),
setDisclaimerText: jest.fn(),
setCommentMinimumCharacterCount: jest.fn(),
addUserConsent: jest.fn(),
};

export default mockBugReporting;