Skip to content
This repository has been archived by the owner on Apr 16, 2024. It is now read-only.

SourcePointUSA/CCPA_Android_SDK

Repository files navigation

❗The CCPA SDK is now part of the Unified SDK. This repo is now deprecated.

Table of Contents

Setup

To use ccpa_cmplibrary in your app, include com.sourcepoint.ccpa_cmplibrary:ccpa_cmplibrary:x.y.z as a dependency to your project's build.gradle.

...
dependencies {
    implementation 'com.sourcepoint.ccpa_cmplibrary:ccpa_cmplibrary:1.3.4'
}

Getting started

  • In your main activity, create an instance of CCPAConsentLib class using CCPAConsentLib.newBuilder() class function passing the configurations and callback handlers to the builder and call .run() on the instantiated CCPAConsentLib object to load a message and get consents or call .loadPM to load a privacy menager message like following:
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";

    private ViewGroup mainViewGroup;

    private void showMessageWebView(WebView webView) {
        webView.setLayoutParams(new ViewGroup.LayoutParams(0, 0));
        webView.getLayoutParams().height = ViewGroup.LayoutParams.MATCH_PARENT;
        webView.getLayoutParams().width = ViewGroup.LayoutParams.MATCH_PARENT;
        webView.bringToFront();
        webView.requestLayout();
        mainViewGroup.addView(webView);
    }
    private void removeWebView(WebView webView) {
        if(webView.getParent() != null)
            mainViewGroup.removeView(webView);
    }

    private CCPAConsentLib buildCCPAConsentLib() {
        return CCPAConsentLib.newBuilder(22, "ccpa.mobile.demo", 6099,"5df9105bcf42027ce707bb43",this)
                .setOnConsentUIReady(consentLib -> {
                    showMessageWebView(consentLib.webView);
                    Log.i(TAG, "onConsentUIReady");
                })
                .setOnConsentUIFinished(consentLib -> {
                    removeWebView(consentLib.webView);
                    Log.i(TAG, "onConsentUIFinished");
                })
                .setOnConsentReady(consentLib -> {
                    Log.i(TAG, "onConsentReady");
                    UserConsent consent = consentLib.userConsent;
                    Log.i(TAG, consent.consentString);
                    if(consent.status == UserConsent.ConsentStatus.rejectedNone){
                        Log.i(TAG, "There are no rejected vendors/purposes.");
                    } else if(consent.status == UserConsent.ConsentStatus.rejectedNone || consent.status == UserConsent.ConsentStatus.consentedAll){
                        Log.i(TAG, "All vendors/purposes were rejected.");
                    } else {
                        for (String vendorId : consent.rejectedVendors) {
                            Log.i(TAG, "The vendor " + vendorId + " was rejected.");
                        }
                        for (String purposeId : consent.rejectedCategories) {
                            Log.i(TAG, "The category " + purposeId + " was rejected.");
                        }
                    }
                })
                .setOnError(consentLib -> {
                    Log.e(TAG, "Something went wrong: ", consentLib.error);
                })
                .build();
    }

    @Override
    protected void onResume() {
        super.onResume();
        buildCCPAConsentLib().run();
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mainViewGroup = findViewById(android.R.id.content);
        findViewById(R.id.review_consents).setOnClickListener(_v -> {
            buildCCPAConsentLib().showPm();
        });
    }
}

Authenticated Consent

In order to use the authenticated consent all you need to do is calling .setAuthId(String) in the instance of ConsentLibBuilder. Example:

CCPAConsentLib.newBuilder(22, "ccpa.mobile.demo", 2372,"5c0e81b7d74b3c30c6852301",this)
    // calling other .set methods
    .setAuthId("JohnDoe")
    .build();

pubData

When the user takes an action within the consent UI, it's possible to attach an arbitrary payload to the action data an have it sent to our endpoints. For more information on how to do that check our wiki: Sending arbitrary data when the user takes an action;

Docs

For the complete documentation, open ./docs/index.html in the browser.

Development

How to build the cmplibrary module from source

Note: skip this step and jump to next section if you already have the compiled the compiled cmplibrary-release.aar binary.

  • Clone and open android-cmp-app project in Android Studio
  • Build the project
  • Open Gradle menu from right hand side menu in Android Studio and select assemble under :cmplibrary > Tasks > assemble

screen shot 2018-11-05 at 4 52 27 pm

  • Run the assemble task by selecting android-cmp-app:cmplibrary [assemble] (should be already selected) and clicking the build icon (or selecting Build > Make Project) from the menus.
  • The release version of the compiled binary should be under cmplibrary/build/outputs/aar/cmplibrary-release.aar directory. Copy this file and import it to your project using the steps below.

How to import the master version of cmplibrary into existing an Android app project for development

  • Open your existing Android project in Android Studio and select the File > New > New Module menu item.
  • Scroll down and select Import .JAR/.AAR Package and click next.
  • Browse and select the distributed cmplibrary-release.aar binary file (or the one you generated using the instructions in the last section)
  • In your project's app/build.gradle file make sure you have cmplibrary-release as a dependency and also add com.google.guava:guava:20.0 as a dependency:
dependencies {
    ...
    implementation project(":cmplibrary-release")
    implementation("com.google.guava:guava:20.0")
}
  • Make sure in your project's settings.gradle file you have:
include ':app', ':cmplibrary-release'
  • Open app/src/main/AndroidManifest.xml and add android.permission.INTERNET permission if you do not have the permission in your manifest:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.your-app">
    <uses-permission android:name="android.permission.INTERNET" />

    <application>
        ...
    </application>
</manifest>