@adobe/react-native-aepedgeconsent
is a wrapper for the iOS and Android Consent for Edge Network extension to allow for integration with React Native applications.
The Consent for Edge Network extension has the following peer dependency, which must be installed prior to installing the Consent extension:
See Requirements and Installation instructions on the main page.
Install the @adobe/react-native-aepedgeconsent
package:
cd MyReactApp
npm install @adobe/react-native-aepedgeconsent
Install the Consent extension in your mobile property and configure the default consent preferences by following the steps in the Consent for Edge Network extension documentation.
Then follow the same document for registering the Consent extension with the Mobile Core. Note that initializing the SDK should be done in native code, additional documentation on how to initialize the SDK can be found here.
Initialization Example
iOS
// AppDelegate.h
@import AEPCore;
@import AEPEdge;
@import AEPEdgeIdentity;
@import AEPEdgeConsent;
...
@implementation AppDelegate
// AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[AEPMobileCore setLogLevel: AEPLogLevelDebug];
[AEPMobileCore registerExtensions:@[AEPMobileEdgeIdentity.class,
AEPMobileEdge.class,
AEPMobileEdgeConsent.class] completion:^{
[AEPMobileCore configureWithAppId:@"yourAppID"];
...
}];
return YES;
}
@end
Android
import com.adobe.marketing.mobile.LoggingMode;
import com.adobe.marketing.mobile.MobileCore;
import com.adobe.marketing.mobile.Edge;
import com.adobe.marketing.mobile.edge.identity.Identity;
import com.adobe.marketing.mobile.edge.consent.Consent;
...
import android.app.Application;
...
public class MainApplication extends Application implements ReactApplication {
...
@Override
public void on Create(){
super.onCreate();
...
MobileCore.setApplication(this);
MobileCore.setLogLevel(LoggingMode.DEBUG);
MobileCore.configureWithAppID("yourAppID");
Edge.registerExtension();
Identity.registerExtension();
Consent.registerExtension();
MobileCore.start(new AdobeCallback() {
@Override
public void call(Object o) {
}});
}
}
In your React Native application, import the Consent extension as follows:
import {Consent} from '@adobe/react-native-aepedgeconsent';
Returns the version of the Consent extension
Syntax
extensionVersion(): Promise<string>
Example
Consent.extensionVersion().then(version => console.log("Consent.extensionVersion: " + version));
Retrieves the current consent preferences stored in the Consent extension and resolves the promise with the current consent preferences or rejects it if an unexpected error occurs or the request timed out. Output example: {"consents": {"collect": {"val": "y"}}}
Syntax
getConsents(): Promise<Record<string, any>>
Example
Consent.getConsents().then(consents => {
console.log("AEPConsent.getConsents returned current consent preferences: " + JSON.stringify(consents));
}).catch((error) => {
console.warn("AEPConsent.getConsents returned error: ", error.message);
});
Merges the existing consents with the given consents. Duplicate keys will take the value of those passed in the API. Input example: {"consents": {"collect": {"val": "y"}}}
Syntax
update(consents: Record<string, any>)
Example
var consents: {[keys: string]: any} = {"consents" : {"collect" : {"val": "y"}}};
Consent.update(consents);