Tealium
The Tealium class serves as the main API entry point for all modules.
This is the previous version (2.x) of Tealium for Flutter. For the latest version, see Tealium for Flutter.
Class: Tealium
The following summarizes the commonly used methods of the Flutter Tealium class.
| Method | Description |
|---|---|
addCustomRemoteCommand() |
Adds a remote command callback to the remote command manager. |
addRemoteCommand() |
Adds a remote command to the remote command manager |
addToDataLayer() |
Adds data to persistent data layer |
clearStoredVisitorIds() |
Deletes the stored cache of visitor IDs and calls resetVisitorId. |
gatherTrackData() |
Gathers data from all collectors and data layer |
getFromDataLayer() |
Gets the value for a specified key in the persistent data layer |
getConsentCategories() |
Gets the user’s consented categories |
getConsentStatus() |
Gets the user’s consent status |
getVisitorId() |
Gets the user’s visitor ID |
initialize() |
Initializes Tealium with configuration parameters |
joinTrace() |
Joins a trace with the given ID |
leaveTrace() |
Leaves a previously joined traced and ends the visitor session |
removeFromDataLayer() |
Removes a list of persistent data keys-value pairs that was previously set using addToDataLayer() |
removeRemoteCommand() |
Removes a remote command from the remote command manager |
resetVisitorId() |
Generates a new visitor ID for the user. |
setConsentCategories() |
Sets the consent categories of a user |
setConsentExpiryListener() |
Sets the consent expired listener/callback |
setConsentStatus() |
Sets the user’s consent status |
setVisitorIdListener() |
Add a listener for changes on visitorId. |
setVisitorServiceListener() |
Sets the visitor service listener/callback |
terminateInstance() |
Terminates the Tealium instance by disabling the Tealium library and removing all module references |
track() |
Track an event or screen view |
addCustomRemoteCommand()
Adds a custom remote command to the remote command manager, backed up by a Tag on Tealium iQ Tag Management.
Tealium.addCustomRemoteCommand(id, callback);
| Parameters | Type | Description | Example |
|---|---|---|---|
id |
String |
Name of the command ID from the tag configuration | "test_command" |
callback |
Function |
A callback function to execute after receiving the response from the remote command. The callback returns a payload of key-value pairs from the tag mappings. | (see example) |
Example:
Tealium.addCustomRemoteCommand('CUSTOM_COMMAND_ID', (payload) {
print(JsonEncoder().convert(payload));
});
addRemoteCommand()
Adds a remote command to the remote command manager.
Tealium.addRemoteCommand(remoteCommand);
| Parameters | Type | Description | Example |
|---|---|---|---|
remoteCommand |
RemoteCommand |
A prebuilt remote command with either path, URL, or webview configurations. | See example below. |
Example:
Tealium.addRemoteCommand(RemoteCommand(TealiumFirebase.commandName, path: "firebase.json")); // local
Tealium.addRemoteCommand(RemoteCommand(TealiumFirebase.commandName, url: "www.tealium.com/path_to_remote_command/firebase.json")); // remote
Tealium.addRemoteCommand(RemoteCommand(TealiumFirebase.commandName)); // webview
addToDataLayer()
Adds data to the persistent data layer for the given expiration.
Tealium.addToDataLayer(data, expiry);
| Parameters | Type | Description | Example |
|---|---|---|---|
data |
Map<String, Object> |
JSON object of key-value pairs, where keys are strings and the values are either a string or array of strings | {'persistent_key' : 'persistent_val'} |
expiry |
Expiry |
Length of time for which to persist the data | Expiry.forever |
clearStoredVisitorIds()
Clears all previously stored visitor IDs and hashed customer identifiers.
Tealium.clearStoredVisitorIds();
getFromDataLayer()
Gets the value for a specified key in the persistent data layer as a callback function.
Tealium.getFromDataLayer(key);
| Parameter | Type | Description |
|---|---|---|
key |
String |
Key to retrieve from the data layer |
N/A |
Future<dynamic> |
Future succeeds after value was successfully retrieved from Tealium.dataLayer |
Example:
Tealium.getFromDataLayer('key')
.then((value) => print('Value From data layer: $value'));
getConsentCategories()
Gets the user’s consented categories.
Tealium.getConsentCategories();
| Parameter | Type | Description |
|---|---|---|
N/A |
Future<List<dynamic>> |
Future completes after the consent categories have been successfully retrieved from the Tealium.ConsentManager |
Example:
Tealium.getConsentCategories()
.then((categories) =>
print('Consent Categories: ' + categories.join(",")));
getConsentStatus()
Gets the user’s consent status as a callback function.
Tealium.getConsentStatus();
| Parameter | Type | Description |
|---|---|---|
N/A |
Future<String> |
Future completes after the consent status was successfully retrieved from the Tealium.ConsentManager |
Example:
Tealium.getConsentStatus()
.then((status) => print('Consent Status: $status'));
getVisitorId()
Gets the user’s visitor ID as a callback function.
Tealium.getVisitorId();
| Parameter | Type | Description |
|---|---|---|
N/A |
Future<String> |
Future returns after the Tealium.visitorId was successfully retrieved |
initialize()
Initialize Tealium before calling any other method.
Tealium.initialize(config);
| Parameter | Type | Description |
|---|---|---|
config |
TealiumConfig |
Configuration |
N/A |
Future<bool> |
Future completes after the Tealium initialization is successful |
Example:
final config = TealiumConfig(
'ACCOUNT',
'PROFILE',
TealiumEnvironment.dev,
[
Collectors.AppData,
Collectors.DeviceData,
Collectors.Lifecycle,
Collectors.Connectivity,
],
[
Dispatchers.Collect,
Dispatchers.TagManagement,
Dispatchers.RemoteCommands,
],
loglevel: LogLevel.DEV,
consentLoggingEnabled: true,
consentPolicy: ConsentPolicy.GDPR,
visitorServiceEnabled: true);
Tealium.initialize(config).then((_) {
print('Tealium Initialized');
Tealium.setConsentStatus(ConsentStatus.consented);
Tealium.setConsentExpiryListener(() => print('Consent Expired'));
});
joinTrace()
Joins a trace with the specified ID. Learn more about Trace.
Tealium.joinTrace(id);
| Parameter | Type | Description | Example |
|---|---|---|---|
id |
String |
Trace ID retrieved from the CDH | "abc123xy" |
leaveTrace()
Leaves a previously joined traced and ends the visitor session. The trace remains active for the duration of the app session until this method is called.
Tealium.leaveTrace();
removeFromDataLayer()
Remove persistent data that was previously set using addToDataLayer().
Tealium.removeFromDataLayer(keys);
| Parameter | Type | Description | Example |
|---|---|---|---|
keys |
List<String> |
Array of key names | ["key1", "key2"] |
removeRemoteCommand()
Removes a remote command from the remote command manager.
Tealium.removeRemoteCommand(id);
| Parameter | Type | Description | Example |
|---|---|---|---|
id |
String |
Name of the command ID to remove | "test_command" |
Example:
Tealium.removeRemoteCommand('test_command');
resetVisitorId()
Generates a new visitor ID for the user.
Tealium.resetVisitorId();
setConsentCategories()
Sets the consent categories of a user. Pass in an array of Strings to set the categories. Default is an empty array until ConsentStatus is set to ConsentStatus.consented. If the consent status is ConsentStatus.consented and no categories are specified with the setConsentCategories() method, then all categories are set.
Tealium.setConsentCategories(categories);
| Parameter | Type | Description | Example |
|---|---|---|---|
categories |
List<ConsentCategories> |
Array of user consent categories | [ConsentCategories.email, ConsentCategories.personalization] |
Example:
Tealium.setConsentCategories([ConsentCategories.analytics, ConsentCategories.email]);
Consent categories
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 |
setConsentExpiryListener()
Sets a callback to execute after the user’s consent preferences have expired according the ConsentExpiry.
Tealium.setConsentExpiryListener(callback);
| Parameter | Type | Description |
|---|---|---|
callback |
Function |
Code to execute after consent expires |
Tealium.setConsentExpiryListener(() {
print('Consent Expired');
});
setConsentStatus()
Sets the consent status of a user. Default is ConsentStatus.unknown until the status is updated.
Tealium.setConsentStatus(status);
| Parameter | Type | Description |
|---|---|---|
status |
ConsentStatus |
Consent status |
Example:
Tealium.setConsentStatus(ConsentStatus.consented);
Consent status
The following consent statuses are available:
| Value | Description |
|---|---|
ConsentStatus.consented |
Consented |
ConsentStatus.notConsented |
Not consented |
ConsentStatus.unknown |
Unknown |
setVisitorIdListener()
Sets a callback to execute when the visitor ID changes.
Tealium.setVisitorIdListener(callback);
| Parameter | Type | Description |
|---|---|---|
callback |
Function |
Code to execute with the updated visitorId. |
Example:
Tealium.setVisitorIdListener((newVisitorId) {
print(newVisitorId);
});
setVisitorServiceListener()
Sets a callback to execute when the visitor profile is 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);
| Parameter | Type | Description |
|---|---|---|
callback |
Function |
Code to execute after the updated visitor profile returns |
Example:
Tealium.setVisitorServiceListener((profile) {
print(JsonEncoder().convert(profile));
});
terminateInstance()
Terminates the Tealium instance by disabling the Tealium library and removing all module references. Re-enable by creating a new Tealium instance, if required.
Tealium.terminateInstance();
track()
Tracks a screen view or event with optional event data.
Tealium.track(tealEvent);
| Parameter | Type | Description |
|---|---|---|
tealEvent |
TealiumDispatch |
Tealium dispatch with the event name and event data. |
To track view or events, pass an instance of TealiumView or TealiumEvent to the track() method:
final tealEvent = TealiumEvent(
'cart_add',
{
'customer_id': 'abc123',
'product_id': ["PROD123", "PROD456"],
'product_price': [4.00, 6.00]
}
);
Tealium.track(tealEvent);
gatherTrackData()
Gathers all data from all collectors and data layer.
Example:
Tealium.gatherTrackData()
.then((data) => print('Gather track data: $data'));
Interface: TealiumDispatch
An interface that defines the type of dispatch to be tracked. The following classes implement TealiumDispatch:
Class: TealiumEvent
To track a user’s interaction with a screen or a screen view, pass an instance of TealiumEvent(eventName, dataLayer) to the track() method. TealiumEvent consists of an event name, which appears in the tracking call as tealium_event, and an optional data dictionary.
final tealEvent = TealiumEvent(eventName, dataLayer);
Tealium.track(tealEvent);
| Parameters | Type | Description |
|---|---|---|
eventName |
String |
The event name, passed as the tealium_event attribute. |
dataLayer |
Map<String, Object> |
(Optional) Data to be sent with the event in key-value format. |
Example:
final tealEvent = TealiumEvent(
'cart_add',
{
'customer_id': 'abc123',
'product_id': ["PROD123", "PROD456"],
'product_price': [4.00, 6.00]
}
);
Tealium.track(tealEvent);
Class: TealiumView
To track screen views, pass an instance of TealiumView(viewName, dataLayer) to the track() method. TealiumView consists of a view name, which appears in the tracking call as tealium_event, and an optional data object.
final screenView = TealiumView(viewName, dataLayer);
Tealium.track(screenView);
| Parameters | Type | Description |
|---|---|---|
viewName |
String |
The view name, passed as the tealium_event attribute. |
dataLayer |
Map<String, Object> |
(Optional) Data to be sent with the event in key-value format. |
Example:
final screenView = TealiumView(
'purchase',
{
'customer_id': 'abc123',
'order_total': 10.00,
'product_id': ["PROD123", "PROD456"],
'order_id': '0123456789'
}
);
Tealium.track(screenView);
This page was last updated: March 31, 2026