Tealium
Class: Tealium
The following summarizes the commonly used methods of the iOS (Swift) Tealium
class.
Method/Property | Description |
---|---|
cancelTimedEvent() |
Cancels the timer for a timed event |
clearAllTimedEvents() |
Clears all previously started timed events |
disable() |
Disables the Tealium library |
flushQueue() |
Sends any queued dispatches immediately |
joinTrace() |
Joins a trace with the specified ID |
leaveTrace() |
Leave a previously joined trace and end the visitor session |
resetVisitorId() |
Generates a new visitor ID for the user |
startTimedEvent() |
Starts a timed event with the given name |
stopTimedEvent() |
Stops the timer for a timed event which triggers the timed_event tracking call |
Tealium() |
Constructor for a new Tealium object |
track() |
Tracks an event with associated data and, optionally, triggers a callback function |
visitorId |
Returns a randomly generated and unique persistent visitor ID |
cancelTimedEvent()
Cancels the timer for a timed event. The timed event is not tracked.
tealium?.cancelTimedEvent(name: "TIMED_EVENT_NAME")
Parameters | Type | Description |
---|---|---|
name |
String |
The name of the timed event |
clearAllTimedEvents()
Clears all previously started timed events. The timed events are not tracked.
tealium?.clearAllTimedEvents()
disable()
Disables the Tealium library and removes all module references. Re-enable by creating a new Tealium instance if required.
tealium?.disable()
flushQueue()
Sends all queued dispatches immediately. Requests may still be blocked by DispatchValidator
s such as Consent Manager
tealium?.disable()
joinTrace()
Joins a trace with the specified ID. The trace remains active for the duration of the app session until leaveTrace()
is called. Learn more about the trace feature in the Tealium Customer Data Hub.
joinTrace(traceId: String)
Parameters | Type | Description | Example |
---|---|---|---|
traceId |
String |
The trace ID acquired from the Trace tool | "12345" |
leaveTrace()
Leave a previously joined trace and end the visitor session. Optional parameter to preserve the trace visitor session when leaving the trace.
tealium?.leaveTrace(killVisitorSession: false)
resetVisitorId()
Generates a new visitor ID for the user.
tealium?.resetVisitorId()
Parameters | Type | Description | Example |
---|---|---|---|
killVisitorSession |
Bool |
(Optional) Defaults to true if no params are passed or pass false if you do not wish to terminate the visitor session |
true |
startTimedEvent()
Starts a timed event with the given name. If this method is called again with the same event name, it is ignored if the event has not been ended or canceled. The event start time is not persisted.
If optional data is passed along with the event name, it is added to the track call when the timer is stopped with the stopTimedEvent()
call.
tealium.startTimedEvent(name: "TIMED_EVENT_NAME", with: ["custom_key": "custom_value"])
Parameters | Type | Description |
---|---|---|
name |
String |
The name of the timed event |
["custom_key": "custom_value"] (optional) |
Map |
An object of key-value pair data to be tracked in the data layer |
stopTimedEvent()
Stops the timer for a timed event which triggers the timed_event
tracking call.
tealium?.stopTimedEvent(name: "TIMED_EVENT_NAME")
Parameters | Type | Description |
---|---|---|
name |
String |
The name of the timed event |
Tealium()
Constructor for a new Tealium
object.
Tealium(config: TealiumConfig, completion: Closure)
Parameters | Type | Description |
---|---|---|
config |
TealiumConfig |
Initialize the Tealium object with a TealiumConfig object containing your account details. |
completion |
Closure |
(Optional) Completion closure to be called on init completion()-> Void )? |
track()
Tracks a screen view or event with optional associated data using the TealiumView
or TealiumEvent
type.
let tealView = TealiumView("VIEW_NAME", dataLayer: ["key": "value"])
tealium?.track(tealView)
Parameters | Type | Description | Example |
---|---|---|---|
viewName |
String |
The name of the screen to be tracked | viewName: "Buy Now" |
dataLayer |
Dictionary |
An object of key-value pairs with data associated with the event to be tracked | data: data: ["product_id" : ["widget123"]] |
let tealEvent = TealiumEvent("EVENT_NAME", dataLayer: ["key": "value"])
tealium?.track(tealEvent)
The value passed to viewName
appears in the data layer as the variable tealium_event
.
Parameters | Type | Description | Example |
---|---|---|---|
eventName |
String |
The name of the event to be tracked | eventName: "Buy Now" |
dataLayer |
Dictionary |
An object of key-value pairs with data associated with the event to be tracked | data: data: ["product_id" : ["widget123"]] |
The value passed to eventName
appears in the data layer as the variable tealium_event
.
visitorId
Returns a randomly generated and unique persistent visitor ID.
let visitorId: String? = tealium.visitorId