Tealium
The Tealium class serves as the main API entry point for all modules.
Class: Tealium
The following summarizes the commonly used methods and properties of the Tealium
class for the NativeScript plugin.
Method/Property | Description |
---|---|
addRemoteCommand() |
Adds a remote command to the remote command manager |
addData() |
Adds data to persistent data storage |
consentCategories |
Gets or sets the consent categories of a user |
consentStatus |
Gets or sets the consent status of a user |
getData() |
Retrieves data from the data layer |
gatherTrackData() |
Gathers data from all collectors and data layer |
initialize() |
Initializes Tealium with configuration parameters |
joinTrace() |
Joins a trace with the given ID |
leaveTrace() |
Leaves active trace session |
removeData() |
Remove persistent data that has been previously set using addData() |
removeRemoteCommand() |
Removes a remote command from the remote command manager |
removeVisitorServiceListener() |
Removes the visitor service listener/callback |
setVisitorServiceListener() |
Defines the visitor service listener/callback |
terminateInstance() |
Disables the Tealium library and removes all module references |
track() |
Track an event or screen view |
visitorId |
Gets the current visitor ID |
addRemoteCommand()
Adds a remote command to the remote command manager.
Tealium.addRemoteCommand(id, callback);
Parameters | Type | Description | Example |
---|---|---|---|
id |
String |
Name of the remote command ID from the tag configuration | "test_command" |
callback |
Function |
A callback function to execute once the response is received from the remote command. The callback returns a payload of key-value pairs from the tag mappings. | (see example) |
Example:
Tealium.addRemoteCommand('mycommand', (result: any): void => {
console.log(result["payload"]["command_id"]); // logs "mycommand"
console.log(result["payload"]["my_remote_command_key"]); // logs value for key "my_remote_command_key"
});
addData()
Adds data to the persistent data storage for the given expiration time.
Tealium.addData(data, expiry);
Parameters | Type | Description | Example |
---|---|---|---|
data |
Object |
Map of key-value pairs, where keys are strings and the values are either a string or array of strings | {"persistent_key2" : "persistent_val2"} |
expiry |
Expiry |
Length of time for which to persist the data | Expiry.forever |
Example:
let data: Map<string, any> = new Map([['test_session_data', 'test']]);
data.set('my_test_value', 1);
data['my_test_value'] = 1;
Tealium.addData(data, Expiry.session);
Expiry
Defines the expiration time for setting a property that expires.
The following expiry options are available:
Value | Description |
---|---|
Expiry.session (default) |
Expires at the end of the current session |
Expiry.forever |
Never expires while the app is installed |
Expiry.untilRestart |
Expires when device is restarted |
consentCategories
Gets or sets the user’s consent categories.
To set the user’s consent categories:
Tealium.consentCategories = categories
To get the user’s consent categories:
let categories = Tealium.consentCategories
Parameters | Type | Description | Example |
---|---|---|---|
categories |
ConsentCategories[] |
Array of user consent categories | [ConsentCategories.email, ConsentCategories.personalization] |
Example:
Tealium.consentCategories = [ConsentCategories.analytics, ConsentCategories.email];
The following consent categories are available:
Value | Description |
---|---|
analytics |
Analytics |
affiliates |
Affiliates |
displayAds |
Display Ads |
email |
|
personalization |
Personalization |
search |
Search |
social |
Social |
bigData |
Big Data |
mobile |
Mobile |
engagement |
Engagement |
monitoring |
Monitoring |
crm |
CRM |
cdp |
CDP |
cookieMatch |
Cookie Match |
misc |
Misc |
consentStatus
Gets or sets the user’s consent status. Default is .unknown
until changed.
To set the user’s consent status:
Tealium.consentStatus = status;
To get the user’s consent status:
let status = Tealium.consentStatus
Parameters | Type | Description | Example |
---|---|---|---|
status |
ConsentStatus |
User consent status | ConsentStatus.consented |
Example:
Tealium.consentStatus = ConsentStatus.consented;
The following consent status are available:
Value | Description |
---|---|
.consented |
Consented |
.notConsented |
Not Consented |
.unknown |
Unknown |
getData()
Retrieves data from the data layer as any
type.
let data = Tealium.getData(key);
Parameters | Type | Description | Example |
---|---|---|---|
key |
String |
The key of the data to retrieve | "KEY" |
let data: Tealium.getData("KEY")
initialize()
Initialize Tealium before calling any other method.
Tealium.initialize(config);
Parameters | Type | Description | Example |
---|---|---|---|
config |
TealiumConfig |
Tealium configuration parameters | (see example) |
Example:
let config: TealiumConfig =
{
account: 'ACCOUNT',
profile: 'PROFILE',
environment: TealiumEnvironment.dev,
dispatchers: [Dispatchers.Collect,
Dispatchers.TagManagement,
Dispatchers.RemoteCommands],
collectors: [Collectors.AppData,
Collectors.DeviceData,
Collectors.Lifecycle,
Collectors.Connectivity],
consentLoggingEnabled: true,
consentPolicy: ConsentPolicy.gdpr,
visitorServiceEnabled: true
};
Tealium.initialize(config);
joinTrace()
Joins a trace with the specified ID. Learn more about the Trace feature in the Tealium Customer Data Hub.
Tealium.joinTrace(id);
Parameters | Type | Description | Example |
---|---|---|---|
id |
String |
Trace ID retrieved from the data source key | abc123xy |
Example:
Tealium.joinTrace("abc123xy");
leaveTrace()
A trace remains active for the duration of the app session until the leaveTrace()
method is called, which leaves a previously joined trace and ends the visitor session.
Tealium.leaveTrace();
removeData()
Remove persistent data that has been previously set using Tealium.addData()
.
Tealium.removeData(keys);
Parameters | Type | Description | Example |
---|---|---|---|
keys |
String[] |
Array of key names | ["foo", "bar"] |
Example:
Tealium.removeData(["foo", "bar"]);
gatherTrackData()
Gathers all data from all collectors and data layer.
Example:
Tealium.gatherTrackData((response: Map<string, any>): void => {
console.log(response);
});
removeRemoteCommand()
Removes a remote command from the remote command manager.
Tealium.removeRemoteCommand(id);
Parameters | Type | Description | Example |
---|---|---|---|
id |
String |
Name of the command ID to remove | "test_command" |
Example:
Tealium.removeRemoteCommand("test_command");
setVisitorServiceListener()
Defines a callback to execute when the visitor profile has been updated. The updated VisitorProfile
is provided in the callback response.
The VisitorService module implements the Data Layer Enrichment feature of the Tealium Customer Data Hub.
Usage of this module is recommended if you are licensed for Tealium AudienceStream and you want to use the visitor profile to enhance the user experience in your mobile application. If you are not licensed for AudienceStream, usage of this module is not recommended as no visitor profile is returned.
Tealium.setVisitorServiceListener(callback);
Parameters | Type | Description | Example |
---|---|---|---|
callback |
Function |
Code to execute once the updated visitor profile is returned | (see example) |
The following example logs the visitor’s audiences and badges to the console:
Tealium.setVisitorServiceListener(profile => {
console.log(profile["audiences"]);
console.log(profile["badges"]);
});
terminateInstance()
Disables the Tealium library and removes all module references. Re-enable by creating a new Tealium instance if required.
Tealium.terminateInstance();
track()
Track an event or screen view with either a TealiumEvent
or TealiumView
dispatch.
Tealium.track(dispatch);
Parameters | Type | Description | Example |
---|---|---|---|
dispatch |
TealiumDispatch |
Tealium dispatch with the event/view name and data layer | TealiumEvent("button_click", new Map([["button_name", "Submit"]])) |
TealiumView
To track screen views, pass an instance of TealiumView(viewName, data)
to the track()
method. TealiumView
comprises a view name, which appears in the tracking call as tealium_event
, and an optional data dictionary.
let tealView = new TealiumView("VIEW_NAME", new Map([["key", "value"]]));
Tealium.track(tealView);
TealiumEvent
To track non-view events, pass an instance of TealiumEvent(eventName, data)
to the track()
method. TealiumEvent
comprises an event name, which appears in the tracking call as tealium_event
, and an optional data dictionary.
The following is an example:
let tealEvent = new TealiumEvent("EVENT_NAME", new Map([["key", "value"]]));
Tealium.track(tealEvent);
visitorId
Gets the current visitor ID.
let visitorId = Tealium.visitorId;
TealiumDispatch
An interface that defines what type of dispatch is tracked, along with the name or title of the event and the data layer.
This page was last updated: May 9, 2024