Swift Class: Tealium

Swift Class: Tealium

by Community Manager on ‎02-02-2017 12:38 PM - edited on ‎01-19-2018 02:46 AM by (513 Views)

Purpose

The Tealium class is a façade that serves as the main API entry point for all additional modules. Almost all API calls will go through the Tealium façade.

Supported Platforms

  • iOS
  • tvOS
  • watchOS
  • macOS

External Dependencies

Foundation

Recommended Usage

Usage of this class is mandatory.

It is automatically included in Carthage and CocoaPods framework builds.

Public API

Tealium

Constructor for a new Tealium object.

Tealium(config: TealiumConfig)

Parameters Type Description
config TealiumConfig object Initialize the Tealium object with a TealiumConfig object containing your account details.
let config = TealiumConfig(account: "your_account",
                           profile: "your_profile",
                           environment: "your_environment")

let tealium = Tealium(config: config)

 

Optionally, you may pass a completion closure block. If you need to use the RemoteCommands feature, or need to send tracking calls immediately after initialization, you should do so in the completion block.

Tealium(config: TealiumConfig, completion: Closure)

Parameters Type Description
config TealiumConfig object Initialize the Tealium object with a TealiumConfig object containing your account details.
completion Closure to be called on init completion (_ modulesResponses: [TealiumModuleResponse])-> Void )?
let config = TealiumConfig(account: "your_account",
                           profile: "your_profile",
                           environment: "your_environment")


let completionHandler = { (_ modulesResponses: [TealiumModuleResponse]) in
            
            print("Tealium ready - your completion code goes here!")
        }

let tealium = Tealium(config: config, completion: completionHandler)

track

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

track(title:String, data:[String:Any], completion:ClosureType)

Parameters Type Description
title String The name of the event to be tracked
data Dictionary An object of key/value pairs with data associated with the event to be tracked
completion ClosureType A function to execute upon completion of the tracking call
// Sample tracking
let mydata = ["someKey": "someValue"]

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

 // Any follow up code here

})

trackView

Tracks a screen view with associated data and, optionally, triggers a callback function.

trackView(title:String, data:[String:Any], completion:ClosureType)

Parameters Type Description
title String The name of the screen view to be tracked
data Dictionary object An object of key/value pairs with data associated with the event to be tracked
completion ClosureType A function to execute upon completion of the tracking call
// Sample tracking
let mydata = ["someKey": "someValue"]

// track call with type specified and completion block
tealium?.trackView(title: "some screen title",
              data: mydata,
              completion: { (success: Bool, info: [String:Any]?, error: Error?) in

 // Any follow up code here

})

Future Improvements

No planned changes

Change Log

Build 1.4.0

  • Removed deprecated track method with TealiumTrackType. Should now call trackView or trackEvent methods instead to differentiate between track call types
  • "tealium_event_type" has been removed from all outgoing track calls, as it is now derived in UDH Event Specs and does not need to be sent
  • Added "call_type" variable to view calls.
  • Added "screen_title" to view calls, which is set to the "title" parameter passed into the trackView call. For "track" calls, "tealium_event" is set to the String value that is passed in as the first parameter.