Skip to content
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

Add Datastream override feature to Edge plugin. #120

Merged
merged 21 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 16 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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ This repository is a monorepo. It contains a collection of Adobe Experience Plat
| [UserProfile](plugins/flutter_aepuserprofile/README.md) | [![pub package](https://img.shields.io/pub/v/flutter_aepuserprofile.svg)](https://pub.dartlang.org/packages/flutter_aepuserprofile) |
| [Messaging](plugins/flutter_aepmessaging/README.md) | [![pub package](https://img.shields.io/pub/v/flutter_aepmessaging.svg)](https://pub.dartlang.org/packages/flutter_aepmessaging) |

> [!NOTE]
> The Flutter plugins within this repository are specifically designed to support the Android and iOS platforms only.

## iOS Privacy Manifest

> [!IMPORTANT]
Expand Down
165 changes: 158 additions & 7 deletions example/lib/edge.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,144 @@ class _MyAppState extends State<EdgePage> {
});
}

Future<void> sendEvent([datasetId]) async {
//Using Dictionaries method
Future<void> sendEventWithDictionaryDatasetId([datasetId]) async {
late List<EventHandle> result;
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
Map<String, dynamic> data = {"free": "form", "data": "example"};

final ExperienceEvent experienceEvent = ExperienceEvent(
{"xdmData": xdmData, "data": data, "datasetIdentifier": datasetId});
{"xdmData": xdmData, "data": data, "datasetIdentifier": datasetId,"datastreamIdOverride": "sampleDatastreamID",});
cacheung marked this conversation as resolved.
Show resolved Hide resolved

result = await Edge.sendEvent(experienceEvent);

if (!mounted) {
log('Failed to setState, widget is not mounted');
return;
}

setState(() {
_edgeEventHandleResponse = result;
print("result info " + result.toString());
});
}

Future<void> sendEventWithDictionaryDatastreamIdOverride() async {
late List<EventHandle> result;
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
Map<String, dynamic> data = {"free": "form", "data": "example"};

final ExperienceEvent experienceEvent = ExperienceEvent(
{
"xdmData": xdmData,
"data": data,
"datastreamIdOverride": "sampleDatastreamID",
});

result = await Edge.sendEvent(experienceEvent);

if (!mounted) {
log('Failed to setState, widget is not mounted');
return;
}

setState(() {
_edgeEventHandleResponse = result;
print("result info " + result.toString());
});
}

Future<void> sendEventWithDictionaryDatastreamConfigOverride() async {
late List<EventHandle> result;
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
Map<String, dynamic> data = {"free": "form", "data": "example"};
Map<String, dynamic> configOverrides = {"config": {
cacheung marked this conversation as resolved.
Show resolved Hide resolved
"com_adobe_experience_platform": {
"datasets": {
"event": {
"datasetId": "sampleDatasetID"
cacheung marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}};

final ExperienceEvent experienceEvent = ExperienceEvent(
{
"xdmData": xdmData,
"data": data,
"datastreamConfigOverride": configOverrides,
});

result = await Edge.sendEvent(experienceEvent);

if (!mounted) {
log('Failed to setState, widget is not mounted');
return;
}

setState(() {
_edgeEventHandleResponse = result;
print("result info " + result.toString());
});
}

//Using Constructors
Future<void> sendEventWithConstructorDatasetId([datasetId]) async {
late List<EventHandle> result;
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
Map<String, dynamic> data = {"free": "form", "data": "example"};

final ExperienceEvent experienceEvent = ExperienceEvent.createEvent(xdmData, data, datasetId);

result = await Edge.sendEvent(experienceEvent);

if (!mounted) {
log('Failed to setState, widget is not mounted');
return;
}

setState(() {
_edgeEventHandleResponse = result;
print("result info " + result.toString());
});
}

Future<void> sendEventWithConstructorDatastreamIdOverride() async {
late List<EventHandle> result;
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
Map<String, dynamic> data = {"free": "form", "data": "example"};

final ExperienceEvent experienceEvent = ExperienceEvent.createEventWithOverrides(xdmData, data, "sampleDatastreamID");

result = await Edge.sendEvent(experienceEvent);

if (!mounted) {
log('Failed to setState, widget is not mounted');
return;
}

setState(() {
_edgeEventHandleResponse = result;
print("result info " + result.toString());
});
}

Future<void> sendEventWithConstructorDatastreamConfigOverride() async {
late List<EventHandle> result;
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
Map<String, dynamic> data = {"free": "form", "data": "example"};
//To override eventDataset using datastream config overrides
Map<String, dynamic> configOverrides = {"config": {
addb marked this conversation as resolved.
Show resolved Hide resolved
"com_adobe_experience_platform": {
"datasets": {
"event": {
"datasetId": "sampleDatasetID"
}
}
}
}};

final ExperienceEvent experienceEvent = ExperienceEvent.createEventWithOverrides(xdmData, data, null, configOverrides);

result = await Edge.sendEvent(experienceEvent);

Expand Down Expand Up @@ -96,14 +227,34 @@ class _MyAppState extends State<EdgePage> {
appBar: AppBar(title: Text("Edge Screen")),
body: Center(
child: ListView(shrinkWrap: true, children: <Widget>[
getRichText('AEPEdge extension version: ', '$_edgeVersion\n'),
getRichText('AEPEdge extension version: ', '$_edgeVersion\n'),
ElevatedButton(
child: Text("sendEventWithDictionary"),
onPressed: () => sendEventWithDictionaryDatasetId(),
),
ElevatedButton(
child: Text("sendEventWithDictionary to Dataset"),
onPressed: () => sendEventWithDictionaryDatasetId('datasetId_example'),
),
ElevatedButton(
child: Text("sendEventWithDictionary datastreamIdOverride"),
onPressed: () => sendEventWithDictionaryDatastreamIdOverride(),
),
ElevatedButton(
child: Text("sendEventWithDictionary datastreamConfigOverride"),
onPressed: () => sendEventWithDictionaryDatastreamConfigOverride(),
),
ElevatedButton(
child: Text("sendEventWithConstructor to Dataset"),
onPressed: () => sendEventWithConstructorDatasetId('datasetId_example'),
),
ElevatedButton(
child: Text("sentEvent(...)"),
onPressed: () => sendEvent(),
child: Text("sendEventWithConstructor datastreamIdOverride"),
onPressed: () => sendEventWithConstructorDatastreamIdOverride(),
),
ElevatedButton(
child: Text("sentEvent to Dataset"),
onPressed: () => sendEvent('datasetIdExample'),
child: Text("sendEventWithConstructor datastreamConfigOverride"),
onPressed: () => sendEventWithConstructorDatastreamConfigOverride(),
),
getRichText(
'Response event handles: = ', '$_edgeEventHandleResponse\n'),
Expand Down
117 changes: 103 additions & 14 deletions plugins/flutter_aepedge/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -174,23 +174,101 @@ final ExperienceEvent experienceEvent = ExperienceEvent({
});
List<EventHandle> result = await Edge.sendEvent(experienceEvent);
```

**Example with Datastream ID override**
```dart
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
final ExperienceEvent experienceEvent = ExperienceEvent({
"xdmData": xdmData,
"datastreamIdOverride": "SampleDatastreamId"
});
List<EventHandle> result = await Edge.sendEvent(experienceEvent);
```

**Example with Datastream confg override**
cacheung marked this conversation as resolved.
Show resolved Hide resolved
```dart
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
Map<String, dynamic> configOverrides = {"config": {
cacheung marked this conversation as resolved.
Show resolved Hide resolved
"com_adobe_experience_platform": {
"datasets": {
"event": {
"datasetId": "sampleDatasetID"
}
}
}
}};
final ExperienceEvent experienceEvent = ExperienceEvent({
"xdmData": xdmData,
"datastreamConfigOverride": configOverrides
});
List<EventHandle> result = await Edge.sendEvent(experienceEvent);
```
------
### Public classes
#### ExperienceEvent
Experience Event is the event to be sent to Adobe Experience Platform Edge Network. The XDM data is required for any Experience Event being sent using the Edge extension.

##### Create Experience Event from Dictionary:
You can create Experience Event either by using dictionaries or by utilizing convenience constructors.

**Syntax**
```dart
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
//Create Experience Event from Dictionary
ExperienceEvent(this.eventData)

//Create Experience event using convenience constructor
ExperienceEvent.createEventWithOverrides(final Map<String, dynamic> xdmData,
[final Map<String, dynamic>? data, final String? datastreamIdOverride, final Map<String, dynamic>? datastreamConfigOverride])

```

**Usage**
##### Create Experience Event from Dictionaries:
```dart
// set free form data to the Experience event:
final ExperienceEvent experienceEvent = ExperienceEvent({
"xdmData": xdmData
"xdmData": xdmData,
"data": data
});

// Set free form data and datastream id override to the current Experience event:
final ExperienceEvent experienceEvent = ExperienceEvent({
"xdmData": xdmData,
addb marked this conversation as resolved.
Show resolved Hide resolved
"data": data,
"datastreamIdOverride": "sampleDatastreamId"
});

// Set free form data and datastream config override to the current Experience event:
final ExperienceEvent experienceEvent = ExperienceEvent({
"xdmData": xdmData,
"data": data,
"datastreamConfigOverride": configOverrides
});
```

cacheung marked this conversation as resolved.
Show resolved Hide resolved
##### Add free form data to the Experience event:
##### Create Experience event using convenience constructors:
addb marked this conversation as resolved.
Show resolved Hide resolved
```dart
// set free form data to the Experience event:
cacheung marked this conversation as resolved.
Show resolved Hide resolved
final ExperienceEvent experienceEvent =
ExperienceEvent.createEventWithOverrides(xdmData, data);

// Set free form data and datastream id override to the current Experience event:
final ExperienceEvent experienceEvent =
ExperienceEvent.createEventWithOverrides(xdmData, data, "sampleDatastreamId");

// Set free form data and datastream config override to the current Experience event:
final ExperienceEvent experienceEvent =
ExperienceEvent.createEventWithOverrides(xdmData, data, null, configOverrides);


```

**Example**

Examples of Creating Experience Event Using Dictionaries.
cacheung marked this conversation as resolved.
Show resolved Hide resolved

```dart
// example 1
// set free form data to the Experience event:
cacheung marked this conversation as resolved.
Show resolved Hide resolved
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
Map<String, dynamic> data = {"free": "form", "data": "example"};
final ExperienceEvent experienceEvent = ExperienceEvent({
Expand All @@ -199,27 +277,36 @@ final ExperienceEvent experienceEvent = ExperienceEvent({
});
```

##### Set the destination Dataset identifier to the current Experience event:

```dart
// example 2
// Set free form data and datastream id override to the current Experience event:
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
final ExperienceEvent experienceevent = ExperienceEvent({
Map<String, dynamic> data = {"free": "form", "data": "example"};
final ExperienceEvent experienceEvent = ExperienceEvent({
"xdmData": xdmData,
"data": null,
"datasetIdentifier": "datasetIdExample"
"data": data,
"datastreamIdOverride": "sampleDatastreamId"
addb marked this conversation as resolved.
Show resolved Hide resolved
});
```

##### Create Experience Event with xdmdata, free form data and the destination Dataset identifier:

```dart
// example 3
// Set datastream config override to the current Experience event:
Map<String, dynamic> xdmData = {"eventType": "SampleEventType"};
Map<String, dynamic> data = {"free": "form", "data": "example"};
Map<String, dynamic> configOverrides = {"config": {
cacheung marked this conversation as resolved.
Show resolved Hide resolved
"com_adobe_experience_platform": {
"datasets": {
"event": {
"datasetId": "sampleDatasetID"
cacheung marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}

final ExperienceEvent experienceEvent = ExperienceEvent({
"xdmData": xdmData,
"data": data,
"datasetIdentifier": "datasetIdExample"
"datastreamConfigOverride": configOverrides
});
```
#### EventHandle
Expand All @@ -229,6 +316,8 @@ The EventHandle is a response fragment from Adobe Experience Platform Edge Netwo
static const String _type = 'type';
static const String _payload = 'payload';
```
## Next steps - Schemas setup and validation with Assurance
For examples on XDM schemas and datasets setup and tips on validating with Assurance, refer to the [Edge Network tutorial](https://github.com/adobe/aepsdk-edge-ios/blob/main/Documentation/Tutorials).

## Contributing
See [CONTRIBUTING](https://github.com/adobe/aepsdk_flutter/blob/main/CONTRIBUTING.md)
Expand Down
Loading
Loading