How It Works
Remote commands are a client-side solution for triggering functionality in your native app.
Use remote commands in two ways:
- Vendor Integrations
Tealium offers pre-built remote command modules that implement a vendor’s native API. See the list of remote command integrations. - Custom Commands
Define your own native custom commands and trigger them using the Custom Remote Command tag in Tealium iQ Tag Management.
Vendor Integrations
A vendor integration is a pre-built remote command module that installs the vendor SDK and defines native code handlers for the vendor’s API.
Implementing a vendor integration requires the following:
- Vendor remote command module
In your app build scripts, replace the vendor SDK with the Tealium remote command module. The remote command module handles the vendor SDK installation and setup for you. - Configuration (Choose one of the following)
- JSON File
A JSON file, loaded locally or hosted remotely, containing the vendor settings, data mappings, and event triggers. - Remote Command Tag
A tag in iQ Tag Management that offers configuration options for the vendor’s API (for use with the Tag Management module).
- JSON File
See the list of remote command vendor integrations.
JSON File
Configure a vendor integration using a JSON file. Load this file locally in the app or from a remotely hosted URL. A JSON template file is available for each vendor integration.
Mappings
A JSON template file has three main sections: config
, mappings
, and commands
.
config
This section sets vendor SDK initialization options such as client ID, API key, or the log level. For example, the following sets the application ID:{ "config": { "applicationid": "appid123" } }
mappings
This section defines your data mappings. The following mapping assigns the data layer variableproduct_id
to the vendor parameterparam_item_id
.{ "mappings": { "product_id": "param_item_id" } }
The vendor parameter may use a prefix with dot notation to scope a mapping to a specific object in the payload. The prefix defines the object and the value to the right of the
.
becomes a property of the object. For example, the following mapping assignsproduct_id
to theparam_item_id
variable of theevent
object. The remote commands parser creates anevent
object withparam_item_id
as one of its properties.{ "mappings": { "product_id": "event.param_item_id" } }
The object prefix is typically
event.
,product.
, orpurchase.
, but may be any custom object name. Refer to the JSON template files to see the object prefixes used for your vendor integration.commands
This section maps Tealium event names to the vendor’s events. The value left of the:
is the Tealium event name and the right value is the Tealium wrapper for the vendor’s method. In the following example, the Tealium eventcart_add
is mapped to the vendor methodlogevent
:{ "commands": { "cart_add": "logevent" } }
Example
The following is an example JSON configuration:
{
"config": {
"analytics_enabled": "true",
"session_timeout_seconds": "30",
"log_level": "max",
"minimum_seconds": "100",
...
},
"mappings": {
"event_title": "event_name",
"product_brand": "event.param_item_brand",
"product_category": "event.param_item_category",
"product_id": "event.param_item_id",
"product_list": "event.param_item_list",
"product_location_id": "event.param_item_location_id",
"product_name": "event.param_item_name",
"product_variant": "event.param_item_variant",
...
},
"commands": {
"launch": "config",
"cart_add": "logevent",
...
}
}
Load Options
There are two options for loading the JSON configuration file: as a local file or from a hosted URL.
To use a local configuration file stored in your iOS (Swift) app:
let config = TealiumConfig(account: "ACCOUNT",
profile: "PROFILE",
environment: "ENVIRONMENT")
config.dispatchers = [Dispatchers.TagManagement, Dispatchers.RemoteCommands]
config.remoteAPIEnabled = true
tealium = Tealium(config: config) { _ in
guard let remoteCommands = self.tealium?.remoteCommands else {
return
}
let facebook = FacebookRemoteCommand(type: .local(file: "facebook"))
remoteCommands.add(facebook)
}
Host the configuration file, accessible as a URL, using the hosted data layer.
To use the hosted configuration file in your iOS (Swift) app:
let config = TealiumConfig(account: "ACCOUNT",
profile: "PROFILE",
environment: "ENVIRONMENT")
config.dispatchers = [Dispatchers.TagManagement, Dispatchers.RemoteCommands]
config.remoteAPIEnabled = true
tealium = Tealium(config: config) { _ in
guard let remoteCommands = self.tealium?.remoteCommands else {
return
}
let facebook = FacebookRemoteCommand(type: .remote(url: "https://tags.tiqcdn.com/dle/ACCOUNT/PROFILE/facebook.json"))
remoteCommands.add(facebook)
}
To use a local configuration file stored in your Android (Kotlin) app:
val config = TealiumConfig(application,
"ACCOUNT", "PROFILE",
Environment.DEV,
dispatchers = mutableSetOf(Dispatchers.RemoteCommands));
var tealium = Tealium.create(TEALIUM_MAIN, config) {
val facebook = FacebookRemoteCommand(this);
remoteCommands?.add(facebook, filename = "facebook.json");
}
Host the configuration file, accessible as a URL, using the hosted data layer.
To use the hosted configuration file in your Android (Kotlin) app:
val config = TealiumConfig(application,
"ACCOUNT", "PROFILE",
Environment.DEV,
dispatchers = mutableSetOf(Dispatchers.RemoteCommands));
var tealium = Tealium.create(TEALIUM_MAIN, config) {
val facebook = FacebookRemoteCommand(this);
remoteCommands?.add(facebook, remoteUrl = "https://tags.tiqcdn.com/dle/ACCOUNT/PROFILE/facebook.json");
}
Vendor Templates
The following remote command JSON templates are available.
Custom Commands
When using iQ Tag Management in your app, custom remote commands provide the ability to trigger native code blocks from the non-rendered webview. This is used in cases where data held inside the non-rendered webview needs to be passed back to the native code for further processing.
Remote commands use custom URL schemes as a way for JavaScript tags to trigger methods in your app. A tag in the non-rendered webview sends the app requests which are processed by a remote command handler that triggers custom code or a vendor SDK.
Components
A remote command has a command name and a payload of data.
- Command
The name of the command, or command ID, registered with native code in your app. - Payload
The data passed to the native app and received as an object namedrequestPayload
in the response callback of the handler.
Define remote commands in your native app at build time. The Custom Remote Command tag only executes pre-defined code on the device.
Native Code
In the native code, the add()
function registers a remote command handler. The callback function response
has access to the payload with response.payload
. In the following example, the referenced payload variables have a matching data layer variable configured in iQ Tag Management.
tealium = Tealium(config: config) { [weak self] _ in
let remoteCommand = RemoteCommand(commandId: "myRemoteCommand", description: "") { response in
guard let payload = response.payload,
let myVariable = payload["myVariable"] as? String else {
return
}
print(myVariable)
}
self.tealium?.remoteCommands?.add(remoteCommand)
}
val remoteCommand = object : RemoteCommand("sample", "testing RCs") {
override fun onInvoke(response: Response) {
Logger.dev(BuildConfig.TAG, "ResponsePayload for webView RemoteCommand ${response.requestPayload}")
}
}
val tealium = Tealium.create(instanceName, config) {
remoteCommands?.add(webViewRemoteCommand)
}
Add a module for the vendor integration to the build script for your platform. Modules are named in the format of TealiumVendorXYZ
, for example TealiumBraze
.
To install, replace the vendor’s dependency with the Tealium remote command dependency. For example, remove the following line:
pod "VendorXYZ-iOS-SDK"
Then add the following line:
pod "TealiumVendorXYZ"
Use Case: Purchase Survey
The following steps demonstrate how to use a remote command to trigger a survey in your app after a user completes a purchase.
- Create native code that prompts the user to take a survey, passing the message and URL as method parameters (from the non-rendered webview).
- Register the block of code as a remote command with the Tealium API.
- Add the Custom Remote Command tag in iQ Tag Management and set the command ID to the same command registered in the native code.
- Set data mappings to pass specific variables back to the app, such as
survey_title
orsurvey_url
. - In the native code, use the variables passed back in the response payload to display the survey to the user.
After completing these steps, you are able to configure the survey title, URL, and logic using extensions in iQ Tag Management without re-deploying your app.
Remote Command Tag
Use iQ Tag Management where a remote command is set up as an instance of the custom Remote Command tag with the following settings:
- Command ID
The name of the command (the same name used in the native methodaddRemoteCommandID
). - Load rule
A rule to determine when to trigger the remote command. - Mapped variables
The data to include in the remote command. Mapped data layer variables are available in theresponse.requestPayload
object in the native code callback.
Example Remote Command Tag
The following is an example of a tracked event in Swift.
tealium?.track(
title: "My Screen",
data: ["tealium_event": "my_event", "my_variable": "my_value"]
);
The tag setup is defined as follows:
- Command ID
myRemoteCommand
- Load rule
IF tealium_event EQUALS my_event
- Mapped variable
my_variable -> myVariable
The following screenshots show the example configured in iQ Tag Management.