Tealium for tvOS

Tealium for tvOS

by on ‎02-01-2016 03:47 PM - edited on ‎05-31-2017 10:05 AM by Community Manager (1,503 Views)

This guide shows how to add Tealium to your Apple TV app to track user activity. 

Table of Contents Placeholder

Requirements

Before proceeding, ensure you have satisfied the following requirements:

Installation

Tealium uses CocoaPods to install and manage dependencies. Add the following dependency to your Podfile:

pod "TealiumTVOS"

The code for the Tealium tvOS library is stored on Github. You must download and install the library.

We recommend cloning the library (instead of downloading) to make it easier to update to future releases.

Once the code is in place follow these steps to add Tealium to your project:

  1. Add TealiumTVOS.framework to your project
  2. Copy framework to project in the resulting dialog box
  3. In the Target's General: Embedded Binaries: options add TealiumTVOS.framework 

Initialization

Once the Tealium for tvOS is added to your project you are ready to start coding.

You will need the following parameters to initialize the code:

  • account - the name of your iQ account
  • profile - the name of the mobile profile within your iQ account
  • environment - one of "qa" or "prod"
  • datasource - (optional) the data source key from UDH
  • instance keya unique name for your instance (multiple instances are supported)

In the Application Delegate or within a helper class setup method, you will invoke a Tealium instance with the following code:

Swift

let config = TEALConfiguration.init(account: "ACCOUNT",
profile: "PROFILE",
environment: "ENV",
datasource: "DATASOURCE") guard let tealium = Tealium.newInstanceForKey("uniqueInstanceKey", configuration: config) else { // Any additional failure response here return }

Objective-C

TEALConfiguration *configuration = [TEALConfiguration configurationWithAccount:@"ACCOUNT"
                                                                       profile:@"PROFILE"
                                                                   environment:@"ENV",
datasource:@"DATASOURCE"]; Tealium *tealiumInstance1 = [Tealium newInstanceForKey:@"uniqueInstanceKey" configuration:configuration]; 

Tracking

Tracking Views

Every time a user opens or changes a screen in the app a tracking call should be made.  A view is tracked by calling trackViewWithTitle() with two parameters: the name of the screen and (optionally) contextual view data.

In any UIViewController's viewDidAppear method: 

Swift

Tealium.instanceForKey("uniqueInstanceKey")?.trackViewWithTitle(NSStringFromClass(self.classForCoder), dataSources: [:])

Objective-C

[[Tealium instanceForKey:@"uniqueInstanceKey"] trackViewWithTitle:NSStringFromClass([self class]) dataSources:nil];

The screen name will be populated in the event data as the screen_title variable.

Tracking Events

All non-view activity should be tracked as an event. This is easily done by calling trackEventWithTitle() with two parameters: an event name and (optionally) contextual event data. 

Swift

Tealium.instanceForKey("uniqueInstanceKey")?.trackEventWithTitle("someEvent", dataSources: [:])

Objective-C

[[Tealium instanceForKey:@"uniqueInstanceKey"] trackEventWithTitle:@"someEvent" dataSources:nil];

The event name will be populated in the event data as the tealium_event variable.

Samples & Documentation