Track
Learn about the methods for tracking user activity.
Track Views
To track screen views, pass an instance of TealiumView(viewName:mutableMapOf)
to the track()
method. TealiumView
consists of a view name, which appears in the tracking call as tealium_event
, and an optional data dictionary.
The following is an example:
val screenView = TealiumView(
"purchase",
mutableMapOf(
"customer_id" to "abc123",
"order_total" to 10.00,
"product_id" to listOf("PROD123", "PROD456"),
"order_id" to "0123456789"
)
)
tealium.track(screenView);
Track Events
To track non-view events, pass an instance of TealiumEvent(eventName:mutableMapOf)
to the track()
method. TealiumEvent
consists of an event name, which appears in the tracking call as tealium_event
, and an optional data dictionary.
The following is an example:
val tealEvent = TealiumEvent(
"cart_add",
mutableMapOf(
"customer_id" to "abc123",
"product_id" to listOf("PROD123", "PROD456"),
"product_price" to listOf(4.00, 6.00)
)
)
tealium.track(tealEvent);
Timed Events
Timed events measure the duration of an event or the duration between two events. Timed events are triggered automatically or manually.
Automatic Triggers
Automatically track the duration between events by setting timedEventTriggers
to a list of EventTrigger
objects, specifying the names of the start and stop events.
The following is an example of tracking a timed event with an automatic trigger:
timedEventTriggers = mutableListOf(EventTrigger.forEventName(
"cart_add",
"purchase"))
Manual Triggers
Manually track the duration of an event by starting and stopping the timed event based on your custom logic.
Start tracking the duration of an event with startTimedEvent()
.
tealium.startTimedEvent(name: "TimeSpentViewingProduct")
Stop a timed event with stopTimedEvent()
:
tealium.stopTimedEvent(name: "TimeSpentViewingProduct")
Cancel a previously started timed event with cancelTimedEvent()
:
tealium.cancelTimedEvent(name: "TimeSpentViewingProduct")
Trace
Join Trace
Join a trace with the specified ID by calling joinTrace()
. Learn more about the Trace feature in the Tealium Customer Data Hub.
Tealium["INSTANCE_NAME"]?.joinTrace("TRACE_ID")
Replace the following:
INSTANCE_NAME
: the instance name you used when initializing the Tealium Kotlin library.TRACE_ID
: the ID of the trace you want to join.
Leave trace
A trace remains active for the duration of the app session until you call leaveTrace()
, which leaves a previously joined trace and ends the visitor session.
Tealium["INSTANCE_NAME"]?.leaveTrace()
End the visitor session remotely with endTraceVisitorSession()
, which does not terminate the SDK session or reset the session ID.
Tealium["INSTANCE_NAME"]?.endTraceVisitorSession()
This page was last updated: April 29, 2025