Tealium for Java

Tealium for Java

by on ‎09-19-2016 08:51 AM - edited on ‎10-24-2018 08:55 AM by (2,627 Views)

This guide shows how to add Tealium to your Java application to track event activity.  Before you begin, here's a video introduction to the platform:

Table of Contents Placeholder



 Before proceeding, ensure you have satisfied the following requirements:

Get the Code

The code for the Tealium Java library is stored in Github. You must retrieve the code to get started.

We recommend cloning the library (instead of downloading) to make it easier to update to future releases.

Code Setup

Import all of the .java files from the src/main/java/com/tealium directory, then add this code:

import com.tealium.*

Using Maven

Make the following changes to your pom.xml file:

Add the repository:


Add the dependency:



Once the files are added to your project you are ready to start coding. The Tealium instance must be invoked with the following parameters before you can begin tracking:

  • account - the name of your account
  • profile - the name of the profile within your account
  • environment - (optional) one of "qa" or "prod"
  • datasource - (optional) the data source key from your Universal Data Hub account
Tealium tealium = new Tealium.Builder("ACCOUNT", "PROFILE")


Once the Tealium instance has been defined you can begin tracking events with the method track(), which takes the following parameters:

  • eventName (required) - a name to identify the event
  • eventData (optional) - an object with event attributes as key/value pairs
  • callback (optional) - a function to be called when the track() method completes


// Set event attributes
Udo data = new Udo();
data.put("user_id", "0123456789");
data.put("email_address", "user@example.com");

// With optional callback
DispatchCallBack callBack = new DispatchCallBack(){
public void dispatchComplete(boolean success, String encodedURLString, String error){
// Callback handling
System.out.println("Dispatch successful: " + String.valueOf(success));
// Tracking a login event
tealium.track("user_login", data, callBack);

Watch this video for a quick summary of the installation steps:


Function Definitions



Instantiate a Tealium object.

Tealium.Builder(account, profile, environment).build()
Parameters Type Description Example Value
account String Tealium account name




Tealium profile




Tealium environment identifer




Tealium data source key from UDH


// Init Tealium
Tealium teal = new Tealium.Builder('ACCOUNT', 'PROFILE')


Convenience track call.

Parameters Type Description
eventName String

Name of event (becomes the tealium_event and event_name event attribute values)



Convenience track call for events that can optionally include additional data and a callback.

track(event, eventData, [callback])
Parameters Type Description
eventName String

Name of event (becomes the tealium_event and event_name event attribute values)



(Optional) Udo of additional data source keys and values



(Optional) Object conforming to the Tealium call back interface
// Event attributes
Udo data = new Udo();
data.put("user_id", "0123456789");
data.put("email_address", "user@example.com");

// With optional callback
DispatchCallBack callBack = new DispatchCallBack(){

public void dispatchComplete(boolean success, String error) {
// Callback code here

tealium.track("user_login", data, callback);



Fetch the DataManager object. The Data Manager processes call time data and handles persistent data.

Returns Description Example Value
DataManager Instance of the Tealium Data Manager object NA
DataManager dm = tealium.getDataManager()


Use the DataManager to make data available across multiple app sessions.

addPersistentData(map<String, Object>)
Parameters Description Example Value
data Required map to add to the existing persistent udo ["key":"value"]
Udo data = new Udo();
data.put("aKey", "aValue")


Use the DataManager to delete previously persisted data by providing a list of keys to delete.

Parameters Description Example Value
keys Array of Keys as strings ["key1", "key2"]
List<String> list = new List<>();


Use the DataManager to retrieve data that has been persisted.

Returns Description Example Value
Udo Udo of persistent data ["key1", "key2"]
Udo persistentData = tealium.getDataManager().getPersistentData()


Use the DataManager to fetch the current session ID. A session ID is created on initialization of the Tealium object.

Returns Description Example Value
String String representation of a timestamp in milliseconds "1473371215123"


Use the DataManager to reset the session ID. For use when needing to start a new session other than at app start time.

Returns Description Example Value
String New String representation of a timestamp in milliseconds that will be added to all dispatches for the remainder of the current session. The returned String is for monitoring convenience as it is automatically added to the volatile data store when this method is called. "1473371215123"



The type signatures of some of the methods have changed. Event data used to be a Map<String, Object> type, but has changed to be a Udo (universal data object) type. Event data must follow a specific format where each value is either a String or List<String>, so a more specific type is helpful. (See the Universal Data Object Guide for the formatting details.)

The new Udo type implements the Map<String, Object> interface, and therefore can be used wherever a Map<String, Object> can. Although still usable, the previous methods using Map<String, Object> have been deprecated and should be switched out for the updated version since they will likely be dropped in a future update.