Skip to content

Add the ConsentChangedNotifier integration. #7

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Twilio OneTrust CMP Integration

This plugin provides the integration points for the OneTrust CMP SDK.
This plugin provides an EXAMPLE integration for the OneTrust CMP SDK.

For more information on on Segment Managed CMP, including how to use this integration, check out the analytics-kotlin-consent repo:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.util.Log
import com.onetrust.otpublishers.headless.Public.Keys.OTBroadcastServiceKeys
import com.segment.analytics.kotlin.consent.ConsentManager
import java.lang.ref.WeakReference
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@ import com.segment.analytics.kotlin.core.platform.policies.CountBasedFlushPolicy
import com.segment.analytics.kotlin.core.platform.policies.FrequencyFlushPolicy
import com.segment.analytics.kotlin.consent.ConsentManager
import com.segment.analytics.kotlin.consent.onetrust.OneTrustConsentCategoryProvider
import com.segment.analytics.kotlin.consent.onetrust.OneTrustConsentChangedNotifier
import org.json.JSONException
import org.json.JSONObject
import sovran.kotlin.SynchronousStore
import java.lang.ref.WeakReference

class MainApplication : Application() {

Expand All @@ -23,6 +25,7 @@ class MainApplication : Application() {
var appContext: Context? = null
private set
lateinit var analytics: Analytics
var notifier: OneTrustConsentChangedNotifier? = null

var haveShownOTBanner = false
lateinit var otPublishersHeadlessSDK: OTPublishersHeadlessSDK
Expand Down Expand Up @@ -109,6 +112,18 @@ class MainApplication : Application() {
Log.d(TAG, "Setting up Analytics with categories: ${categories}")
consentCategoryProvider.setCategoryList(categories)

// The notifier is used to tell the consent plugin that consent has changed.
// OneTrust sends out a Broadcast Intent when consent changes. The notifier
// can be used to start (.register()) or stop (.unregister()) listening for
// those broadcast. For app, we'll just start it once and not stop it to make
// sure we we're listening no matter which activity is using the OneTrust UI.
notifier = OneTrustConsentChangedNotifier(
WeakReference(this@MainApplication),
categories,
consentPlugin)

notifier?.register()

// This call starts the events following through the ConsentManagement Plugin
// The plugin will BLOCK all events until start() is called. Here we do it after
// we have gotten valid information from OneTrust, so you MUST enter valid OneTrust
Expand Down
Loading