Tealium
The Tealium class serves as the main API entry point for all modules.
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 . |
deleteFromDataLayer() |
Deletes a single key-value pair from the data layer that was previously set using addToDataLayer() |
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 listerner 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.addRemoteCommand('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 |
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()
deleteFromDataLayer()
Deletes a single key-value pair from the data layer that was previously set using addToDataLayer()
.
Tealium.deleteFromDataLayer(key);
Parameters | Type | Description | Example |
---|---|---|---|
key |
String |
Key to retrieve from the data layer | "key_to_delete" |
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<ConsentCategories>> |
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(callback);
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 |
config |
Configuration |
N/A |
Future<String> |
Future returns true if the Tealium initialization is successful, or false if there is an error |
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],
loglevel: LogLevel.DEV,
consentLoggingEnabled: true,
consentPolicy: ConsentPolicy.GDPR,
visitorServiceEnabled: true
};
Tealium.initialize(config)
.then((value) => {
if (value)
{
print('Tealium Initialized'),
Tealium.setConsentStatus(ConsentStatus.consented),
Tealium.setConsentExpiryListener(
() => print('Consent Expired'));
}
else
{
print('Tealium Initialization Error')
}
});
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 Tealium.setPersistentData()
.
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 |
---|---|---|---|
keys |
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 .consented
. If the consent status is .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 |
---|---|
anlytics |
Anlytics |
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 .unknown
until the status is updated.
Tealium.setConsentStatus(status);
Parameter | Type | Description |
---|---|---|
status |
status |
Consent status |
Example:
Tealium.setConsentStatus(ConsentStatus.consented);
Consent Status
The following consent statuses are available:
Value | Description |
---|---|
.consented |
Consented |
.notConsented |
Not consented |
.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.terminateIntance();
track()
Track an event with either a TealiumEvent
or TealiumView
dispatch.
Tealium.track(dispatch);
Parameter | Type | Description | Example |
---|---|---|---|
dispatch |
TealiumDispatch |
Tealium dispatch with the event name and data layer | TealiumEvent('button_click', { 'button_name': 'Submit' }) |
gatherTrackData()
Gathers all data from all collectors and data layer.
Example:
Tealium.gatherTrackData()
.then((data) => developer.log('Gather track Data: $data'))
This page was last updated: March 15, 2024