Skip to content

Commit 6195883

Browse files
committed
Updates to support consent lib 1.2.2 and update snapshot and release yml.
1 parent c242140 commit 6195883

File tree

8 files changed

+103
-38
lines changed

8 files changed

+103
-38
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ jobs:
3636
restore-keys: |
3737
${{ runner.os }}-gradle-core-
3838
- name: Publush release to sonatype
39-
run: ./gradlew publishToSonatype -Prelease closeAndReleaseSonatypeStagingRepository
39+
run: ./gradlew clean build publishToSonatype -Prelease closeAndReleaseSonatypeStagingRepository
4040
env:
4141
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
4242
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
@@ -53,4 +53,4 @@ jobs:
5353
-d '{"tag_name": "${{ env.RELEASE_VERSION }}", "name": "${{ env.RELEASE_VERSION }}", "body": "Release of version ${{ env.RELEASE_VERSION }}", "draft": false, "prerelease": false, "generate_release_notes": true}'
5454
env:
5555
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
56-
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}
56+
RELEASE_VERSION: ${{ steps.vars.outputs.tag }}

.github/workflows/snapshot.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ jobs:
2222
restore-keys: |
2323
${{ runner.os }}-gradle-core-
2424
- name: Publush snapshot to sonatype
25-
run: ./gradlew publishToSonatype
25+
run: ./gradlew clean build publishToSonatype
2626
env:
2727
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
2828
SIGNING_KEY_PASSWORD: ${{ secrets.SIGNING_KEY_PASSWORD }}
2929
ORG_GRADLE_PROJECT_sonatypeUsername: ${{ secrets.NEXUS_USERNAME }}
3030
ORG_GRADLE_PROJECT_sonatypePassword: ${{ secrets.NEXUS_PASSWORD }}
31-
SIGNING_PRIVATE_KEY_BASE64: ${{ secrets.SIGNING_PRIVATE_KEY_BASE64 }}
31+
SIGNING_PRIVATE_KEY_BASE64: ${{ secrets.SIGNING_PRIVATE_KEY_BASE64 }}

