Provides SRG SSR implementation for Commanders Act and ComScore to send page view events and custom events.
Note: custom events are only supported with Commanders Act.
To use this module, add the following dependency to your module's build.gradle/build.gradle.kts file:
implementation("ch.srgssr.pillarbox:pillarbox-analytics:<pillarbox_version>")Before using any functionality, SRGAnalytics must be initialized in your Application's onCreate() method using either the initSRGAnalytics() or the SRGAnalytics.init() method and providing an AnalyticsConfig instance.
class MyApplication : Application() { override fun onCreate() { super.onCreate() val config = AnalyticsConfig( vendor = AnalyticsConfig.Vendor.SRG, appSiteName = "Your AppSiteName here", sourceKey = SourceKey.DEVELOPMENT, nonLocalizedApplicationName = "Your non-localized AppSiteName here", ) initSRGAnalytics(config) // or SRGAnalytics.init(this, config) } }User consent can be configured when initializing analytics in your Application's onCreate() method:
val userConsent = UserConsent( comScore = ComScoreUserConsent.UNKNOWN, commandersActConsentServices = emptyList(), ) val config = AnalyticsConfig( vendor = AnalyticsConfig.Vendor.SRG, appSiteName = "Your AppSiteName here", sourceKey = SourceKey.DEVELOPMENT, nonLocalizedApplicationName = "Your non-localized AppSiteName here", userConsent = userConsent, ) initSRGAnalytics(config)Or it can be updated at any time using the following code snippet:
val userConsent = UserConsent( comScore = ComScoreUserConsent.DECLINED, commandersActConsentServices = listOf("service1_id", "service2_id"), ) SRGAnalytics.setUserConsent(userConsent)The updated values will be sent with the next analytics event.
To send a page view, use SRGAnalytics.sendPageView(). It will send the event only to Commanders Act.
val commandersActPageView = CommandersActPageView( name = "page_name", type = "page_type", levels = listOf("level1", "level2"), ) SRGAnalytics.sendPageView( commandersAct = commandersActPageView )In the case of a multi-pane view, each pane view can send a page view. It is useful when reusing views from a single pane view inside the multi-pane view. For Android Auto applications, it is not recommended to send page view.
Events are application events that the analytics team wants to track. It could be a click event, a user choice, etc...
val commandersActEvent = CommandersActEvent(name = "event") SRGAnalytics.sendEvent(commandersActEvent)Top-level entry point for managing analytics in Pillarbox for SRG SSR applications.
Commanders Act specific classes.
ComScore specific classes.