Skip to content

Commit 8c10036

Browse files
authored
Merge pull request #2 from segment-integrations/development
LIBMOBILE-1157 - development to main
2 parents 9e50a32 + 73227ab commit 8c10036

File tree

2 files changed

+83
-4
lines changed

2 files changed

+83
-4
lines changed

lib/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ dependencies {
5252

5353
// Partner Dependencies
5454
dependencies {
55-
// TODO add your partner deps here
55+
implementation("com.quantcast.android.measurement:QuantcastAndroidSdk:1.5.1")
5656
}
5757

5858
// Test Dependencies
Lines changed: 82 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,89 @@
11
package com.segment.analytics.kotlin.destinations.quantcast
22

3+
import android.app.Activity
4+
import com.quantcast.measurement.service.QuantcastClient
5+
import com.segment.analytics.kotlin.android.plugins.AndroidLifecycle
6+
import com.segment.analytics.kotlin.core.*
37
import com.segment.analytics.kotlin.core.platform.DestinationPlugin
8+
import com.segment.analytics.kotlin.core.platform.Plugin
9+
import com.segment.analytics.kotlin.core.platform.plugins.logger.log
10+
import kotlinx.serialization.Serializable
411

5-
class QuantcastDestination: DestinationPlugin() {
12+
/**
13+
* Quantcast is an audience measurement tool that captures demographic and traffic data about the
14+
* visitors to your site, to make sure your ads are targeted at the right people.
15+
*
16+
* @see <a href="https://www.quantcast.com/">Quantcast</a>
17+
* @see <a href="https://segment.com/docs/integrations/quantcast/">Quantcast Integration</a>
18+
* @see <a href="https://github.com/quantcast/android-measurement#quantcast-android-sdk">
19+
* Quantcast Android SDK</a>
20+
*/
21+
class QuantcastDestination : DestinationPlugin(), AndroidLifecycle {
622
companion object {
7-
private const val QUANTCAST_FULL_KEY = "quantcast"
23+
private const val QUANTCAST_FULL_KEY = "Quantcast"
24+
private const val VIEWED_EVENT_FORMAT = "Viewed %s Screen"
825
}
26+
internal var quantcastSettings: QuantcastSettings? = null
27+
928
override val key: String = QUANTCAST_FULL_KEY
10-
}
29+
30+
override fun update(settings: Settings, type: Plugin.UpdateType) {
31+
super.update(settings, type)
32+
this.quantcastSettings =
33+
settings.destinationSettings(key, QuantcastSettings.serializer())
34+
if (type == Plugin.UpdateType.Initial) {
35+
analytics.log("QuantcastClient.enableLogging(true)")
36+
QuantcastClient.enableLogging(true)
37+
}
38+
}
39+
40+
override fun identify(payload: IdentifyEvent): BaseEvent {
41+
analytics.log("QuantcastClient.recordUserIdentifier(${payload.userId})")
42+
QuantcastClient.recordUserIdentifier(payload.userId)
43+
return payload
44+
}
45+
46+
override fun screen(payload: ScreenEvent): BaseEvent {
47+
quantcastLogEvent(String.format(VIEWED_EVENT_FORMAT, payload.name))
48+
return payload
49+
}
50+
51+
override fun track(payload: TrackEvent): BaseEvent {
52+
quantcastLogEvent(payload.event)
53+
return payload
54+
}
55+
56+
override fun onActivityStarted(activity: Activity?) {
57+
super.onActivityStarted(activity)
58+
analytics.log(
59+
"QuantcastClient.activityStart(activity, ${quantcastSettings?.apiKey}, null, null)")
60+
QuantcastClient.activityStart(activity, quantcastSettings?.apiKey, null, null)
61+
}
62+
63+
override fun onActivityStopped(activity: Activity?) {
64+
super.onActivityStopped(activity)
65+
analytics.log("QuantcastClient.activityStop()")
66+
QuantcastClient.activityStop()
67+
}
68+
69+
private fun quantcastLogEvent(event: String) {
70+
analytics.log("QuantcastClient.logEvent($event)")
71+
QuantcastClient.logEvent("Viewed $event Screen")
72+
73+
}
74+
}
75+
76+
/**
77+
* Quantcast Settings data class.
78+
*/
79+
@Serializable
80+
data class QuantcastSettings(
81+
// Quantcast API key
82+
var apiKey: String,
83+
// P-Code after login to Quantcast.
84+
var pCode: String,
85+
// By default data will be sent to Quantcast Measure, if enable it sends data to Quantcast Advertise
86+
var advertise: Boolean,
87+
// When data is for eCommerce events, Segment will include labels corresponding to the products included in the event.
88+
var advertiseProducts: Boolean
89+
)

0 commit comments

Comments
 (0)