11package 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.*
37import 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