Skip to content

Commit

Permalink
feat: return consent info whenever it changes
Browse files Browse the repository at this point in the history
BREAKING CHANGE: Alters the return types of two methods
  • Loading branch information
DoctorJohn authored and dylancom committed Aug 13, 2023
1 parent e63100b commit f04ac01
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ private String getPrivacyOptionsRequirementStatusString(
}
}

private WritableMap getConsentInformation() {
WritableMap consentStatusMap = Arguments.createMap();
consentStatusMap.putString(
"status", getConsentStatusString(consentInformation.getConsentStatus()));
consentStatusMap.putBoolean("canRequestAds", consentInformation.canRequestAds());
consentStatusMap.putString(
"privacyOptionsRequirementStatus",
getPrivacyOptionsRequirementStatusString(
consentInformation.getPrivacyOptionsRequirementStatus()));
consentStatusMap.putBoolean(
"isConsentFormAvailable", consentInformation.isConsentFormAvailable());
return consentStatusMap;
}

@ReactMethod
public void requestInfoUpdate(@Nonnull final ReadableMap options, final Promise promise) {
try {
Expand Down Expand Up @@ -111,17 +125,7 @@ public void requestInfoUpdate(@Nonnull final ReadableMap options, final Promise
currentActivity,
consentRequestParameters,
() -> {
WritableMap requestInfoMap = Arguments.createMap();
requestInfoMap.putString(
"status", getConsentStatusString(consentInformation.getConsentStatus()));
requestInfoMap.putBoolean("canRequestAds", consentInformation.canRequestAds());
requestInfoMap.putString(
"privacyOptionsRequirementStatus",
getPrivacyOptionsRequirementStatusString(
consentInformation.getPrivacyOptionsRequirementStatus()));
requestInfoMap.putBoolean(
"isConsentFormAvailable", consentInformation.isConsentFormAvailable());
promise.resolve(requestInfoMap);
promise.resolve(getConsentInformation());
},
formError ->
rejectPromiseWithCodeAndMessage(
Expand Down Expand Up @@ -156,11 +160,7 @@ public void showForm(final Promise promise) {
rejectPromiseWithCodeAndMessage(
promise, "consent-form-error", formError.getMessage());
} else {
WritableMap consentFormMap = Arguments.createMap();
consentFormMap.putString(
"status",
getConsentStatusString(consentInformation.getConsentStatus()));
promise.resolve(consentFormMap);
promise.resolve(getConsentInformation());
}
}),
formError ->
Expand Down Expand Up @@ -193,7 +193,7 @@ public void showPrivacyOptionsForm(final Promise promise) {
rejectPromiseWithCodeAndMessage(
promise, "privacy-options-form-error", formError.getMessage());
} else {
promise.resolve("Privacy options form presented successfully.");
promise.resolve(getConsentInformation());
}
}));
} catch (Exception e) {
Expand Down
63 changes: 30 additions & 33 deletions ios/RNGoogleMobileAds/RNGoogleMobileAdsConsentModule.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,20 @@ - (NSString *)getPrivacyOptionsRequirementStatusString:
}
#endif

#if !TARGET_OS_MACCATALYST
- (NSDictionary *)getConsentInformation {
return @{
@"status" : [self getConsentStatusString:UMPConsentInformation.sharedInstance.consentStatus],
@"canRequestAds" : @(UMPConsentInformation.sharedInstance.canRequestAds),
@"privacyOptionsRequirementStatus" :
[self getPrivacyOptionsRequirementStatusString:UMPConsentInformation.sharedInstance
.privacyOptionsRequirementStatus],
@"isConsentFormAvailable" :
@(UMPConsentInformation.sharedInstance.formStatus == UMPFormStatusAvailable)
};
}
#endif

