Set up tracking

You can use the user actions APIs below to measure your user’s engagement with your app.

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.

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

Track user actions

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
React Native
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

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

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

Track app states and screens

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
React Native
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

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

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

For more information, see Mobile Core API Reference.

Get help