Track events

The SDK provides 3 event tracking APIs to log events for reporting, segmentation, and various other data collection use cases:

  1. Send events to Edge Network (requires Edge Network extension)

  2. Track user actions (requires Adobe Analytics extension)

  3. Track app states and screens (requires Adobe Analytics extension)

Send events to Edge Network

The Edge Network extension provides an API to send an ExperienceEvent to Edge Network. And ExperienceEvent is an object that contains data conforming to an XDM ExperienceEvent schema definition in Adobe Experience Platform.

Experience Events to track time-series-based user actions in your mobile application or cross channel.

In the following reference examples, you'll create an ExperienceEvent and then send it using the sendEvent API.

For the XDM schema, we've added the Environment Details mixin and also created a custom mixin for product reviews that contain the following fields:

  • productSku

  • rating

  • ratingText

  • reviewerId

Create ExperienceEvent

Android
iOS — Swift
Android

Java

Map<String, Object> reviewXdmData = new HashMap<>();
reviewXdmData.put("productSku", "demo123");
reviewXdmData.put("rating", 5);
reviewXdmData.put("reviewText", "I love this demo!");
reviewXdmData.put("reviewerId", "Anonymous user");
Map<String, Object> xdmData = new HashMap<>();
xdmData.put("eventType", "MyFirstXDMExperienceEvent");
xdmData.put(_yourTenantId, reviewXdmData);
ExperienceEvent experienceEvent = new ExperienceEvent.Builder()
.setXdmSchema(xdmData)
.build();
iOS — Swift

Swift

var xdmData : [String: Any] = [:]
xdmData["eventType"] = "MyFirstXDMExperienceEvent"
xdmData[_yourTenantId] = ["productSku": "demo123",
"rating": 5,
"reviewText": "I love this demo!",
"reviewerId": "Anonymous user"]
let experienceEvent = ExperienceEvent(xdm: xdmData)

Objective-C

NSDictionary<NSString*, NSObject*>* xdmData;
[xdmData setValue:@"MyFirstXDMExperienceEvent" forKey:@"eventType"];
[xdmData setValue:@{@"productSku": @"demo123",
@"rating": @5,
@"reviewText": @"I love this demo!",
@"reviewerId": @"Anonymous user"}
forKey:_yourTenantId];
AEPExperienceEvent *experienceEvent = [[AEPExperienceEvent alloc] initWithXdm:xdmData data:nil datasetIdentifier:nil];

Send ExperienceEvent to Edge Network

Use the AEP Edge mobile extension to send the Experience event created in the previous step.

Android
iOS — Swift
Android

Java

Edge.sendEvent(experienceEvent, null);
iOS — Swift

Swift

Edge.sendEvent(experienceEvent: experienceEvent)

Objective-C

[AEPMobileEdge sendExperienceEvent:event completion:nil];

Track user actions (for Adobe Analytics)

This section shows you how to start track user actions in your mobile app. To view and report on this data in those respective solutions, set up Analytics or other Experience Cloud solution extensions.

Actions are events that occur in your app. Use this API to track and measure an action, where each action has one or more corresponding metrics that increment each time the event occurs. For example, you might call this API for each new subscription each time an article is viewed, or each time a level is completed.

You must call this API when an event that you want to track occurs. In addition to the action name, you can send additional context data with each track action call.

Android
iOS — Obj-C
React Native
Flutter
Cordova
Unity
Xamarin
Android

Java

trackAction

Syntax

public static void trackAction(final String action, final Map<String, String> contextData)

Example

Map<String, String> additionalContextData = new HashMap<String, String>();
additionalContextData.put("customKey", "value");
MobileCore.trackAction("loginClicked", additionalContextData);
iOS — Obj-C

trackAction

Objective C

Syntax

+ (void) trackAction: (nullable NSString*) action data: (nullable NSDictionary*) data;

Example

[ACPCore trackAction:@"action name" data:@{@"key":@"value"}];

Swift

Syntax

+ (void) trackAction: (nullable NSString*) action data: (nullable NSDictionary*) data;

Example

ACPCore.trackAction("action name", data: ["key": "value"])
React Native

JavaScript

Syntax

trackAction(action?: String, contextData?: { string: string });

Example

ACPCore.trackAction("action", {"mytest": "action"});
Flutter

Dart

Syntax

Future<void> trackAction(String action, {Map<String, String> data});

Example

FlutterACPCore.trackAction("mytest", data: {"mytest": "action"});J
Cordova

Javascript

Calling trackAction

ACPCore.trackAction("cordovaAction", {"cordovaKey":"cordovaValue"}, successCallback, errorCallback);
Unity

C#

Calling TrackAction

var contextData = new Dictionary<string, string>();
contextData.Add("key", "value");
ACPCore.TrackAction("action name", contextData);
Xamarin

C#

Calling TrackAction

iOS

var data = new NSMutableDictionary<NSString, NSString>
{
["key"] = new NSString("value")
};
ACPCore.TrackAction("action", data);

Android

var data = new Dictionary<string, string>();
data.Add("key", "value");
ACPCore.TrackAction("action", data);

Track app states and screens (for Adobe Analytics)

States represent screens or views in your app. Each time a new state is displayed in your application, for example, when a user navigates from the home page to the news feed, this method might be called. This method also sends an Analytics state tracking hit with optional context data.

Android
iOS — Obj-C
React Native
Flutter
Cordova
Unity
Xamarin
Android

Java

In Android, trackState is typically called each time a new activity is loaded.

trackState

Syntax

public static void trackState(final String state, final Map<String, String> contextData)

Example

Map<String, String> additionalContextData = new HashMap<String, String>();
additionalContextData.put("customKey", "value");
MobileCore.trackState("homePage", additionalContextData);
iOS — Obj-C

trackState

Objective C

Syntax

+ (void) trackState: (nullable NSString*) state data: (nullable NSDictionary*) data;

Example

[ACPCore trackState:@"state name" data:@{@"key":@"value"}];

Swift

Syntax

+ (void) trackState: (nullable NSString*) state data: (nullable NSDictionary*) data;

Example

ACPCore.trackState("state name", data: ["key": "value"])
React Native

JavaScript

Syntax

trackState(state?: String, contextData?: { string: string });

Example

ACPCore.trackState("state", {"mytest": "state"});
Flutter

Dart

Syntax

Future<void> trackState(String state, {Map<String, String> data});

Example

FlutterACPCore.trackState("state", data: {"mytest": "state"});
Cordova

Javascript

Calling track state

ACPCore.trackState("cordovaState", {"cordovaKey":"cordovaValue"}, successCallback, errorCallback);
Unity

C#

Calling TrackState

var dict = new Dictionary<string, string>();
dict.Add("key", "state value");
ACPCore.TrackState("state", dict);
Xamarin

C#

Calling TrackState

iOS

var data = new NSMutableDictionary<NSString, NSString>
{
["key"] = new NSString("value")
};
ACPCore.TrackState("state", data);

Android

var data = new Dictionary<string, string>();
data.Add("key", "value");
ACPCore.TrackState("state", data);

For more information, see Mobile Core API Reference.

Get help