Ad Identifier Module for Android

Ad Identifier Module for Android

by on ‎02-07-2018 02:13 PM - edited 3 weeks ago by (691 Views)

Introduction

The Android operating system provides each device with a user-resettable "Ad Identifier" (a.k.a. ADID) that can be used to identify an individual device's interaction with adverts displayed via ad networks, and can help companies to measure how effective their advertising spend has been.

How Tealium can help

To take the burden away from your app developers, Tealium has built a module that integrates with our standard Android library (version 5.2+), which automatically collects the ad identifier when available, and makes the data available as a standard variable for you to use with your tags.

Dependencies

This module depends on the Google Play Services Ads SDK, and will not function if the SDK is not present in your app. It was built against SDK version 9.4.0, but should function with older and newer versions without issue.

Instructions

Option 1: Manually add dependency

Download the AdIdentifier file from

https://github.com/Tealium/tealium-android/tree/master/Support/AdIdentifier

In the project's root build.gradle, make sure you have the following:

allprojects {
    repositories {
       jcenter()
        flatDir {
              dirs 'libs'
        }
    }
}

Include in your app's "libs" directory, and add the following to your project module's build.gradle:

dependencies {
    compile(name:'tealium-5.5.1', ext:'aar') // only required if you do not already have this reference
    compile(name:'tealium.adidentifier-5.2.0', ext:'aar')
    compile(name:'tealium.lifecycle-1.1.1', ext:'aar') // only required if you do not already have this reference and require lifecycle tracking
}

Option 2: Maven Dependency

In your project's root gradle file, add the following maven repository:

maven {
    url "http://maven.tealiumiq.com/android/releases/"
}

In your project module gradle file, add the following maven dependency:

dependencies{
    compile 'com.tealium:library:5.5.1' //only required if you do not have this reference
    compile 'com.tealium:adidentifier:1.0'
    compile 'com.tealium:lifecycle:1.1.1' //only required if you do not already have this reference and require lifecycle tracking
}

In the same block where you instantiate the Tealium library (after instantiating Tealium), add the following calls:

// import the Tealium AdIdentifier module in the import section
import com.tealium.adidentifier.AdIdentifier;
// context to pass to AdIdentifier module
Context mContext = this;
…
// substitute the example instance name here with the same instance name you used when initializing the Tealium library
private static final String TEALIUM_INSTANCENAME = "teal";
// call this to store the referrer as Persistent data - recommended
AdIdentifier.setIdPersistent(TEALIUM_INSTANCENAME, mContext);
// call this to store the referrer as Volatile data (reset at app restart/terminate) - not recommended in most cases
AdIdentifier.setIdVolatile(TEALIUM_INSTANCENAME, mContext);

Deleting the stored AdIdentifier information (not usually required)

To delete the stored Ad Identifier string, you can call the standard methods provided by the Tealium library to remove variables from persistent or volatile storage. The key name for the variable is exposed by the TealiumAdIdentifier class. Here's an example to remove the stored Ad Identifier from both persistent and volatile data. This code will have no effect and will not throw an error if the variable doesn't already exist.

// import the Tealium AdIdentifier module in the import section
import com.tealium.adidentifier.AdIdentifier;
…
private static final String TEALIUM_INSTANCENAME = "teal";
final Tealium instance = Tealium.getInstance(TEALIUM_INSTANCENAME);
// remove from persistent data store
instance.getDataSources().getPersistentDataSources().edit().remove(AdIdentifier.KEYNAME).apply();

// remove from volatile data store (session only)
instance.getDataSources().getVolatileDataSources().remove(AdIdentifier.KEYNAME);

Caveats and warnings

  1. If the user has not allowed access to the Ad Identifier, the module will set the "google_adid" variable to the string "Ad Tracking Disabled". You should handle this in your Tealium IQ/AudienceStream configuration to ensure you pass the correct/expected data to your 3rd party technology vendors.

  2. Please ensure you have already included the Google Play Services Ads SDK in your app. See here for instructions: https://developers.google.com/android/guides/setup