Track events
The SDK provides three event tracking APIs to log events for reporting, segmentation, and various other data collection use cases:
  1. 1.
    Send events to Edge Network (requires Edge Network extension)
  2. 2.
    Track user actions (requires Adobe Analytics extension)
  3. 3.
    Track app states and screens (requires Adobe Analytics extension)

Send events to Edge Network

This step requires knowledge of Experience Data Model (XDM) in Adobe Experience Platform. For more information about XDM, please read the XDM documentation.
The Edge Network extension provides an API to send an ExperienceEvent to Edge Network. An Experience Event is an object that contains data conforming to the XDM ExperienceEvent schema definition in Adobe Experience Platform.
In the following reference examples, you'll create an ExperienceEvent and then send it using the sendEvent API.
Additionally, you'll need to add the Environment Details field group and create a custom field group for product reviews that contain the following fields:
  • productSku
  • rating
  • ratingText
  • reviewerId

Create an Experience Event

Android
iOS (AEP 3.x)

Java

1
Map<String, Object> reviewXdmData = new HashMap<>();
2
reviewXdmData.put("productSku", "demo123");
3
reviewXdmData.put("rating", 5);
4
reviewXdmData.put("reviewText", "I love this demo!");
5
reviewXdmData.put("reviewerId", "Anonymous user");
6
7
Map<String, Object> xdmData = new HashMap<>();
8
xdmData.put("eventType", "MyFirstXDMExperienceEvent");
9
xdmData.put(_yourTenantId, reviewXdmData);
10
11
ExperienceEvent experienceEvent = new ExperienceEvent.Builder()
12
.setXdmSchema(xdmData)
13
.build();
Copied!

Swift

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

Objective-C

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

Send the Experience Event to Edge Network

Use the Adobe Experience Platform Edge Mobile Extension to send the Experience Event created in the previous step.
Android
iOS (AEP 3.x)

Java

1
Edge.sendEvent(experienceEvent, null);
Copied!

Swift

1
Edge.sendEvent(experienceEvent: experienceEvent)
Copied!

Objective-C

1
[AEPMobileEdge sendExperienceEvent:event completion:nil];
Copied!

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 Adobe Analytics or another 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 every new subscription, every time an article is viewed, or every 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 (AEP 3.x)
iOS (ACP 2.x)
React Native
Flutter
Cordova
Unity
Xamarin

trackAction

Java

Syntax
1
public static void trackAction(final String action, final Map<String, String> contextData)
Copied!
Example
1
Map<String, String> additionalContextData = new HashMap<String, String>();
2
additionalContextData.put("customKey", "value");
3
MobileCore.trackAction("loginClicked", additionalContextData);
Copied!

trackAction

Swift

Syntax
1
static func track(action: String?, data: [String: Any]?)
Copied!
Example
1
MobileCore.track(action: "actionName", data: ["key": "value"])
Copied!

Objective-C

Syntax
1
@objc(trackAction:data:)
2
static func track(action: String?, data: [String: Any]?)
Copied!
Example
1
[AEPMobileCore trackAction:@"action name" data:@{@"key": @"value"}];
Copied!

trackAction

Objective-C

Syntax
1
+ (void) trackAction: (nullable NSString*) action data: (nullable NSDictionary*) data;
Copied!
Example
1
[ACPCore trackAction:@"action name" data:@{@"key":@"value"}];
Copied!

Swift

Syntax
1
+ (void) trackAction: (nullable NSString*) action data: (nullable NSDictionary*) data;
Copied!
Example
1
ACPCore.trackAction("action name", data: ["key": "value"])
Copied!

JavaScript

Syntax
1
trackAction(action?: String, contextData?: { string: string });
Copied!
Example
1
ACPCore.trackAction("action", {"mytest": "action"});
Copied!

Dart

Syntax
1
Future<void> trackAction(String action, {Map<String, String> data});
Copied!
Example
1
FlutterACPCore.trackAction("mytest", data: {"mytest": "action"});J
Copied!

Javascript

Calling trackAction

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

C#

Calling TrackAction

1
var contextData = new Dictionary<string, string>();
2
contextData.Add("key", "value");
3
ACPCore.TrackAction("action name", contextData);
Copied!

C#

Calling TrackAction

iOS
1
var data = new NSMutableDictionary<NSString, NSString>
2
{
3
["key"] = new NSString("value")
4
};
5
ACPCore.TrackAction("action", data);
Copied!
Android
1
var data = new Dictionary<string, string>();
2
data.Add("key", "value");
3
ACPCore.TrackAction("action", data);
Copied!

Track app states and screens (for Adobe Analytics)

States represent screens or views in your app. The trackState method is called every time a new state is displayed in your application. For example, this method would be called when a user navigates from the home page to the news feed. This method also sends an Adobe Analytics state-tracking hit with optional context data.
Android
iOS (AEP 3.x)
iOS (ACP 2.x)
React Native
Flutter
Cordova
Unity
Xamarin

trackState

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

Java

Syntax
1
public static void trackState(final String state, final Map<String, String> contextData)
Copied!
Example
1
Map<String, String> additionalContextData = new HashMap<String, String>();
2
additionalContextData.put("customKey", "value");
3
MobileCore.trackState("homePage", additionalContextData);
Copied!

trackState

Swift

Syntax
1
static func track(state: String?, data: [String: Any]?)
Copied!
Example
1
MobileCore.track(state: "state name", data: ["key": "value"])
Copied!

Objective-C

Syntax
1
@objc(trackState:data:)
2
static func track(state: String?, data: [String: Any]?)
Copied!
Example
1
[AEPMobileCore trackState:@"state name" data:@{@"key": @"value"}];
Copied!

trackState

Objective-C

Syntax
1
+ (void) trackState: (nullable NSString*) state data: (nullable NSDictionary*) data;
Copied!
Example
1
[ACPCore trackState:@"state name" data:@{@"key":@"value"}];
Copied!

Swift

Syntax
1
+ (void) trackState: (nullable NSString*) state data: (nullable NSDictionary*) data;
Copied!
Example
1
ACPCore.trackState("state name", data: ["key": "value"])
Copied!

JavaScript

Syntax
1
trackState(state?: String, contextData?: { string: string });
Copied!
Example
1
ACPCore.trackState("state", {"mytest": "state"});
Copied!

Dart

Syntax
1
Future<void> trackState(String state, {Map<String, String> data});
Copied!
Example
1
FlutterACPCore.trackState("state", data: {"mytest": "state"});
Copied!

Javascript

Calling trackState

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

C#

Calling TrackState

1
var dict = new Dictionary<string, string>();
2
dict.Add("key", "state value");
3
ACPCore.TrackState("state", dict);
Copied!

C#

Calling TrackState

iOS
1
var data = new NSMutableDictionary<NSString, NSString>
2
{
3
["key"] = new NSString("value")
4
};
5
ACPCore.TrackState("state", data);
Copied!
Android
1
var data = new Dictionary<string, string>();
2
data.Add("key", "value");
3
ACPCore.TrackState("state", data);
Copied!
For more information, see the Mobile Core API Reference.

Get help

Last modified 1mo ago