Install

Install Tealium for Swift

CocoaPods

CocoaPods is a centralized dependency manager for iOS, which supports both Objective-C and Swift across Apple’s iOS, tvOS, watchOS and macOS platforms. It is not the only dependency manager for the Apple platforms, but it is certainly one of the most common.

Follow these steps:

Add the Tealium Swift pod to your Podfile using your favorite text editor. The pod is called “tealium-swift” (see example in the Full Podfile section below. Optionally, you may implement the modular pods instead using the subspecs listed in the Recommended Podfile section below.

Run pod install in the terminal and allow the installation to complete. If this doesn’t find the correct Pods, you may need to run pod repo update.

Open your Xcode project (remembering to use the “.xcworkspace” file instead of “.xcodeproj”).

In the file you are planning to instantiate Tealium from, add a new import statement: import TealiumSwift

This import remains the same whether you are using the full set of modules, or only a subset.

That’s it! You may now use the Tealium Swift library in your app.

Recommended Podfile

The following is our recommended Podfile. If you do not require certain features, simply comment out the lines you don’t need, and these modules will not be compiled into your app.

# Podfile# replace CPodTest with your target
target 'CPodTest'do# Comment the next line if you're not using Swift and don't# want to use dynamic frameworks
use_frameworks!# Pods for CPodTest# *** Recommended minimum:# Only disable if you're sure you don't need them. ***# All pods depend on Core. Supports all platforms.
pod "tealium-swift/Core"# All platforms. Provides important info about# the app bundle.
pod "tealium-swift/TealiumAppData"# All platforms. Sends data to UDH.
pod "tealium-swift/TealiumCollect"# All platforms. Assists with GDPR/privacy compliance.
pod "tealium-swift/TealiumConsentManager"# iOS, macOS, tvOS only. Detects connectivity state and# queues track calls while offline.# Should be used in conjunction with# TealiumDispatchQueue module.
pod "tealium-swift/TealiumConnectivity"# All platforms. Adds "tealium_datasource" to each# dispatch, and extends TealiumConfig class.
pod "tealium-swift/TealiumDataSource"# All platforms. Stores persistent data to File Storage.# Bundles PersistentData module.# Should not be used if DefaultsStorage module is in use.# Pick the option that best suits you.# pod "tealium-swift/TealiumFileStorage"# All platforms. Enables the use of delegates# and completion handlers on the Tealium class.
pod "tealium-swift/TealiumDelegate"# All platforms. Adds device information to each dispatch.
pod "tealium-swift/TealiumDeviceData"# All platforms. Enables offline storage of queued events.# (required for Consent, Connectivity).
pod "tealium-swift/TealiumDispatchQueue"# All platforms. Add app lifecycle information to each dispatch.
pod "tealium-swift/TealiumLifecycle"# All platforms. Enables logging information to the LLDB console.
pod "tealium-swift/TealiumLogger"# iOS only. Used with the TagManagement module to trigger Remote Commands
pod "tealium-swift/TealiumRemoteCommands"# iOS only. Enables Tealium iQ Tag Management.
pod "tealium-swift/TealiumTagManagement"# All platforms. Adds important data to each dispatch, and enables temporary storage of data for the current session.
pod "tealium-swift/TealiumVolatileData"# *** Optional modules: You may not need these modules. Enable as required. *** ## iOS Only. Gathers app attribution data and advertising IDs.# pod "tealium-swift/TealiumAttribution"# iOS and tvOS only. Generally not recommended. See separate notes in module documentation.# pod "tealium-swift/TealiumAutotracking"# All platforms. Stores persistent data to UserDefaults. Bundles PersistentData module. Should not be used if FileStorage module is in use.
pod "tealium-swift/TealiumDefaultsStorage"# iOS only. Reports detailed crash information. Will install separate TealiumCrashReporter dependency (based on PLCrashReporter).# pod "tealium-swift/Crash"
end

Full Podfile

Imports the entire Tealium library, including all modules specified as optional. You must use the TealiumModulesList on the TealiumConfig class to disable unneeded modules.

# Uncomment the next line to define a global platform for your project
platform :ios, '9.0'
target 'CPodTest'do# Comment the next line if you're not using Swift and don't want to use dynamic frameworks
use_frameworks!# Pods for CPodTest# new entry for Tealium pod
pod 'tealium-swift'
end

Carthage

Carthage is a popular decentralized dependency manager for the various Apple platforms (iOS, tvOS, watchOS, macOS). You can find out more about Carthage here: https://github.com/Carthage/Carthage
You can install Carthage manually or using Homebrew (recommended). If using Homebrew, you can install Carthage with the following command:

brew install carthage

Then follow these steps:

Add the following entry to your Cartfile:
github "tealium/tealium-swift"

Run carthage update in your terminal window, which will produce frameworks for the following platforms:

iOS

macOS

tvOS

watchOS

To build only for a particular platform, use Carthage’s –platform argument:
carthage update --platform ios --cache-builds (--cache-builds will speed up subsequent builds after the initial build)

Be sure to follow the instructions listed in the Carthage Getting Started documentation to add the relevant Build Phases scripts, to ensure you don’t run into any issues when submitting your app.

Make sure the Tealium frameworks have been added to the Embedded Binaries section in your project settings, otherwise your app will crash at launch.

About Modules (v1.6.5)

As of version 1.6.5, the Tealium Swift SDK has been split up into separate modules/frameworks. This means you need only import the specific frameworks for the modules you need to use, which helps to reduce the binary size and, ultimately, increase your app’s performance.

Due to some current limitations in Carthage, we had to choose between the convenience of importing the entire SDK in one go, and the flexibility and performance gains of a fully modular install. The downside to this is that it’s now necessary to add each module you wish to use individually. Carthage will build all the modules and output the resulting .framework files into your Carthage build directory, but you can delete any modules you don’t need, and just drag into Xcode those that you do need.

Module Import Statements

importTealiumCore// required for Tealium, TealiumConfig, TealiumInstanceManagerimportTealiumVolatileData// required if you wish to store volatile data through the Volatile Data APIimportTealiumFileStorageimportTealiumDefaultsStorage// required if you need to store persistent dataimportTealiumRemoteCommands// required if you need to interact with the Remote Commands APIimportTealiumDelegate// required if you need to set up a tracking delegateimportTealiumDataSource// allows datasource param to be set on the TealiumConfig class instanceimportTealiumLifecycle// only required if you need to manually call the Lifecycle API

Manual

The full source code for the Swift Library is available on GitHub, and, as such, you can manually install the library by simply copying the required code into your Xcode project.

Import the Tealium folder into your project and add the desired modules. The library employs a drag-and-drop modular architecture when the source files are referenced directly. Each subfolder within tealium-swift/tealium contains all the files related to that module. The Core submodule is required and you should also implement either the TagManagement or Collect module in order for dispatches to be sent. If no dispatch modules are added, the app will not transmit any data.