Swift Module: Autotracking

Swift Module: Autotracking

by on ‎02-06-2017 11:45 AM - edited on ‎12-22-2017 07:59 AM by (641 Views)


Automatically triggers tracking calls when certain user interface interactions take place, e.g. taps, swipes, screen views.


  • Automatically trigger track calls from UIViewController view appearances
  • Automatically trigger track calls for UI Events (ie button taps)
  • Includes delegate methods for reporting or suppressing autotracked data

Supported Platforms

  • iOS
  • tvOS

External Dependencies

Foundation, UIKit, UIApplication

Bridging Header

Please note, this module has been ported from Objective-C code, and as such, requires a Bridging Header.

How to create a Bridging Header

  1. In your Swift project, create a new file. When prompted to select a file type, select Objective-C File.
  2. Give this file a temporary name, such as "placeholder.m", as you are going to remove it later.
  3. Click "Finish", and XCode should prompt you to create a Bridging Header (if it doesn't, you probably already have a Bridging Header in your project). Press "Create Bridging Header" to continue, and Xcode will automatically create the new header file for you.
  4. Delete your "placeholder.m" file from the project. You will notice a new file called -Bridging-Header.h
  5. Add the following import statements to the new Bridging Header:
#import "UIApplication+TealiumTracker.h"
#import "UIViewController+TealiumTracker.h"

Compatible Platforms

  • iOS
  • tvOS

Recommended Usage

In general, usage of this module is discouraged and not recommended for the following reasons:

  • Increased memory usage
  • Increased possibility for crashes to occur due to UI changes outside of Tealium's control (e.g. UI component being deallocated before the track call has completed)
  • Increased battery consumption
  • Unwanted additional tracking calls
  • Does not fully remove the need to add additional tracking data/events, so additional coding is still required

As an alternative to Autotracking, we strongly recommend you spend time carefully planning the tracking and data you need to capture, and have your developers pass this data to Tealium at the appropriate time.

Autotracking may be useful if you are evaluating Tealium and need a quick implementation, but it is unlikely to fulfill all your tracking requirements on its own.

Included Variables

The following variables will be transmitted with each tracking call while the module is enabled:

Variable Name Description Example Value
autotracked Set to true and added to each autotracked tracking call true

Public API

The following methods are available to change the default behavior of the Autotracking module, or to monitor autotracked tracking calls:


tealiumAutotrackingShouldTrack(data: [String:Any]) -> Bool

Parameters Description Example Value
data Dictionary with String keys and Any value type. Values are typically String or [String] ["key":"value"]
func tealiumAutotrackShouldTrack(data: [String:Any]) -> Bool {
   // Filter out View appearance events
   if data["tealium_event_type"] as? String == "view" {
       return false
   return true


tealiumAutotrackDidComplete(success:Bool, info:[String:Any]?, error:Error?)

Parameters Description Example Value
success If the autotracked triggered call was successful. true
info Optional information as a [String:Any] dictionary regarding the track call. Typically holds delivery type info, final call format, and the payload (the data dictionary used to generate the call).  
error Error, if any, returned.  
func tealiumAutotrackDidComplete(success:Bool, info:[String:Any]?, error:Error?) {
    print("Tealium autotrack call completed with info: \(info)")

Future Improvements

  • Migrate fully to Swift
  • Extend API and improve stability to mitigate possible sources of crashes

Change Log

Build 1

  • UI Event Autotracking
  • UIViewController viewDidAppear Autotracking
  • Completion & suppression delegate methods