TagManagement Module
A client-side implementation of the Universal Tag (utag.js) which uses a non-rendered WKWebView instance to execute JavaScript.
Usage
The TagManagement module is a client-side implementation of the Universal Tag (utag.js
) which uses a non-rendered WKWebView
instance to execute JavaScript. This module is required in apps that make use of Tealium iQ Tag Management. It is automatically included in Carthage and CocoaPods framework builds.
Supported Platforms
- iOS
Requirements
- WebKit (WKWebView)
Install
Install the TagManagement module with CocoaPods or Carthage.
CocoaPods
To install the TagManagement module with CocoaPods, add the following pod to your Podfile:
pod 'tealium-swift/TealiumTagManagement'
The framework is auto-instantiated. It has a dependency on the TealiumCore
pod. Learn more about CocoaPods installation for iOS.
Carthage
To install the TagManagement module with Carthage, following these steps:
-
Go to the app target’s General configuration page in Xcode.
-
Add the following framework to the Embedded Binaries section:
TealiumTagManagement.framework
The framework is auto-instantiated. It has a dependency on TealiumCore
. No additional import statements are necessary. Learn more about Carthage installation for iOS.
Data Layer
The following variables are transmitted with each tracking call:
Variable | Type | Description | Example |
---|---|---|---|
dispatch_service |
String |
Static string to indicate which module the tracking call came from | "tagmanagement" |
Public API
The WKWebView protocols are accessible by adding another object conforming the WKWebView
delegate to the module’s multicast delegate:
tealium.tagManagement()?.delegates.add(MY_OBJECT)
About WKWebView
Prior to version 1.7.0, this module used UIWebView
which is now deprecated in favor of WKWebView
. The OS requires that WKWebView
always be attached to a UIView
, even if it is not rendered. If it is not attached to a UIView, the OS severely throttles the performance and the JavaScript executes suboptimally. To accommodate this the Tag Management module attempts to attach the non-rendered WKWebView to the root UIView of your app.
If your app has a complex view hierarchy and the module cannot detect the rootViewController
, initialize TealiumConfig with a view to attach to in viewDidLoad
, viewWillAppear:
, or viewDidAppear:
.
Release 1.7.1 significantly improves the auto-detection of views and removes the need to specify a view in most scenarios. But you must test this in your app to verify that tracking calls are sent correctly. See Release Notes for full details.
If your app jumps to a UIViewController
upon receiving a push notification, and has a different view hierarchy than when Tealium was initialized, you must update the current UIView
using the following API method.
override func viewDidLoad() {
super.viewDidLoad()
// this view does not have a navigation controller
if self.navigationController == nil {
// update the current root UIView on the Tealium instance
tealium?.updateRootView(self.view)
}
// Do any additional setup after loading the view.
}
See the sample app Swift-WKWebView for a full example.
WKWebView
and UIWebView
use different methods to store cookies (WKHTTPCookieStore
and HTTPCookieStorage
respectively), so the module automatically synchronizes cookies the first time that WKWebView is launched. The cookies in HTTPCookieStorage
are not deleted, but eventually expire on their own.
The shouldAddCookieObserver
method allows you to use your own cookie observer during cookie synchronization, which requires a cookie observer to retrieve cookies on the main thread after setting them. This issue is caused by bugs in WKWebView
, which prevents your own observer from being called.
This page was last updated: January 7, 2023