pillarbox-analytics

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.

Integration

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>")

Getting started

Configure analytics

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 = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG,
nonLocalizedApplicationName = "Your non-localized AppSiteName here",
)

initSRGAnalytics(config)
// or
SRGAnalytics.init(this, config)
}
}

Handle user consent

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 = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG,
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.

Send page view

To send a page view, use SRGAnalytics.sendPageView(). It will send the event to both Commanders Act and ComScore.

val commandersActPageView = CommandersActPageView(
name = "page_name",
type = "page_type",
levels = listOf("level1", "level2"),
)

val comScorePageView = ComScorePageView(name = "page_name")

SRGAnalytics.sendPageView(
commandersAct = commandersActPageView,
comScore = comScorePageView,
)

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.

Send event

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)

Packages

Link copied to clipboard

Top-level entry point for managing analytics in Pillarbox for SRG SSR applications.

Commanders Act specific classes.

Link copied to clipboard

ComScore specific classes.