Tealium for watchOS

Tealium for watchOS

by on ‎02-01-2016 03:47 PM - edited on ‎10-12-2018 09:28 AM by (1,283 Views)

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

Table of Contents Placeholder

 Requirements

  • Xcode 7 or higher
  • iOS 8.1 or higher
  • watchOS 2.0 or higher
  • Tealium for iOS installed in the host app
  • 400KB available space in .ipa file size (this accounts for the tealium-ios library needed in the host app)
  • Bitcode compliant framework  

Add the Dependency

 TealiumWATCHOS.framework is intended to be used in a watchOS extension application where the TealiumIOS.framework has been implemented in the host application. 

  1. Add TealiumWATCHOSExtension.framework to the project's watchOS Extension target
  2. Copy or reference the framework to the project in the resulting dialog box
  3. In the Target's General: Embedded Binaries: Options add TealiumWATCHOSExtension.framework

    For Swift projects be sure to add <TealiumWATCHOSExtension/TEALWKExtension.h> to your bridging header file.

  4. Make sure all paths are as expected under Projects: Target: Build Settings 

Initialization

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

In the Application Delegate, or within a helper class setup method, add the following code to initialize the Tealium instance: 

Swift

// Get Tealium instance
let config = TEALWKExtensionConfiguration.configuration()
guard let tealium = TEALWKExtension.newInstanceForKey("[hostTealiumInstanceKey]") else {

     // Any additional failure response here

     return
}

Objective-C

// import area
#import <TealiumWATCHOSExtension/TealiumWATCHOS.h>
...

// Within a setup method
TEALWKExtensionConfiguration *config = [TEALWKExtensionConfiguration configuration];
config.logLevel = TEALLogLevelDev;

[TEALWKExtension newInstanceForKey:@"[hostTealiumInstanceKey]" configuration:config]; 

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, use this code:

Swift

TEALWKExtension.instanceForKey("[hostTealiumInstanceKey]")?.trackViewWithTitle(NSStringFromClass(self.classForCoder), dataSources: [String:String]())

Objective-C

[[TEALWKExtension instanceForKey:@"[hostTealiumInstanceKey]"] trackViewWithTitle:NSStringFromClass([self class]) dataSources:@{}];

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. 

In any method that triggers or responds to an event trigger, use this code: 

Swift

TEALWKExtension.instanceForKey("[hostTealiumInstanceKey]")?.trackEventwWithTitle("someEvent"), dataSources: [String:String]())

Objective-C

[[Tealium instanceForKey:@"[hostTealiumInstanceKey]"] trackEventWithTitle:@"someEvent" dataSources:@{@"optionalKey":@"optionalValue"}];

Samples & Documentation