Adding Tealium to Your Android App

Adding Tealium to Your Android App

by Community Manager on ‎01-04-2017 01:25 PM - edited Friday (1,893 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 9 and higher 

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.


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 {
compile 'com.tealium:library:5.2.0'

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 {
    compile(name:'tealium-5.2.0', 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 config = Tealium.Config.create(application,
Tealium.createInstance("INSTANCE", config);

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); 

v5.1.0 and above - CookieManager is enabled by default.  
v5.0.4 and below - CookieManager is disbabled by default. Enablement of CookieManager is required for 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