To help familiarize yourself with the Tealium library, tracking methods, and best practice implementation, it is recommended to download the Swift sample apps.
To abstract the Tealium implementation from the rest of your app, we recommend the use of the sample helper class. This gives you a single entry point from which to initialize and make tracking calls. It also allows you to update the code in your helper file, and not in every single ViewController or Swift file.
Install the Tealium for iOS library with CocoaPods, Carthage or manually.
To install the Tealium for iOS library with CocoaPods (recommended):
Add the Tealium Swift pod to your Podfile:
To install the pod, run the following command:
If the command doesn’t find the correct Pods, try running the command pod repo update.
Open your Xcode project using the .xcworkspace file (Do not use the .xcodeproj file).
To import any number of modules, add the following import statement in the file you plan to instantiate Tealium from:
The following is the recommended Podfile:
To disable specific modules from the Podfile, comment them out in the Podfile with #.
# 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. Installs separate TealiumCrashReporter dependency (based on PLCrashReporter).# pod "tealium-swift/Crash"
The full Podfile imports the entire Tealium for iOS (Swift) library, including all modules specified as optional:
# 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
To disable specific modules, see the TealiumModulesList struct and relevant methods to blacklist the modules in the TealiumConfig class.
To install Tealium for iOS (Swift) library with Carthage:
Add the following to your Cartfile:
To produce frameworks for iOS, macOS, tvOS and watchOS, run the following command:
To build only for a particular platform such as “iOS”, and to speed up subsequent builds after the initial build, use Carthage’s --platform argument:
carthage update --platform ios --cache-builds
Drag the frameworks you require into your Xcode project’s General > Embedded Binaries section.
Make sure the Tealium frameworks have been added to the Embedded Binaries section in your project settings, otherwise your app crashes at launch.
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.
About Modules (1.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.
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
Due to Carthage limitations, we had to choose between the convenience of importing the entire SDK, 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 builds all the modules and output the resulting .framework files into your Carthage build directory.
Delete any modules you don’t need, and drag the modules that you do need into Xcode.
See Modules for further details on recommended module lists.
To install Tealium for iOS (Swift) library manually:
Download Tealium for Swift for the full source code, and copy it into your Xcode project.
Import the Tealium folder into your project
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 along with either of the dispatch modules: TagManagement or Collect. If a dispatch module is not added, the app does not transmit any data.
To initialize Tealium, pass a TealiumConfig instance to the Tealium() constructor, as shown in the following example: