Skip to content

Commit ad60198

Browse files
authored
Merge pull request #7 from segment-integrations/update-sample-with-notifier
Add the ConsentChangedNotifier integration.
2 parents 1e7584a + 9bea219 commit ad60198

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Twilio OneTrust CMP Integration
22

3-
This plugin provides the integration points for the OneTrust CMP SDK.
3+
This plugin provides an EXAMPLE integration for the OneTrust CMP SDK.
44

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

lib/src/main/java/com/segment/analytics/kotlin/consent/onetrust/OneTrustConsentChangedNotifier.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import android.content.BroadcastReceiver
44
import android.content.Context
55
import android.content.Intent
66
import android.content.IntentFilter
7+
import android.util.Log
78
import com.onetrust.otpublishers.headless.Public.Keys.OTBroadcastServiceKeys
89
import com.segment.analytics.kotlin.consent.ConsentManager
910
import java.lang.ref.WeakReference

testapp/src/main/java/com/segment/analytics/consent/onetrust/testapp/MainApplication.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ import com.segment.analytics.kotlin.core.platform.policies.CountBasedFlushPolicy
1212
import com.segment.analytics.kotlin.core.platform.policies.FrequencyFlushPolicy
1313
import com.segment.analytics.kotlin.consent.ConsentManager
1414
import com.segment.analytics.kotlin.consent.onetrust.OneTrustConsentCategoryProvider
15+
import com.segment.analytics.kotlin.consent.onetrust.OneTrustConsentChangedNotifier
1516
import org.json.JSONException
1617
import org.json.JSONObject
1718
import sovran.kotlin.SynchronousStore
19+
import java.lang.ref.WeakReference
1820

1921
class MainApplication : Application() {
2022

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

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

115+
// The notifier is used to tell the consent plugin that consent has changed.
116+
// OneTrust sends out a Broadcast Intent when consent changes. The notifier
117+
// can be used to start (.register()) or stop (.unregister()) listening for
118+
// those broadcast. For app, we'll just start it once and not stop it to make
119+
// sure we we're listening no matter which activity is using the OneTrust UI.
120+
notifier = OneTrustConsentChangedNotifier(
121+
WeakReference(this@MainApplication),
122+
categories,
123+
consentPlugin)
124+
125+
notifier?.register()
126+
112127
// This call starts the events following through the ConsentManagement Plugin
113128
// The plugin will BLOCK all events until start() is called. Here we do it after
114129
// we have gotten valid information from OneTrust, so you MUST enter valid OneTrust

0 commit comments

Comments
 (0)