RCT_EXPORT_METHOD(requestInfoUpdate
: (NSDictionary *)options
: (RCTPromiseResolveBlock)resolve
Expand All @@ -96,20 +110,7 @@ - (NSString *)getPrivacyOptionsRequirementStatusString:
@"message" : error.localizedDescription,
} mutableCopy]];
} else {
resolve(@{
@"status" : [self
getConsentStatusString:UMPConsentInformation.sharedInstance
.consentStatus],
@"canRequestAds" :
@(UMPConsentInformation.sharedInstance.canRequestAds),
@"privacyOptionsRequirementStatus" :
[self getPrivacyOptionsRequirementStatusString:
UMPConsentInformation.sharedInstance
.privacyOptionsRequirementStatus],
@"isConsentFormAvailable" :
@(UMPConsentInformation.sharedInstance.formStatus ==
UMPFormStatusAvailable)
});
resolve([self getConsentInformation]);
}
}];
#endif
Expand All @@ -125,24 +126,20 @@ - (NSString *)getPrivacyOptionsRequirementStatusString:
@"message" : loadError.localizedDescription,
} mutableCopy]];
} else {
[form
presentFromViewController:[UIApplication sharedApplication]
.delegate.window.rootViewController
completionHandler:^(NSError *_Nullable dismissError) {
if (dismissError) {
[RNSharedUtils
rejectPromiseWithUserInfo:reject
userInfo:[@{
@"code" : @"consent-form-error",
@"message" : dismissError.localizedDescription,
} mutableCopy]];
} else {
resolve(@{
@"status" : [self getConsentStatusString:UMPConsentInformation
.sharedInstance.consentStatus],
});
}
}];
[form presentFromViewController:[UIApplication sharedApplication]
.delegate.window.rootViewController
completionHandler:^(NSError *_Nullable dismissError) {
if (dismissError) {
[RNSharedUtils
rejectPromiseWithUserInfo:reject
userInfo:[@{
@"code" : @"consent-form-error",
@"message" : dismissError.localizedDescription,
} mutableCopy]];
} else {
resolve([self getConsentInformation]);
}
}];
}
}];
#endif
Expand All @@ -165,7 +162,7 @@ - (NSString *)getPrivacyOptionsRequirementStatusString:
formError.localizedDescription,
} mutableCopy]];
} else {
resolve(@"Privacy options form presented successfully.");
resolve([self getConsentInformation]);
}
}];
#endif
Expand Down
5 changes: 2 additions & 3 deletions src/AdsConsent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { AdsConsentPurposes } from './AdsConsentPurposes';
import { AdsConsentSpecialFeatures } from './AdsConsentSpecialFeatures';
import { isPropertySet, isArray, isBoolean, isObject, isString } from './common';
import {
AdsConsentFormResult,
AdsConsentInfo,
AdsConsentInfoOptions,
AdsConsentInterface,
Expand Down Expand Up @@ -76,11 +75,11 @@ export const AdsConsent: AdsConsentInterface = {
return native.requestInfoUpdate(options);
},

showForm(): Promise<AdsConsentFormResult> {
showForm(): Promise<AdsConsentInfo> {
return native.showForm();
},

showPrivacyOptionsForm(): Promise<string> {
showPrivacyOptionsForm(): Promise<AdsConsentInfo> {
return native.showPrivacyOptionsForm();
},

Expand Down
19 changes: 2 additions & 17 deletions src/types/AdsConsent.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,12 @@ export interface AdsConsentInterface {
*
* ```
*/
showForm(): Promise<AdsConsentFormResult>;
showForm(): Promise<AdsConsentInfo>;

/**
* Presents a privacy options form if privacyOptionsRequirementStatus is required.
*/
showPrivacyOptionsForm(): Promise<string>;
showPrivacyOptionsForm(): Promise<AdsConsentInfo>;

/**
* Returns the value stored under the `IABTCF_TCString` key
Expand Down Expand Up @@ -144,21 +144,6 @@ export interface AdsConsentInfoOptions {
testDeviceIdentifiers?: string[];
}

/**
* The result of a Google-rendered consent form.
*/
export interface AdsConsentFormResult {
/**
* The consent status of the user after closing the consent form.
*
* - `UNKNOWN`: Unknown consent status.
* - `REQUIRED`: User consent required but not yet obtained.
* - `NOT_REQUIRED`: User consent not required.
* - `OBTAINED`: User consent already obtained.
*/
status: AdsConsentStatus;
}

/**
* The result of requesting info about a users consent status.
*/
Expand Down

0 comments on commit f04ac01

Please sign in to comment.