Swift Class: Tealium

Swift Class: Tealium

by Community Manager ‎02-02-2017 12:38 PM - edited ‎02-02-2017 03:47 PM (197 Views)

This guide specifies the syntax of the functions available in the Tealium class of the Tealium for Swift library.

Table of Contents Placeholder

Core Module

The Core module is required and located in tealium/core.

Tealium()

Constructor for a Tealium object.

let config = TealiumConfig(account: "your_account",
profile: "your_profile",
environment: "your_environment")

let tealium = Tealium(config: config)
Parameters Type Description
config TealiumConfig object Initialize the Tealium object with a TealiumConfig object containing your account details.

track()

Tracks an event with associated data and, optionally, triggers a callback function.

// Sample tracking
let optionalData = ["someKey": "someValue"]

// track call with type specified and completion block
tealium.track(title: "someEvent",
type: TealiumTrackType.view,
data: optionalData,
completion: { (success: Bool, info: [String:AnyObject]?, error: Error?) in

// Any follow up code here

})
Parameters Type Description
title String The name of the event to be tracked
data Dictionary object An object of key/value pairs with data associated with the event to be tracked
type TealiumTrackType constant The type of event to be tracked. 
  • TealiumTrackType.view - for tracking screen views
  •  TealiumTrackType.activity - (default) for tracking non-view user events
completion Completion block A function to execute upon completion of the tracking call

PersistentData Module

The PersistentData module is optional and located in tealium/persistentdata.

persistentData().add()

Add data to all track calls, for current and all subsequent app sessions (clears only if removed or app deleted).

// SAMPLE
let extraData = ["someKey":"someValue" as AnyObject]

tealium.persistentData().add(data:extraData)
Parameters Type Description
data
Dictionary object Key/value pairs of data to be tracked across all subsequent events. 

persistentData().getData()

Retrieve all persistent data previously set with persistentData().add().

// SAMPLE
let data = tealium.persistentData().getData()

persistentData().deleteData()

Remove data previously added with the persistentData().add() method.

// SAMPLE
let keysToRemove = ["someKey", "anotherKey"]
tealium.persistentData().deleteData(forKeys:keysToRemove)
Parameters Type Description
forKeys
Array of Strings The key names of data to be removed from persistence.

persistentData().deleteAllData()

Delete all data previously add via persistentData().add().

// SAMPLE
tealium.persistentData().deleteAllData()

 

VolatileData Module

The VolatileData module is optional and located in tealium/volatiledata.

volatileData().add()

Add data to all track calls, for current session only ie. until app terminates.

// SAMPLE
let keysToRemove = ["someKey", "anotherKey"]
tealium.persistentData().deleteData(forKeys:keysToRemove)
Parameters Type Description
forKeys
Array of Strings The key names of data to be removed from persistence.

volatileData().getData()

Retrieve all volatile data previously set with volatileData().add().

// SAMPLE
let data = tealium.volatileData().getData()

volatileData().deleteData()

Remove data previously added with the volatileData().add() method.

// SAMPLE
let keysToRemove = ["someKey", "anotherKey"]
tealium.volatileData().deleteData(forKeys:keysToRemove)
Parameters Type Description
forKeys
Array of Strings

The key names of data to be removed from volatile data.

volatileData().deleteAllData()

Delete all data previously add via volatileData().add().

// SAMPLE
tealium.volatileData().deleteAllData()

volatileData().resetSessionId()

Reset the session id for current session.

// SAMPLE
tealium.volatileData().resetSessionId()

volatileData().setSessionId()

Override the existing session id for current session.

// SAMPLE
tealium.volatileData().setSessionId(sessionId:"someSessionId")
Parameters Type Description
sessionId
String

A unique identifier for the current session.