The SDK provides three event tracking APIs to log events for reporting, segmentation, and various other data collection use cases:
- Send events to Edge Network (requires Edge Network extension)
- Track user actions (requires Adobe Analytics extension)
- Track app states and screens (requires Adobe Analytics extension)
{% hint style="info" %} This step requires knowledge of Experience Data Model (XDM) in Adobe Experience Platform. For more information about XDM, please read the XDM documentation. {% endhint %}
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
{% tabs %} {% tab title="Android" %}
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();
{% endtab %}
{% tab title="iOS (AEP 3.x)" %}
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)
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];
{% endtab %} {% endtabs %}
Use the Adobe Experience Platform Edge Mobile Extension to send the Experience Event created in the previous step.
{% tabs %} {% tab title="Android" %}
Edge.sendEvent(experienceEvent, null);
{% endtab %}
{% tab title="iOS (AEP 3.x)" %}
Edge.sendEvent(experienceEvent: experienceEvent)
[AEPMobileEdge sendExperienceEvent:event completion:nil];
{% endtab %} {% endtabs %}
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.
{% hint style="warning" %} 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. {% endhint %}
{% tabs %} {% tab title="Android" %}
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);
{% endtab %}
{% tab title="iOS (AEP 3.x)" %}
Syntax
static func track(action: String?, data: [String: Any]?)
Example
MobileCore.track(action: "actionName", data: ["key": "value"])
Syntax
@objc(trackAction:data:)
static func track(action: String?, data: [String: Any]?)
Example
[AEPMobileCore trackAction:@"action name" data:@{@"key": @"value"}];
{% endtab %}
{% tab title="iOS (ACP 2.x)" %}
Syntax
+ (void) trackAction: (nullable NSString*) action data: (nullable NSDictionary*) data;
Example
[ACPCore trackAction:@"action name" data:@{@"key":@"value"}];
Syntax
+ (void) trackAction: (nullable NSString*) action data: (nullable NSDictionary*) data;
Example
ACPCore.trackAction("action name", data: ["key": "value"])
{% endtab %}
{% tab title="React Native" %}
Syntax
trackAction(action?: String, contextData?: { string: string });
Example
ACPCore.trackAction("action", {"mytest": "action"});
{% endtab %}
{% tab title="Flutter" %}
Syntax
Future<void> trackAction(String action, {Map<String, String> data});
Example
FlutterACPCore.trackAction("mytest", data: {"mytest": "action"});J
{% endtab %}
{% tab title="Cordova" %}
ACPCore.trackAction("cordovaAction", {"cordovaKey":"cordovaValue"}, successCallback, errorCallback);
{% endtab %}
{% tab title="Unity" %}
var contextData = new Dictionary<string, string>();
contextData.Add("key", "value");
ACPCore.TrackAction("action name", contextData);
{% endtab %}
{% tab title="Xamarin" %}
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);
{% endtab %} {% endtabs %}
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.
{% tabs %} {% tab title="Android" %}
On Android, trackState
is typically called each time a new activity is loaded.
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);
{% endtab %}
{% tab title="iOS (AEP 3.x)" %}
Syntax
static func track(state: String?, data: [String: Any]?)
Example
MobileCore.track(state: "state name", data: ["key": "value"])
Syntax
@objc(trackState:data:)
static func track(state: String?, data: [String: Any]?)
Example
[AEPMobileCore trackState:@"state name" data:@{@"key": @"value"}];
{% endtab %}
{% tab title="iOS (ACP 2.x)" %}
Syntax
+ (void) trackState: (nullable NSString*) state data: (nullable NSDictionary*) data;
Example
[ACPCore trackState:@"state name" data:@{@"key":@"value"}];
Syntax
+ (void) trackState: (nullable NSString*) state data: (nullable NSDictionary*) data;
Example
ACPCore.trackState("state name", data: ["key": "value"])
{% endtab %}
{% tab title="React Native" %}
Syntax
trackState(state?: String, contextData?: { string: string });
Example
ACPCore.trackState("state", {"mytest": "state"});
{% endtab %}
{% tab title="Flutter" %}
Syntax
Future<void> trackState(String state, {Map<String, String> data});
Example
FlutterACPCore.trackState("state", data: {"mytest": "state"});
{% endtab %}
{% tab title="Cordova" %}
ACPCore.trackState("cordovaState", {"cordovaKey":"cordovaValue"}, successCallback, errorCallback);
{% endtab %}
{% tab title="Unity" %}
var dict = new Dictionary<string, string>();
dict.Add("key", "state value");
ACPCore.TrackState("state", dict);
{% endtab %}
{% tab title="Xamarin" %}
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);
{% endtab %} {% endtabs %}
For more information, see the Mobile Core API Reference.
- Visit the SDK community forum to ask questions
- Contact Adobe Experience Cloud customer care for immediate assistance