• Platforms
  • Partners
  • Forums
  • TLC Tealium Learning Center Tealium Learning
    Community
  • Discussions & Ideas Dicussions & Ideas
  • Product Guides Product Guides
  • Knowledge Base Knowledge Base
  • Developer Docs Developer Docs
  • Education Education
  • TLC Blog TLC Blog
  • Support Desk Support Desk
  • CDH Customer Data Hub Customer Data Hub

Table of Contents

  • Class: Tealium
    • addRemoteCommand()
    • addData()
    • consentCategories
    • consentStatus
    • getData()
    • initialize()
    • joinTrace()
    • leaveTrace()
    • removeData()
    • removeRemoteCommand()
    • setVisitorServiceListener()
    • terminateInstance()
    • track()
    • visitorId
NATIVESCRIPT

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
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);

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 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"]);

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.

TealiumConfig

 
  • Mobile
  • Getting Started
    • Overview
    • Quick Start Guide
    • Mobile Concepts
    • Client-Side
    • Server-Side
    • Tracking Webviews
    • Data Layer
    • Consent Management
    • Event Batching
    • User Location and Geofencing
    • Deep Links
    • Timed Events
    • Trace
    • Hosted Data Layer
    • Feature Comparison
    • Troubleshooting
  • Remote Commands
    • Overview
    • How It Works
    • Integrations
      • AppsFlyer
      • Braze
      • Contentsquare
      • Facebook
      • Firebase
      • Kochava
      • Usabilla
  • Android (Java)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Module
      • Optimizely X Tracking Module
    • Android TV
    • Android Wear
    • API Reference
      • ConsentManager
      • DataSources
      • Lifecycle
      • Tealium
      • Tealium.Config
      • TealiumLocation
    • Release Notes
  • Android (Kotlin)
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • Identity Resolution
    • Module List
      • Ad Identifier Module
      • Collect Module
      • Collectors Module
      • Crash Reporter Module
      • Install Referrer Module
      • Lifecycle Tracking Module
      • Location Manager Module
      • RemoteCommands Module
      • Tag Management Dispatcher Module
      • Visitor Service Module
    • Android TV
    • API Reference
      • ConsentCategory
      • ConsentManager
      • CurrentVisit
      • DataLayer
      • Lifecycle
      • LocationManager
      • Tealium
      • TealiumConfig
      • VisitorProfile
      • VisitorService
    • Release Notes
  • Cordova
    • Overview
    • Install
    • Track
    • Data Management
    • Module List
      • Ad Identifier Module
      • Crash Reporter Module
      • Install Referrer Module
    • API Reference
    • Release Notes
  • Flutter
    • Overview
    • Install
    • Track
    • Consent Management
    • Data Management
    • API Reference
    • Release Notes
  • iOS (Objective-C)
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • Consent Management
    • Tag Management
    • Module List
      • Lifecycle Tracking Module
    • tvOS
    • watchOS
    • API Reference
    • Release Notes
  • iOS (Swift) 1.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Data Management
    • App Extensions
    • Identity Resolution
    • Consent Management
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DataSource Module
      • DefaultStorage Module
      • Delegate Module
      • DeviceData Module
      • DispatchQueue Module
      • FileStorage Module
      • Lifecycle Module
      • Location Module
      • Logger Module
      • PersistentData Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
      • VolatileData Module
    • Feature Comparison
    • Working with Objective-C
    • API Reference
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManagerDelegate
      • TealiumConsentManager
      • TealiumInstanceManager
      • TealiumPersistentData
      • TealiumVolatileData
      • Tealium
    • Release Notes
  • iOS (Swift) 2.x
    • Overview
    • Install
    • Track
    • Data Layer
    • Consent Management
    • App Extensions
    • Identity Resolution
    • Modules
    • Module List
      • AppData Module
      • Attribution Module
      • AutoTracking Module
      • Collect Module
      • Connectivity Module
      • CrashReporter Module
      • DeviceData Module
      • Lifecycle Module
      • Location Module
      • RemoteCommands Module
      • TagManagement Module
      • VisitorService Module
    • Working with Objective-C
    • API Reference
      • Tealium
      • TealiumConfig
      • TealiumConsentCategories
      • TealiumConsentManager
      • TealiumDataLayer
      • TealiumInstanceManager
    • Release Notes
  • NativeScript
    • Overview
    • Install
    • Track
    • API Reference
      • Tealium
      • TealiumConfig
    • Release Notes
  • React Native 1.x
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • React Native 2.x
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Unity
    • Overview
    • Install
    • Track
    • API Referencee
  • Xamarin
    • Overview
    • Install
    • Track
    • Data Management
    • Consent Management
    • API Reference
    • Release Notes
  • Web
  • Getting Started
    • Overview
    • Quick Start Guide
    • Web Concepts
  • Adobe Launch
    • Overview
    • Install
    • Data Layer
  • AMP
    • Install
    • Track
    • Data Layer
    • Overview
  • Angular
    • Install
    • Track
    • API Reference
    • Overview
  • Google Tag Manager
    • Overview
    • Data Layer
    • Install
  • JavaScript (Web)
    • Install
    • Track
    • Data Layer
    • Overview
    • Universal Data Object (utag_data)
    • Universal Tag (utag.js)
    • Data Layer Object (b)
    • Single-Page Applications
    • Settings
    • Debugging
    • API Reference
      • Cookie Functions
      • GDPR Functions
      • Tracking Functions
      • Utility Functions
    • Release Notes
  • Server
  • C#
    • Overview
    • Install
    • Track
    • Data Layer
    • API Reference
    • Release Notes
  • HTTP API
    • Overview
    • Endpoint
    • Data Layer
  • Java
    • Overview
    • Install
    • Track
    • API Reference
    • Release Notes
  • Node
    • Overview
    • Install
    • Track
    • API Reference
  • Python
    • Overview
    • Install
    • Track
    • API Reference
  • Roku
    • Overview
    • Install
    • Track
    • API Reference
  • Ruby
    • Overview
    • Install
    • Track
    • API Reference

Was this article helpful?

This page was last updated: January 28, 2021       Thank you for your feedback!
  • Platforms
  • Partners
  • Forums
  • Mobile
  • Getting Started
  • Remote Commands
  • Android (Java)
  • Android (Kotlin)
  • Cordova
  • Flutter
  • iOS (Objective-C)
  • iOS (Swift) 1.x
  • iOS (Swift) 2.x
  • NativeScript
  • React Native 1.x
  • React Native 2.x
  • Unity
  • Xamarin
  • Web
  • Getting Started
  • Adobe Launch
  • AMP
  • Angular
  • Google Tag Manager
  • JavaScript (Web)
  • Server
  • C#
  • HTTP API
  • Java
  • Node
  • Python
  • Roku
  • Ruby