Tealium
The Tealium class serves as the main API entry point for all modules.
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. |
clearStoredVisitorIds() |
Deletes the stored cache of visitorIds and calls resetVisitorId . |
clearAllTimedEvents() |
Clears all previously started timed events. |
decorateUrl() |
Decorates the URL with the Adobe ECID parameters. |
disable() |
Disables the Tealium library. |
flushQueue() |
Sends any queued dispatches immediately. |
gatherTrackData() |
Returns all custom data layer values and collector module data layer values. |
getTagManagementWebView() |
Returns the TagManagement WebView. |
joinTrace() |
Joins a trace with the specified ID. |
leaveTrace() |
Leave a previously joined trace and end the visitor session. |
linkECIDToKnownIdentifier |
Links the current ECID to a known secondary ID. |
onVisitorId |
Allows subscription to changes on visitorId . |
resetVisitor() |
Resets the visitor ECID by retrieving a new one on the next tracking call. |
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. |
visitor |
Returns the full AdobeVisitor instance. |
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()
clearStoredVisitorIds()
Clears all previously stored visitor IDs and hashed customer identifiers.
tealium?.clearStoredVisitorIds()
decorateUrl()
Decorates the input URL with the Adobe ECID query parameters.
decorateUrl(_ url: URL, completion: ((URL) → Void)
Parameters | Type | Description |
---|---|---|
url |
URL |
The URL to decorate |
completion |
URL -> Void |
The block called with the decorated URL. |
Example:
var tealium: Tealium?
...
let url = URL(string: "https://www.tealium.com")!
tealium?.adobeVisitorApi?.decorateUrl(url) { newUrl in
// use the new URL
}
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()
gatherTrackData()
Retrieves all the current custom data layer values and collector module data layer values. The results are cached for subsequent calls and returned asynchronously. Set retrieveCachedData
to false
to get the most recent values. Use the completion handler to process the returned values. Reference custom data layer values directly using their custom keys and reference collector module values using TealiumDataKey.
.
tealium?.gatherTrackData(retreiveCachedData: false, completion: { allData in
let lifecycleTotalWakeCount = allData[TealiumDataKey.totalWakeCount]
let visitorId = allData[TealiumDataKey.visitorId]
let userLanguage = allData["user_language"]
})
See also Tealium.dataLayer.all
.
getTagManagementWebView()
(New in v2.10.0)
Returns the TagManagement WebView so clients can set the isInspectable
flag and debug on XCode 14.3+.
Any other use of the private Webview object, such as loading another web page, may lead to unpredictable behavior and is strongly discouraged.
tealium?.getTagManagementWebView { webView in
if #available(iOS 16.4, *) {
webView.isInspectable = true // To inspect tagManagement webviews on XCode 14.3+ and iOS 16.4+
}
}
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)
Parameters | Type | Description | Example |
---|---|---|---|
killVisitorSession |
Bool |
(Optional) Set to true if no params are passed. Set to false if you don’t want to terminate the visitor session. The default is true . |
false |
linkECIDToKnownIdentifier()
Links the current ECID to a known secondary identifier, such as an email address or other internal ID.
linkECIDToKnownIdentifier(
_ knownID: String,
adobeDataProviderId: String,
authState: AdobeVisitorAuthState?,
completion: ((Result<AdobeVisitor, Error>) → Void)
Parameters | Type | Description |
---|---|---|
knownId |
String |
The known identifier. |
adobeDataProviderId |
String |
The Adobe data provider identifier. |
authState |
AdobeVisitorAuthState |
The authenticated state. |
completion |
Result<AdobeVisitor, Error> |
The Adobe response listener. |
Example:
var tealium: Tealium?
...
tealium?.adobeVisitorApi?.linkECIDToKnownIdentifier(
"myidentifier", adobeDataProviderId: "123456", .unknown
)
onVisitorId
Notifies of visitor ID changes.
let subscription = tealium?.onVisitorId.subscribe { newVisitor in
// handle visitor change here
}
resetVisitor()
Resets the visitor ECID by retrieving a new one on the next tracking call.
resetVisitor()
Example:
var tealium: Tealium?
//...
tealium?.adobeVisitorApi?.resetVisitor()
resetVisitorId()
Generates a new visitor ID for the user.
tealium?.resetVisitorId()
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
.
visitor
Returns the full AdobeVisitor instance.
var tealium: Tealium?
//...
let visitor = tealium?.adobeVisitorApi?.visitor
let id: String? = visitor?.experienceCloudId
let nextRefresh: Date? = visitor?.nextRefresh
let blob: String? = visitor?.blob
let region: String? = visitor?.dcsRegion
let ttl: String? = visitor?.idSyncTTL
visitorId
Returns a randomly generated and unique persistent visitor ID.
let visitorId: String? = tealium.visitorId
This page was last updated: May 9, 2024