iOS WebView Implementation
Ketch Smart Tag for an iOS application
This document demonstrates the Ketch Smart Tag usage for the Swift based native iOS application.
It handles the storage of the corresponding policy strings to SharedPreferences,
as per standards requirements for the in-app support:
Prerequisites
- Registered Ketch organization account
- Configured application property record
- Custom identity space
- index.html Ketch Smart Tag integration bridge
Quick Start
Step 1. Copy the integration bridge into the app
Add an index.html file with privacy web form wrapper to your project.
The index.html
file makes use of WebKit WKWebView
and JavascriptInterface
to
communicate back and forth with the native runtime of the iOS application.
Step 2. Add Info.plist privacy tracking request
Define Info.plist
string for tracking allowance request with key
Privacy - Tracking Usage Description
(NSUserTrackingUsageDescription
)
that describes wanted purpose, e.g. "Please indicate whether you consent to our collection and use
of your data in order to perform the operation(s) you’ve requested."
Step 3. Create the Ketch Preferences Center view with the webView
Integrate source code of preference settings view controller to your project.
File for SwiftUIt integration: ConsentView
And add source code for config: ConsentConfig
Step 4. Integrate calls for presentation of preference settings view (or view controller)
- Request permission for application tracking using
requestTrackingAuthorization
fromAppTrackingTransparency.ATTrackingManager
:
import AppTrackingTransparency
...
ATTrackingManager.requestTrackingAuthorization { authorizationStatus in
if case .authorized = authorizationStatus {
...
}
}
- Retrieve
advertisingIdentifier
fromAdSupport.ASIdentifierManager
:
import AppTrackingTransparency
import AdSupport
...
ATTrackingManager.requestTrackingAuthorization { authorizationStatus in
if case .authorized = authorizationStatus {
let advertisingId = ASIdentifierManager.shared().advertisingIdentifier
...
}
}
- Create ConsentConfig by .configure(:...) method and save it for future preferencesCenter launch. To keep the activity as configurable as the Ketch Smart Tag on the HTML page, it expects an organization code and property code to be passed in to it:
import AppTrackingTransparency
import AdSupport
...
private var config: ConsentConfig?
struct ContentView: View {
...
var body: some View {
...
.onAppear {
ATTrackingManager.requestTrackingAuthorization { authorizationStatus in
if case .authorized = authorizationStatus {
let advertisingId = ASIdentifierManager.shared().advertisingIdentifier
self?.config = ConsentConfig.configure(
orgCode: "#{your_org_code}#",
propertyName: "#{your_property}#",
advertisingIdentifier: advertisingId
)
}
}
}
}
- Show PreferenceCenter once you need to launch preferences setup:
...
.sheet(item: $configItem) { configItem in
ConsentView(config: configItem)
}
- Full integration code with config:
import AppTrackingTransparency
import AdSupport
...
private var config: ConsentConfig?
struct ContentView: View {
@State private var configItem: ConsentConfig?
var body: some View {
VStack {
Button("Show Preference Center") {
configItem = config
}
}
.onAppear {
ATTrackingManager.requestTrackingAuthorization { authorizationStatus in
if case .authorized = authorizationStatus {
let advertisingId = ASIdentifierManager.shared().advertisingIdentifier
config = ConsentConfig.configure(
orgCode: "#{your_org_code}#",
propertyName: "#{your_property}#",
advertisingIdentifier: advertisingId
)
}
}
}
.sheet(item: $configItem) { configItem in
ConsentView(config: configItem)
}
...
}
}
Check out our iOS samples repo for a full example.
Updated 3 months ago