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:
let tealView = TealiumView("VIEW_NAME", dataLayer: ["KEY": "VALUE"])
tealium?.track(tealView)
Replace the following:
VIEW_NAME
: 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:
let tealEvent = TealiumEvent("EVENT_NAME", dataLayer: ["KEY": "VALUE"])
tealium?.track(tealEvent)
Replace the following:
EVENT_NAME
: 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 TimedEventTrigger
objects, specifying tthe names of the start and stop events.
The following is an example of tracking a timed event with an automatic trigger:
config.timedEventTriggers = [TimedEventTrigger(
start: "cart_add",
stop: "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")
Clear all previously started timed events with clearAllTimedEvents()
:
tealium?.clearAllTimedEvents()
Trace
Join Trace
The joinTrace()
method joins a trace with the specified ID. Learn more about the Trace feature in the Tealium Customer Data Hub.
class TealiumHelper {
var tealium: Tealium?
// ...
func joinTrace(traceId id: String) {
tealium?.joinTrace(id: "TRACE_ID")
// ...
}
}
Replace TRACE_ID
with the ID of the trace you want to join.
Leave trace
A trace remains active for the duration of the app session until the leaveTrace()
method is called, which leaves a previously joined trace and ends the visitor session.
class TealiumHelper {
var tealium: Tealium?
// ...
func leaveTrace() {
tealium?.leaveTrace()
// ...
}
}
Connector actions set to run at "End of Visit"
do not run until the session expires.
To preserve the trace visitor session when leaving the trace, pass the optional argument false
, as shown in the following example:
tealium?.leaveTrace(killVisitorSession: false)
This page was last updated: May 9, 2024