Tealium for Java - 1.0.0 - 1.0.1

Tealium for Java - 1.0.0 - 1.0.1

by on ‎02-06-2017 01:57 PM - edited on ‎02-07-2017 09:25 PM by Community Manager (579 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  your pom.xml file:

Add the repository:


Add the dependency:




Once the Tealium 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 - one of "dev", "qa", or "prod"
Tealium tealium = new Tealium.Builder("ACCOUNT", "PROFILE", "ENVIRONMENT").build();


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
Map<String, Object> data = new HashMap<>(2);
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


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


Track an event with associated data and, optionall, trigger a callback function.

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

Name of event (becomes the event_name event attribute value)


Map Object

(Optional) Map<String, Object> of additional data source keys and values



(Optional) Object conforming to the Tealium call back interface
// Event attributes
Map<String, Object> data = new HashMap<>(2);
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 map <String,Object> ["key":"value"]
Map<String, Object> data = new HashMap<>();
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
Map Of type <String,Object> ["key1", "key2"]
Map<String,Object> 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"