Code Examples

Check out some useful snippets and code examples for initialization below.

package com.example.testapp

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.preference.PreferenceManager
import com.liveramp.ats.LRAtsManager
import com.liveramp.ats.model.LRAtsConfiguration
import com.liveramp.ats.model.LRCustomIdentifier
import com.liveramp.ats.model.LREmailIdentifier
import com.liveramp.ats.model.LRPhoneIdentifier

class MainActivity : AppCompatActivity() {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        // set fake consent (for testing purposes only!), this should be handled by CMP SDK
        // GDPR
        setSharedPreferencesKey(
            "IABTCF_TCString",
            "CPKZ42oPKZ5YtADABCENBlCgAP_AAAAAAAAAAwwAQAwgDDABADCAAA"
        )
        setSharedPreferencesKey(
            "IABTCF_VendorConsents",
            "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"
        )
        setSharedPreferencesKey("IABTCF_PurposeConsents", "1111111111")
        // CCPA
        setSharedPreferencesKey("IABUSPrivacy_String", "1-N-")
        // TODO: remove fake consent above after testing

        // init ATS SDK
        LRAtsManager.initialize(
            LRAtsConfiguration(
                configurationId = "40b867f9-93cc-4687-a2c7-d02bed91aaee",
                isTestMode = false,
                logToFileEnabled = false,
                apiKey = ""
            )
        ) { success, error ->
            if (success) {
                // get envelope for email
                LRAtsManager.getEnvelope(LREmailIdentifier("[email protected]")) { envelope, error ->
                    // use envelope here
                }
                // or phone number
                LRAtsManager.getEnvelope(LRPhoneIdentifier("+14842918944")) { envelope, error ->
                    // use envelope here
                }
                // or for id
                LRAtsManager.getEnvelope(LRCustomIdentifier("54321:abc123")) { envelope, error ->
                    // use envelope here
                }
                // get dealIds for email
                LRAtsManger.getDealIDs(LRDealIdentifier("[email protected]")) { dealIDResult, error ->
                    // use dealIds here
                }
            }
        }
    }

    private fun setSharedPreferencesKey(key: String, value: String) {
        val preferences = PreferenceManager.getDefaultSharedPreferences(applicationContext)
        val editor = preferences.edit()
        editor.putString(key, value)
        editor.apply()
    }
}
package com.liveramp.atstestapp;

import android.content.SharedPreferences;
import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;

import com.liveramp.ats.LRAtsManager;
import com.liveramp.ats.LRError;
import com.liveramp.ats.callbacks.LRCompletionHandlerCallback;
import com.liveramp.ats.model.LRAtsConfiguration;
import com.liveramp.ats.model.LRCustomIdentifier;
import com.liveramp.ats.model.LREmailIdentifier;
import com.liveramp.ats.model.LRPhoneIdentifier;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // set fake consent (for testing purposes only!), this should be handled by CMP SDK
        // GDPR
        setSharedPreferencesKey(
                "IABTCF_TCString",
                "CPKZ42oPKZ5YtADABCENBlCgAP_AAAAAAAAAAwwAQAwgDDABADCAAA"
        );
        setSharedPreferencesKey(
                "IABTCF_VendorConsents",
                "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001"
        );
        setSharedPreferencesKey("IABTCF_PurposeConsents", "1111111111");
        // CCPA
        setSharedPreferencesKey("IABUSPrivacy_String", "1-N-");
        // TODO: remove fake consent above after testing
        
        // init ATS SDK
        LRAtsManager.INSTANCE.initialize(new LRAtsConfiguration("40b867f9-93cc-4687-a2c7-d02bed91aaee", false, false, ""), new LRCompletionHandlerCallback() {
            @Override
            public void invoke(boolean success, @Nullable LRError lrError) {
                if (success) {
                    // get envelope for email
                    LRAtsManager.INSTANCE.getEnvelope(new LREmailIdentifier("[email protected]"), (envelope, error) -> {
                        // use envelope here
                    });
                    // or phone number
                    LRAtsManager.INSTANCE.getEnvelope(new LRPhoneIdentifier("+14842918944"), (envelope, error) -> {
                        // use envelope here
                    });
                    // or for id
                    LRAtsManager.INSTANCE.getEnvelope(new LRCustomIdentifier("54321:abc123"), (envelope, error) -> {
                        // use envelope here
                    });
                    // get dealIds for email
                    LRAtsManager.INSTANCE.getDealIDs(new LRDealIdentifier("[email protected]"), (dealIDResult, lrError1) -> {
                        // use dealIds here
                    });
                }
            }
        });
    }

    private void setSharedPreferencesKey(String key, String value) {
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
        SharedPreferences.Editor editor = preferences.edit();
        editor.putString(key, value);
        editor.apply();
    }
}