Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ This repository is a monorepo. It contains a collection of Adobe Experience Plat
| [@adobe/react-native-aepuserprofile](./packages/userprofile) | [![npm version](https://badge.fury.io/js/%40adobe%2Freact-native-aepuserprofile.svg)](https://www.npmjs.com/package/@adobe/react-native-aepuserprofile) [![npm downloads](https://img.shields.io/npm/dm/@adobe/react-native-aepuserprofile)](https://www.npmjs.com/package/@adobe/react-native-aepuserprofile)
| [@adobe/react-native-aepedge](./packages/edge) | [![npm version](https://badge.fury.io/js/%40adobe%2Freact-native-aepedge.svg)](https://www.npmjs.com/package/@adobe/react-native-aepedge) [![npm downloads](https://img.shields.io/npm/dm/@adobe/react-native-aepedge)](https://www.npmjs.com/package/@adobe/react-native-aepedge) |
| [@adobe/react-native-aepedgeidentity](./packages/edgeidentity) | [![npm version](https://badge.fury.io/js/%40adobe%2Freact-native-aepedgeidentity.svg)](https://www.npmjs.com/package/@adobe/react-native-aepedgeidentity) [![npm downloads](https://img.shields.io/npm/dm/@adobe/react-native-aepedgeidentity)](https://www.npmjs.com/package/@adobe/react-native-aepedgeidentity) |
| [@adobe/react-native-aepedgeconsent](./packages/edgeconsent) | [![npm version](https://badge.fury.io/js/%40adobe%2Freact-native-aepedgeconsent.svg)](https://www.npmjs.com/package/@adobe/react-native-aepedgeconsent) [![npm downloads](https://img.shields.io/npm/dm/@adobe/react-native-aepedgeconsent)](https://www.npmjs.com/package/@adobe/react-native-aepedgeconsent) |
| [@adobe/react-native-aepmessaging](./packages/messaging) | [![npm version](https://badge.fury.io/js/%40adobe%2Freact-native-aepmessaging.svg)](https://www.npmjs.com/package/@adobe/react-native-aepmessaging) [![npm downloads](https://img.shields.io/npm/dm/@adobe/react-native-aepmessaging)](https://www.npmjs.com/package/@adobe/react-native-aepmessaging) |
| [@adobe/react-native-aepassurance (3.0.0-alpha.1)](./packages/assurance) | [![npm version](https://img.shields.io/npm/v/@adobe/react-native-aepassurance/alpha?color=green&label=npm%20package)](https://www.npmjs.com/package/@adobe/react-native-aepassurance/v/3.0.0-alpha.1) [![npm downloads](https://img.shields.io/npm/dm/@adobe/react-native-aepassurance)](https://www.npmjs.com/package/@adobe/react-native-aepassurance/v/3.0.0-alpha.1) |

Expand Down
52 changes: 47 additions & 5 deletions apps/AEPSampleApp/extensions/Consent.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,55 @@ governing permissions and limitations under the License.
@format
*/

import React, {Component} from 'react';
import React, {useState, Component} from 'react';
import {Button, StyleSheet, Text, View, ScrollView} from 'react-native';
import {AEPConsent} from '@adobe/react-native-aepedgeconsent';
import {AEPCore} from '@adobe/react-native-aepcore';

export default Consent = ({ navigation }) => {
const [version, setVersion] = useState('');
const [consents, setConsents] = useState('');
AEPConsent.extensionVersion().then(version => setVersion(version));

function getConsents() {
var consents = {"consents" : {"collect" : {"val": "n"}}};
AEPConsent.getConsents().then(currentConsents => {
let consentsStr = JSON.stringify(currentConsents);
setConsents(consentsStr);
console.log("AdobeExperienceSDK: AEPConsent.getConsents returned current consent preferences: " + consentsStr);
}).catch((error) => {
console.warn("AdobeExperienceSDK: AEPConsent.getConsents returned error: ", error);
});
}

return (
<View style={styles.container}>
<ScrollView contentContainerStyle={{ marginTop: 75 }}>
<Button onPress={() => navigation.goBack()} title="Go to main page" />
<Text style={styles.welcome}>Consent</Text>
<Button title="extensionVersion()" onPress={consentExtensionVersion}/>
<Text style={styles.welcome}>Consent v{version}</Text>
<Button title="Set Default Consent - Yes" onPress={() => setDefaultConsent(true)}/>
<Button title="Set Collect Consent - Yes" onPress={() => updateCollectConsent(true)}/>
<Button title="Set Collect Consent - No" onPress={() => updateCollectConsent(false)}/>
<Button title="Get Consents" onPress={getConsents}/>
<View style={styles.breakLine}/>
<Text style={styles.text}>{consents}</Text>
</ScrollView>
</View>
)
}

function consentExtensionVersion() {
AEPConsent.extensionVersion().then(version => console.log("AdobeExperienceSDK: AEPConsent version: " + version));
function updateCollectConsent(allowed: boolean) {
var collectConsentStatus = allowed ? {"val": "y"} : {"val": "n"};

var consents: {[keys: string]: any} = {"consents" : {"collect" : collectConsentStatus}};
AEPConsent.update(consents);
console.log("AdobeExperienceSDK: AEPConsent.update called with: " + JSON.stringify(consents));
}

function setDefaultConsent(allowed: boolean) {
var collectConsentStatus = allowed ? {"val": "y"} : {"val": "n"};
var defaultConsents: {[keys: string]: any} = {"consent.default": {"consents" : {"collect" : collectConsentStatus}}};
AEPCore.updateConfiguration(defaultConsents);
}

const styles = StyleSheet.create({
Expand All @@ -45,5 +75,17 @@ const styles = StyleSheet.create({
fontSize: 22,
textAlign: 'center',
margin: 10,
},
text: {
fontSize: 15,
textAlign: 'center',
margin: 5,
},
breakLine: {
borderWidth: 0.5,
borderColor: 'black',
margin: 10,
marginTop: 10,
marginBottom: 10,
}
});
2 changes: 1 addition & 1 deletion apps/AEPSampleApp/ios/AEPSampleApp/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
rootViewController.view = rootView;
self.window.rootViewController = rootViewController;
[self.window makeKeyAndVisible];
[AEPMobileCore setLogLevel: AEPLogLevelDebug];
[AEPMobileCore setLogLevel: AEPLogLevelTrace];
[AEPMobileCore configureWithAppId:@"your-app-ID"];
[AEPMobileCore registerExtensions: @[AEPMobileIdentity.class,
AEPMobileLifecycle.class,
Expand Down
85 changes: 83 additions & 2 deletions packages/edgeconsent/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,85 @@

# React Native AEP Consent for Edge Network Extension
# React Native Consent for Edge Network Extension

// todo
[![npm version](https://badge.fury.io/js/%40adobe%2Freact-native-aepedgeconsent.svg)](https://www.npmjs.com/package/@adobe/react-native-aepedgeconsent)
[![npm downloads](https://img.shields.io/npm/dm/@adobe/react-native-aepedgeconsent)](https://www.npmjs.com/package/@adobe/react-native-aepedgeconsent)

`@adobe/react-native-aepedgeconsent` is a wrapper for the iOS and Android [Consent for Edge Network extension](https://aep-sdks.gitbook.io/docs/foundation-extensions/consent-for-edge-network) to allow for integration with React Native applications.

## Prerequisites

The Consent for Edge Network extension has the following peer dependency, which must be installed prior to installing the Consent extension:
- [Core](../core/README.md)

## Installation

See [Requirements and Installation](https://github.com/adobe/aepsdk-react-native#requirements) instructions on the main page.

Install the `@adobe/react-native-aepedgeconsent` package:

```bash
cd MyReactApp
npm install @adobe/react-native-aepedgeconsent
```

## Usage

### Installing and registering the extension with the AEP Mobile Core
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](https://aep-sdks.gitbook.io/docs/foundation-extensions/consent-for-edge-network).

Copy link
Contributor

Choose a reason for hiding this comment

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

When we point the user to this doc, react user might not know they should use the Objective C setup instead of swift. We should point that out to use the Objective-C setup.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

👍 Good point, we will clarify that in the GitBook page soon.

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](https://github.com/adobe/aepsdk-react-native#initializing).

### Importing the extension
In your React Native application, import the AEPConsent extension as follows:
```javascript
import {AEPConsent} from '@adobe/react-native-aepedgeconsent';
```

## API reference
Copy link
Contributor Author

Choose a reason for hiding this comment

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

also let me know what you think about having a separate API reference section/page. This example follows the GitBook doc format with syntax + example.
cc @yangyansong-adbe


### extensionVersion
Returns the version of the AEPConsent extension

**Syntax**
```javascript
static extensionVersion(): Promise<string>
```

**Example**
```javascript
AEPConsent.extensionVersion().then(version => console.log("AEPConsent.extensionVersion: " + version));
```

### getConsents
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**
```javascript
static getConsents(): Promise<{string: any}>
```

**Example**
```javascript
AEPConsent.getConsents().then(consents => {
console.log("AEPConsent.getConsents returned current consent preferences: " + JSON.stringify(consents));
}).catch((error) => {
console.warn("AEPConsent.getConsents returned error: ", error.message);
});
```

### update
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**
```javascript
static update(consents: {string: any})
```

**Example**
```javascript
var consents: {[keys: string]: any} = {"consents" : {"collect" : {"val": "y"}}};
AEPConsent.update(consents);
```
13 changes: 13 additions & 0 deletions packages/edgeconsent/__tests__/AEPConsentTests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,17 @@ describe('AEPEdgeConsent', () => {
await AEPConsent.extensionVersion();
expect(spy).toHaveBeenCalled();
});

it('updateConsents is called with correct parameters', async () => {
const spy = jest.spyOn(NativeModules.AEPEdgeConsent, 'update');
let consents = {"consents": {"collect": {"val": "y"}}};
await AEPConsent.update(consents);
expect(spy).toHaveBeenCalledWith(consents);
});

it('getConsents is called with correct parameters', async () => {
const spy = jest.spyOn(NativeModules.AEPEdgeConsent, 'getConsents');
await AEPConsent.getConsents();
expect(spy).toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
*/
package com.adobe.marketing.mobile.reactnative.edgeconsent;

import com.adobe.marketing.mobile.AdobeCallbackWithError;
import com.adobe.marketing.mobile.AdobeError;
import com.adobe.marketing.mobile.edge.consent.Consent;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.bridge.WritableMap;

import java.util.Map;

public class RCTAEPEdgeConsentModule extends ReactContextBaseJavaModule {
private final ReactApplicationContext reactContext;
Expand All @@ -33,4 +40,27 @@ public String getName() {
public void extensionVersion(final Promise promise) {
promise.resolve(Consent.extensionVersion());
}

@ReactMethod
public void update(final ReadableMap consents) {
Consent.update(RCTAEPEdgeConsentUtils.toMap(consents));
}

@ReactMethod
public void getConsents(final Promise promise) {
Consent.getConsents(new AdobeCallbackWithError<Map<String, Object>>() {
@Override
public void call(final Map<String, Object> consents) {
// null is unexpected, handle as empty to resolve the promise
WritableMap consentsAsWritableMap = RCTAEPEdgeConsentUtils.toWritableMap(consents);
promise.resolve(consentsAsWritableMap != null ? consentsAsWritableMap : Arguments.createMap());
}

@Override
public void fail(final AdobeError adobeError) {
final String errorName = adobeError != null ? adobeError.getErrorName() : AdobeError.UNEXPECTED_ERROR.getErrorName();
promise.reject(getName(), String.format("getConsents - Failed to retrieve consents (%s)", errorName), new Error(errorName));
}
});
}
}
Loading