lib/build.gradle.kts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ android {
4040

4141
dependencies {
4242
implementation("com.segment:sovran-kotlin:1.3.1")
43-
implementation("com.segment.analytics.kotlin:android:1.13.1")
44-
implementation("com.segment.analytics.kotlin.destinations:consent:1.0.0-SNAPSHOT")
45-
implementation("androidx.multidex:multidex:2.0.1")
43+
implementation("com.segment.analytics.kotlin:android:1.14.0")
44+
implementation("com.segment.analytics.kotlin.destinations:consent:1.2.2")
45+
implementation("androidx.multidex:multidex:2.0.1")
4646
implementation("androidx.core:core-ktx:1.10.1")
4747
implementation("androidx.lifecycle:lifecycle-process:2.6.1")
4848
implementation("androidx.lifecycle:lifecycle-common-java8:2.6.1")

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@ import com.segment.analytics.kotlin.destinations.consent.ConsentCategoryProvider
55

66
class OneTrustConsentCategoryProvider(
77
val otPublishersHeadlessSDK: OTPublishersHeadlessSDK,
8-
val categories: List<String>
8+
var categories: List<String> = emptyList()
99
) : ConsentCategoryProvider {
1010

11+
12+
13+
1114
override fun getCategories(): Map<String, Boolean> {
1215
var categoryConsentMap = HashMap<String, Boolean>()
1316

@@ -23,4 +26,8 @@ class OneTrustConsentCategoryProvider(
2326

2427
return categoryConsentMap
2528
}
29+
30+
override fun setCategoryList(categories: List<String>) {
31+
this.categories = categories
32+
}
2633
}

testapp/build.gradle.kts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,11 @@ android {
3737
dependencies {
3838
implementation(project(mapOf("path" to ":lib")))
3939

40-
implementation("com.segment.analytics.kotlin.destinations:consent:1.0.0-SNAPSHOT")
40+
implementation("com.segment.analytics.kotlin.destinations:consent:1.2.2")
4141
implementation("com.segment.analytics.kotlin:android:1.13.1")
42-
implementation("com.onetrust.cmp:native-sdk:202303.2.0.0")
42+
implementation("com.onetrust.cmp:native-sdk:202309.1.0.0")
4343
implementation("com.squareup.okhttp3:okhttp:4.10.0")
44+
implementation("com.segment.analytics.kotlin:destination-filters:0.1.1")
4445
implementation(project(":lib"))
4546

4647
implementation("androidx.core:core-ktx:1.10.1")

testapp/src/main/AndroidManifest.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="com.segment.analytics.destinations.mydestination.testapp">
44

5+
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
<uses-permission android:name="android.permission.INTERNET" />
8+
59
<application
610
android:allowBackup="true"
711
android:icon="@mipmap/ic_launcher"

testapp/src/main/java/com/segment/analytics/destinations/mydestination/testapp/MainApplication.kt

Lines changed: 79 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,20 @@ package com.segment.analytics.destinations.mydestination.testapp
33
import android.app.Application
44
import android.content.Context
55
import android.util.Log
6+
import com.onetrust.otpublishers.headless.Public.OTCallback
67
import com.onetrust.otpublishers.headless.Public.OTPublishersHeadlessSDK
7-
import com.segment.analytics.kotlin.core.Analytics
8+
import com.onetrust.otpublishers.headless.Public.Response.OTResponse
89
import com.segment.analytics.kotlin.android.Analytics
10+
import com.segment.analytics.kotlin.core.Analytics
911
import com.segment.analytics.kotlin.core.platform.policies.CountBasedFlushPolicy
1012
import com.segment.analytics.kotlin.core.platform.policies.FrequencyFlushPolicy
11-
import com.segment.analytics.kotlin.destinations.consent.ConsentBlockingPlugin
12-
import com.segment.analytics.kotlin.destinations.consent.ConsentManagementPlugin
13+
import com.segment.analytics.kotlin.destinations.consent.ConsentManager
1314
import com.segment.analytics.kotlin.destinations.consent.onetrust.OneTrustConsentCategoryProvider
15+
import org.json.JSONException
16+
import org.json.JSONObject
1417
import sovran.kotlin.SynchronousStore
1518

16-
class MainApplication: Application() {
19+
class MainApplication : Application() {
1720

1821
companion object {
1922
const val TAG = "main"
@@ -25,48 +28,99 @@ class MainApplication: Application() {
2528
lateinit var otPublishersHeadlessSDK: OTPublishersHeadlessSDK
2629

2730
// Update these:
28-
private const val SEGMENT_WRITE_KEY = "<Your Segment WRITEKEY>"
29-
const val DOMAIN_URL = "<Your OneTrust Domain URL>"
30-
const val DOMAIN_ID = "<Your OneTrust Domain ID>"
31-
const val WEBHOOK_URL = "<Your webhook.site webhook url>"
31+
// private const val SEGMENT_WRITE_KEY = "<Your Segment WRITEKEY>"
32+
// const val DOMAIN_URL = "<Your OneTrust Domain URL>"
33+
// const val DOMAIN_ID = "<Your OneTrust Domain ID>"
34+
// const val WEBHOOK_URL = "<Your webhook.site webhook url>"
35+
36+
37+
private const val SEGMENT_WRITE_KEY = "Iqc4U4x6130y1XFCLIP40N3WSTHXkTPz"
38+
const val DOMAIN_URL = "cdn.cookielaw.org"
39+
// const val DOMAIN_ID = "72eadd89-8bfb-4d82-aed4-20a33299b6d1-test"
40+
const val DOMAIN_ID = "14747048-7048-4b70-9aab-d1862f43f034-test"
41+
// const val DOMAIN_ID = "foo"
42+
const val WEBHOOK_URL = "https://webhook.site/9bbdf672-fd47-4235-8c81-922bc7145f22"
43+
44+
45+
const val LANGUAGE_CODE = "en"
46+
}
47+
48+
49+
private fun getGroupIds(domainGroupData: JSONObject): List<String> {
50+
val result: MutableList<String> = ArrayList()
51+
try {
52+
val groups = domainGroupData.getJSONArray("Groups")
53+
for (i in 0 until groups.length()) {
54+
val group = groups.getJSONObject(i)
55+
val groupId = group.getString("OptanonGroupId")
56+
result.add(groupId)
57+
}
58+
} catch (ex: JSONException) {
59+
ex.printStackTrace()
60+
}
61+
return result
3262
}
33-
3463

3564
override fun onCreate() {
3665
super.onCreate()
3766

3867
appContext = this
39-
otPublishersHeadlessSDK = OTPublishersHeadlessSDK(this)
4068

41-
Analytics.debugLogsEnabled = true
4269

70+
71+
Analytics.debugLogsEnabled = true
4372
analytics = Analytics(SEGMENT_WRITE_KEY, applicationContext) {
4473
this.collectDeviceId = true
4574
this.trackApplicationLifecycleEvents = true
4675
this.trackDeepLinks = true
47-
this.flushPolicies = listOf(
76+
this.flushPolicies = mutableListOf(
4877
CountBasedFlushPolicy(1), // Flush after each event
4978
FrequencyFlushPolicy(5000) // Flush after 5 Seconds
5079
)
5180
}
5281

53-
// List of categories we care about; we will query OneTrust SDK locally on the status
54-
// of these categories when stamping an event with consent status.
55-
val categories = listOf<String>("C0001", "C0002")
56-
val consentCategoryProvider = OneTrustConsentCategoryProvider(otPublishersHeadlessSDK, categories)
82+
83+
analytics.add(WebhookPlugin(WEBHOOK_URL))
84+
85+
otPublishersHeadlessSDK = OTPublishersHeadlessSDK(this)
86+
87+
val consentCategoryProvider = OneTrustConsentCategoryProvider(otPublishersHeadlessSDK)
5788
val store = SynchronousStore()
58-
val consentPlugin = ConsentManagementPlugin(store, consentCategoryProvider)
59-
val consentBlockingPlugin = ConsentBlockingPlugin("Segment.io", store, true)
6089

61-
// Add the Consent Plugin directly to analytics
90+
val consentPlugin = ConsentManager(store, consentCategoryProvider)
91+
6292
analytics.add(consentPlugin)
6393

94+
otPublishersHeadlessSDK.startSDK(
95+
DOMAIN_URL,
96+
DOMAIN_ID,
97+
LANGUAGE_CODE,
98+
null,
99+
false,
100+
object : OTCallback {
101+
override fun onSuccess(otSuccessResponse: OTResponse) {
102+
// do logic to render UI getOTSDKData();
103+
val otData =
104+
MainApplication.otPublishersHeadlessSDK.bannerData.toString()
105+
Log.d(TAG, "OT onSuccess: otData: $otData")
106+
107+
val categories =
108+
getGroupIds(MainApplication.otPublishersHeadlessSDK.domainGroupData)
109+
110+
Log.d(TAG, "Setting up Analytics with categories: ${categories}")
111+
consentCategoryProvider.setCategoryList(categories)
112+
consentPlugin.start()
113+
}
114+
115+
override fun onFailure(otErrorResponse: OTResponse) {
116+
// Use below method to get errorCode and errorMessage.
117+
val errorCode = otErrorResponse.responseCode
118+
val errorDetails = otErrorResponse.responseMessage
119+
// Use toString() to log complete OT response
64120

65-
// Add the WebhookPlugin that will post to given WEBHOOK_URL
66-
val webhookDestinationPlugin = WebhookPlugin(WEBHOOK_URL)
67-
// Add the webhook destination plugin into the main timeline
68-
analytics.add(webhookDestinationPlugin)
69-
// Add the blocking plugin to this destination
70-
webhookDestinationPlugin.add(ConsentBlockingPlugin("Webhook", store))
121+
Log.i(TAG, otErrorResponse.toString())
122+
}
123+
}
124+
)
71125
}
72126
}

testapp/src/main/java/com/segment/analytics/destinations/mydestination/testapp/WebhookDestination.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.segment.analytics.destinations.mydestination.testapp
33
import android.util.Log
44
import com.segment.analytics.kotlin.core.*
55
import com.segment.analytics.kotlin.core.platform.DestinationPlugin
6+
import com.segment.analytics.kotlin.core.platform.EventPlugin
67
import com.segment.analytics.kotlin.core.platform.Plugin
78
import kotlinx.coroutines.CoroutineScope
89
import kotlinx.coroutines.Dispatchers
@@ -15,9 +16,7 @@ import okhttp3.OkHttpClient
1516
import okhttp3.Request
1617
import okhttp3.RequestBody.Companion.toRequestBody
1718

18-
class WebhookPlugin(
19-
private val webhookUrl: String
20-
) : DestinationPlugin() {
19+
class WebhookPlugin(val webhookUrl: String) : DestinationPlugin() {
2120
override val key: String = "Webhook"
2221
override lateinit var analytics: Analytics
2322
val JSON = "application/json; charset=utf-8".toMediaType()

0 commit comments

Comments
 (0)