Track
Learn about the methods for tracking user activity.
Track Views
To track screen views, pass an instance of TealiumView(viewName:dataLayer:)
to the track()
method. TealiumView
is comprised of a view name, which appears in the tracking call as tealium_event
, and an optional data dictionary.
The following is an example:
val tealView = TealiumView("VIEW_NAME", mutableMapOf("KEY" to "VALUE"))
tealium.track(tealView);
Replace the following:
VIEW_NAME
with the name of the screen view you want to track.KEY:VALUE
: an object of key-value pairs with data associated with the event you want to track.
Track Events
To track non-view events, pass an instance of TealiumEvent(eventName:dataLayer:)
to the track()
method. TealiumEvent
is comprised 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("EVENT_NAME", mutableMapOf("KEY" to "VALUE"))
tealium.track(tealEvent);
Replace the following:
EVENT_NAME
with the name of the non-view event you want to track.KEY:VALUE
: an object of key-value pairs with data associated with the event you want to track.
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: May 9, 2024