Adding Tealium to Your Android App

Adding Tealium to Your Android App

by Community Manager on ‎01-04-2017 01:25 PM - edited 3 weeks ago by (12,580 Views)

This guide shows how to add Tealium to your Android Mobile or Android TV app to track user activity.

Table of Contents Placeholder


  • Android Studio
  • Android API Level 19 and higher (KitKat/4.4)

For use with iQ Tag Management:

For use with Universal Data Hub:

Get the Code

The code for the Tealium Android library can be found on Github. You must download and install the library before proceeding.

Cloning the library, instead of downloading, will make it easier to update to future releases.


The current version of the Tealium Android library is 5.5.4, released on 1/23/2019

Tealium uses Maven to install and manage dependencies.

Add the Tealium Maven URL to your project root build.gradle file:

allprojects {
repositories {

maven {
url ""

Add the Tealium dependency to your project module build.gradle file:

dependencies {
implementation 'com.tealium:library:5.5.4'

Add to Project Manually

You can also add the dependency manually.

Add flatDir to your project root build.gradle file:

allprojects {
    repositories {
        flatDir {
            dirs 'libs'

Add tealium-5.x.x.aar to <PROJECT_ROOT>/<MODULE>/libs.

Add the Tealium library dependency to your build.gradle file: 

dependencies {
    implementation(name:'tealium-5.5.4', ext:'aar')


The Tealium instance must be configured with the following parameters before it will begin tracking:

  • account - the name of your account
  • profile - the name of your profile
  • environment - one of "qa" or "prod"
  • datasource - (optional) the data source key from UDH
  • instance - a unique name for your instance (multiple instances are supported)

Add the following code to the onCreate method in the Application sub-class:

Tealium.Config tealConfig = Tealium.Config.create(application,
// Currently optional - add a 6 character alphanumeric data source ID.
// If you have not been given a data source ID, you can omit this. Note that this is a mock value
/* setForceOverrideLogLevel - optional - forces the log level to be set to one of "dev", "qa", "prod" or "silent".
* Overrides remote publish setting. Remote publish settings used if omitted. */
Tealium.createInstance("INSTANCE", tealConfig);

When Collect is enabled,
v.5.5.1 and above - data will be sent to profile provided in Tealium.Config object
v.5.5.0 and below - data will be sent to "main" profile

Tracking Views

Every time a user opens or changes a screen in the app a tracking call should be made.  A view is tracked by calling trackView() with two parameters: the name of the screen and (optionally) contextual view data. 

The screen name will be populated in the event data as the screen_title variable.

Map<String, Object> data = new HashMap<>(1);
data.put("someKey", "someValue");

Tealium.getInstance("INSTANCE").trackView("screenName", data);

Tracking Events

All non-view activity should be tracked as an event. This is easily done by calling trackEvent() with two parameters: an event name and (optionally) contextual event data.

The event name will be populated in the event data as the tealium_event variable.

Map<String, Object> data = new HashMap<>(1);
data.put("someKey", "someValue");

Tealium.getInstance("INSTANCE_NAME").trackEvent("someEvent", data); 

Overriding The Default Log Level

By default, the amount of logging performed by the Tealium library is controlled by the remote publish settings. Sometimes, however, this is not convenient for developers who may not have access to Tealium iQ to change the settings.

Since release 5.3.1 of the Tealium library, we now support overriding the log level locally at initialization time. To set a specific log level, use the following snippet:

Tealium.Config tealConfig = Tealium.Config.create(application,

/* Options are:
* "dev" (warnings, errors, info)
* "qa" (errors & warnings only)
* "prod" (errors only)
* "silent" (no logging, but may produce a couple of lines of log output in cases where the config object hasn't yet been initialized)
tealConfig.setForceOverrideLogLevel("dev"); // forces the log level to be set to dev

v5.1.0 and above - CookieManager is enabled by default.  
v5.0.4 and below - CookieManager is disbabled by default. Enabling CookieManager is required if using Tag Management

If you have enabled Tag Managements in your mobile profile then the following code can be added to activate cookie management. This code allows the Tag Management Webview to:

This must be placed after the initialization statement.


private static WebViewCreatedListener createCookieEnablerListener() {
return new WebViewCreatedListener() {
public void onWebViewCreated(WebView webView) {
final CookieManager mgr = CookieManager.getInstance();

// Accept all cookies

mgr.setAcceptThirdPartyCookies(webView, true);


Log.d(TAG, "WebView " + webView + " created and cookies enabled.");

Additional Resources