diff --git a/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidLibraryPublishingPlugin.kt b/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidLibraryPublishingPlugin.kt index d4a7f3180..ce608126e 100644 --- a/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidLibraryPublishingPlugin.kt +++ b/build-logic/plugins/src/main/java/ch/srgssr/pillarbox/gradle/PillarboxAndroidLibraryPublishingPlugin.kt @@ -88,7 +88,11 @@ class PillarboxAndroidLibraryPublishingPlugin : Plugin { extensions.configure { dokkaSourceSets.getByName("main") { - includes.from("Module.md") + if (file("Module.md").exists()) { + includes.from("Module.md") + } else { + includes.from("docs/README.md") + } // This is currently broken in Dokka for Android modules. See: https://github.com/Kotlin/dokka/issues/2876 sourceLink { @@ -104,7 +108,7 @@ class PillarboxAndroidLibraryPublishingPlugin : Plugin { customStyleSheets.from(rootProject.projectDir.resolve("dokka/styles/pillarbox.css")) footerMessage.set("© SRG SSR") // TODO Enable this once we have some content there - // homepageLink.set("https://srgssr.github.io/pillarbox-android") + // homepageLink.set("https://android.pillarbox.ch/") templatesDir.set(rootProject.projectDir.resolve("dokka/templates")) } } diff --git a/build.gradle.kts b/build.gradle.kts index 78fdb46f0..afe17c18c 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -2,7 +2,6 @@ * Copyright (c) SRG SSR. All rights reserved. * License information is available from the LICENSE file. */ -import org.jetbrains.dokka.gradle.tasks.DokkaGenerateTask // Top-level build file where you can add configuration options common to all sub-projects/modules. plugins { @@ -18,13 +17,13 @@ plugins { alias(libs.plugins.pillarbox.detekt) } -tasks.withType { - generator.includes.from("dokka/Pillarbox.md") -} - dokka { moduleVersion = providers.environmentVariable("VERSION_NAME").orElse("dev") + dokkaPublications.html { + includes.from("dokka/Pillarbox.md") + } + pluginsConfiguration.html { // See the overridable images here: // https://github.com/Kotlin/dokka/tree/master/dokka-subprojects/plugin-base/src/main/resources/dokka/images @@ -32,7 +31,7 @@ dokka { customStyleSheets.from("dokka/styles/pillarbox.css") footerMessage.set("© SRG SSR") // TODO Enable this once we have some content there - // homepageLink.set("https://srgssr.github.io/pillarbox-android") + // homepageLink.set("https://android.pillarbox.ch/") templatesDir.set(file("dokka/templates")) } } diff --git a/dokka/Pillarbox.md b/dokka/Pillarbox.md index c8c4adc2e..7bd3e54c4 100644 --- a/dokka/Pillarbox.md +++ b/dokka/Pillarbox.md @@ -11,4 +11,4 @@ It is split in multiple modules, whose documentation is available from the side - [GitHub repository](https://github.com/SRGSSR/pillarbox-android) - [Pillarbox releases](https://github.com/SRGSSR/pillarbox-android/releases) - [Pillarbox for Apple](https://swiftpackageindex.com/SRGSSR/pillarbox-apple) -- [Pillarbox for the Web](https://srgssr.github.io/pillarbox-web/api) +- [Pillarbox for the Web](https://web.pillarbox.ch/api/) diff --git a/pillarbox-analytics/Module.md b/pillarbox-analytics/Module.md deleted file mode 100644 index 7770fdb9b..000000000 --- a/pillarbox-analytics/Module.md +++ /dev/null @@ -1,12 +0,0 @@ -# Module pillarbox-analytics - -Provides SRG SSR implementation for [CommandersAct](https://www.commandersact.com/) and [ComScore](https://comscore.com/) to send page view events and -custom events. - -> ⚠️ Custom events are only supported with CommandersAct! - -To use this module, add the following dependency to your project's `build.gradle`/`build.gradle.kts` file: - -```kotlin -implementation("ch.srgssr.pillarbox:pillarbox-analytics:") -``` diff --git a/pillarbox-analytics/docs/README.md b/pillarbox-analytics/docs/README.md index 23d3e0c30..8b8fe1dff 100644 --- a/pillarbox-analytics/docs/README.md +++ b/pillarbox-analytics/docs/README.md @@ -1,95 +1,132 @@ -[![Pillarbox logo](https://github.com/SRGSSR/pillarbox-apple/blob/main/docs/README-images/logo.jpg)](https://github.com/SRGSSR/pillarbox-android) -[![Last release](https://img.shields.io/github/v/release/SRGSSR/pillarbox-android?label=Release)](https://github.com/SRGSSR/pillarbox-android/releases) -[![Android min SDK](https://img.shields.io/badge/Android-21%2B-34A853)](https://github.com/SRGSSR/pillarbox-android) -[![License](https://img.shields.io/github/license/SRGSSR/pillarbox-android?label=License)](https://github.com/SRGSSR/pillarbox-android/blob/main/LICENSE) +# Module pillarbox-analytics -# Pillarbox Analytics module +Provides SRG SSR implementation for [Commanders Act](https://www.commandersact.com/) and [ComScore](https://comscore.com/) to send page view events +and custom events. -Provides SRG SSR implementation for CommandersAct and ComScore to send page view events and custom events. - -Custom events are supported only with CommandersAct! +**Note:** custom events are only supported with Commanders Act. ## Integration -```gradle -implementation("ch.srgssr.pillarbox:pillarbox-analytics:$LATEST_RELEASE_VERSION") +To use this module, add the following dependency to your project's `build.gradle`/`build.gradle.kts` file: + +```kotlin +implementation("ch.srgssr.pillarbox:pillarbox-analytics:") ``` ## Getting started -### Configuration and create +### Configure analytics -Before using `SRGAnalytics` make sure to call `SRGAnalytics.init` first, otherwise it can lead to undefined behavior. -It is strongly recommended to call the initializer inside your `Application.onCreate` method. +Before using any functionality, [SRGAnalytics][ch.srgssr.pillarbox.analytics.SRGAnalytics] must be initialized in your +[Application][android.app.Application]'s [onCreate()][android.app.Application.onCreate] method using either the +[initSRGAnalytics()][ch.srgssr.pillarbox.analytics.SRGAnalytics.initSRGAnalytics] or the +[SRGAnalytics.init()][ch.srgssr.pillarbox.analytics.SRGAnalytics.init] method and providing an +[AnalyticsConfig][ch.srgssr.pillarbox.analytics.AnalyticsConfig] instance. ```kotlin -class DemoApplication : Application() { - +class MyApplication : Application() { override fun onCreate() { super.onCreate() - + val config = AnalyticsConfig( vendor = AnalyticsConfig.Vendor.SRG, - nonLocalizedApplicationName = "PillarboxDemo", - appSiteName = "pillarbox-demo-android", - sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG + appSiteName = "Your AppSiteName here", + sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG, + nonLocalizedApplicationName = "Your non-localized AppSiteName here", ) - - initSRGAnalytics(config = config) + + initSRGAnalytics(config) + // or + SRGAnalytics.init(this, config) } } ``` ### Handle user consent -User consent can be configured at initialization, from your `Application` class: +User consent can be configured when initializing analytics in your [Application][android.app.Application]'s +[onCreate()][android.app.Application.onCreate] method: + ```kotlin -val initialUserConsent = UserConsent( +val userConsent = UserConsent( comScore = ComScoreUserConsent.UNKNOWN, - commandersActConsentServices = emptyList() + commandersActConsentServices = emptyList(), ) val config = AnalyticsConfig( vendor = AnalyticsConfig.Vendor.SRG, - nonLocalizedApplicationName = "PillarboxDemo", - appSiteName = "pillarbox-demo-android", + appSiteName = "Your AppSiteName here", sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG, - userConsent = initialUserConsent + nonLocalizedApplicationName = "Your non-localized AppSiteName here", + userConsent = userConsent, ) -initSRGAnalytics(config = config) +initSRGAnalytics(config) ``` Or it can be updated at any time using the following code snippet: + ```kotlin -val updatedUserConsent = UserConsent( - comScore = ComScoreUserConsent.DECLINED, // or ComScoreUserConsent.ACCEPTED - commandersActConsentServices = listOf("service1_id", "service2_id") +val userConsent = UserConsent( + comScore = ComScoreUserConsent.DECLINED, + commandersActConsentServices = listOf("service1_id", "service2_id"), ) -SRGAnalytics.setUserConsent(updatedUserConsent) +SRGAnalytics.setUserConsent(userConsent) ``` -User consent values will be updated with the next analytics event. +The updated values will be sent with the next analytics event. ### Send page view -To send a page view use `SRGAnalytics.sendPageView`. It will trigger a CommandersAct and a Comscore page view event directly. +To send a page view, use [SRGAnalytics.sendPageView()][ch.srgssr.pillarbox.analytics.SRGAnalytics.sendPageView]. It will send the event to both +Commanders Act and ComScore. ```kotlin -val commandersActEvent = CommandersActPageView(name = "main", type = "tbd", levels = listOf("app", "pillarbox")) -val comScoreEvent = ComScorePageView(name = "main") -SRGAnalytics.sendPageView(commandersAct = commandersActEvent, comScore = comScoreEvent) -``` +val commandersActPageView = CommandersActPageView( + name = "page_name", + type = "page_type", + levels = listOf("level1", "level2"), +) -In the case of a multi pane view each pane view can send a page view. It is useful then reusing view from single pane view inside the multi pane view. +val comScorePageView = ComScorePageView(name = "page_name") -For Android Auto application it is not recommended to send page view. +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 the analytics team of the application want to track. It could be click event, user choice etc.. +Events are application events that the analytics team wants to track. It could be a click event, a user choice, etc... ```kotlin -SRGAnalytics.sendEvent(CommandersActEvent(name = "event")) +val commandersActEvent = CommandersActEvent(name = "event") + +SRGAnalytics.sendEvent(commandersActEvent) ``` + +# Package ch.srgssr.pillarbox.analytics + +Top-level entry point for managing analytics in Pillarbox for SRG SSR applications. + +# Package ch.srgssr.pillarbox.analytics.commandersact + +Commanders Act specific classes. + +# Package ch.srgssr.pillarbox.analytics.comscore + +ComScore specific classes. + +[android.app.Application]: https://developer.android.com/reference/kotlin/android/app/Application.html +[android.app.Application.onCreate]: https://developer.android.com/reference/kotlin/android/app/Application.html#oncreate +[ch.srgssr.pillarbox.analytics.AnalyticsConfig]: https://android.pillarbox.ch/api/pillarbox-analytics/ch.srgssr.pillarbox.analytics/-analytics-config/index.html +[ch.srgssr.pillarbox.analytics.SRGAnalytics]: https://android.pillarbox.ch/api/pillarbox-analytics/ch.srgssr.pillarbox.analytics/-s-r-g-analytics/index.html +[ch.srgssr.pillarbox.analytics.SRGAnalytics.init]: https://android.pillarbox.ch/api/pillarbox-analytics/ch.srgssr.pillarbox.analytics/-s-r-g-analytics/init.html +[ch.srgssr.pillarbox.analytics.SRGAnalytics.initSRGAnalytics]: https://android.pillarbox.ch/api/pillarbox-analytics/ch.srgssr.pillarbox.analytics/-s-r-g-analytics/init-s-r-g-analytics.html +[ch.srgssr.pillarbox.analytics.SRGAnalytics.sendPageView]: https://android.pillarbox.ch/api/pillarbox-analytics/ch.srgssr.pillarbox.analytics/-s-r-g-analytics/send-page-view.html diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/AnalyticsConfig.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/AnalyticsConfig.kt index 213464892..84d4fa9e3 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/AnalyticsConfig.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/AnalyticsConfig.kt @@ -4,17 +4,25 @@ */ package ch.srgssr.pillarbox.analytics +import ch.srgssr.pillarbox.analytics.AnalyticsConfig.Companion.SOURCE_KEY_SRG_DEBUG +import ch.srgssr.pillarbox.analytics.AnalyticsConfig.Companion.SOURCE_KEY_SRG_PROD +import ch.srgssr.pillarbox.analytics.SRGAnalytics.initSRGAnalytics + /** - * SRG Analytics config + * Represents the configuration for analytics tracking for SRG SSR applications. This should be used in conjunction with + * [SRGAnalytics.initSRGAnalytics] or [SRGAnalytics.init]. + * + * This class holds the necessary information for configuring analytics tracking, including the vendor, application details, user consent, and + * persistent labels. * - * @property vendor business unit. - * @property appSiteName The App/Site name given by the analytics team. - * @property sourceKey The CommandersAct sourceKey given by the analytics team. - * @property nonLocalizedApplicationName Application name for the analytics, by default the application name defined in the manifest. You can set - * it to null if the application name is not localized. - * @property userConsent User consent to transmit to ComScore and CommandersAct. - * @property comScorePersistentLabels initial ComScore persistent labels. - * @property commandersActPersistentLabels initial CommandersAct persistent labels. + * @property vendor The vendor to which the application belongs to. + * @property appSiteName The name of the app/site being tracked, given by the analytics team. + * @property sourceKey The CommandersAct source key. Production apps should use [SOURCE_KEY_SRG_PROD], and apps in development should use + * [SOURCE_KEY_SRG_DEBUG]. + * @property nonLocalizedApplicationName The non-localized name of the application. By default, the application name defined in the manifest is used. + * @property userConsent The user consent to transmit to ComScore and CommandersAct. + * @property comScorePersistentLabels The initial persistent labels for ComScore analytics. + * @property commandersActPersistentLabels The initial persistent labels for Commanders Act analytics. */ data class AnalyticsConfig( val vendor: Vendor, @@ -25,9 +33,8 @@ data class AnalyticsConfig( val comScorePersistentLabels: Map? = null, val commandersActPersistentLabels: Map? = null, ) { - /** - * Vendor + * Represents the different vendors supported by the application. */ @Suppress("UndocumentedPublicProperty") enum class Vendor { @@ -42,12 +49,12 @@ data class AnalyticsConfig( @Suppress("UndocumentedPublicClass") companion object { /** - * SRG Production CommandersAct source key + * The source key for SRG SSR apps in production. */ const val SOURCE_KEY_SRG_PROD = "3909d826-0845-40cc-a69a-6cec1036a45c" /** - * SRG Debug CommandersAct source key + * The source key for SRG SSR apps in development. */ const val SOURCE_KEY_SRG_DEBUG = "6f6bf70e-4129-4e47-a9be-ccd1737ba35f" } diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/SRGAnalytics.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/SRGAnalytics.kt index a2805240c..09fcb48c0 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/SRGAnalytics.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/SRGAnalytics.kt @@ -2,11 +2,11 @@ * Copyright (c) SRG SSR. All rights reserved. * License information is available from the LICENSE file. */ -@file:Suppress("MemberVisibilityCanBePrivate") package ch.srgssr.pillarbox.analytics import android.app.Application +import ch.srgssr.pillarbox.analytics.SRGAnalytics.init import ch.srgssr.pillarbox.analytics.SRGAnalytics.initSRGAnalytics import ch.srgssr.pillarbox.analytics.commandersact.CommandersAct import ch.srgssr.pillarbox.analytics.commandersact.CommandersActEvent @@ -19,22 +19,29 @@ import ch.srgssr.pillarbox.analytics.comscore.ComScoreSrg import ch.srgssr.pillarbox.analytics.comscore.NoOpComScore /** - * Analytics for SRG SSR + * SRG Analytics entry point. * - * Before using SRGAnalytics make sure to call [SRGAnalytics.init] or [initSRGAnalytics]. - * Otherwise nothing will be send. + * This object provides a facade for interacting with both Commanders Act and ComScore analytics services. It allows for sending page views, events, + * and managing persistent labels for both services. * - * ```kotlin - * Class MyApplication : Application() { + * Before using any functionality, `SRGAnalytics` must be initialized in your [Application]'s [onCreate()][Application.onCreate] method using either + * the [initSRGAnalytics()][initSRGAnalytics] or the [init()][init] method and providing an [AnalyticsConfig] instance. * + * ```kotlin + * class MyApplication : Application() { * override fun onCreate() { * super.onCreate() + * * val config = AnalyticsConfig( * vendor = AnalyticsConfig.Vendor.SRG, - * virtualSite = "Your AppSiteName here", - * sourceKey = "CommandersAct source key" + * appSiteName = "Your AppSiteName here", + * sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG, + * nonLocalizedApplicationName = "Your non-localized AppSiteName here", * ) - * initSRGAnalytics(config = config) + * + * initSRGAnalytics(config) + * // or + * SRGAnalytics.init(this, config) * } * } * ``` @@ -43,8 +50,14 @@ object SRGAnalytics { private var instance: Analytics? = null /** - * SRG CommandersAct analytics, do not use it unless you don't have any other choice! - * Meant to be used internally inside Pillarbox + * Provides access to the [CommandersAct] instance. + * + * If an instance of [CommandersAct] is available, it is returned. Otherwise, a no-op instance is returned, preventing any actions from being + * performed. + * + * Do not use it unless you don't have any other choice! Meant to be used internally inside Pillarbox. + * + * @return The [CommandersAct] instance, or a no-op instance if none is available. */ val commandersAct: CommandersAct get() { @@ -52,8 +65,14 @@ object SRGAnalytics { } /** - * SRG ComScore analytics, do not use it unless you don't have any other choice! - * Meant to be used internally inside Pillarbox + * Provides access to the [ComScore] instance. + * + * If an instance of [ComScore] is available, it is returned. Otherwise, a no-op instance is returned, preventing any actions from being + * performed. + * + * Do not use it unless you don't have any other choice! Meant to be used internally inside Pillarbox. + * + * @return The [ComScore] instance, or a no-op instance if none is available. */ val comScore: ComScore get() { @@ -61,10 +80,15 @@ object SRGAnalytics { } /** - * Initialize SRGAnalytics have to be called in [Application.onCreate] + * Initializes the [SRGAnalytics] instance. + * + * This method should be called only once, typically in your [Application]'s [onCreate()][Application.onCreate] method. It initializes the + * various analytics services like ComScore and Commanders Act based on the provided configuration. * - * @param application The application instance where you override onCreate(). - * @param config The [AnalyticsConfig] to initialize with. + * @param application The [Application] instance. + * @param config The [AnalyticsConfig] object containing the configuration for the analytics services. + * + * @throws IllegalStateException If the [SRGAnalytics] instance is already initialized. */ @Synchronized @JvmStatic @@ -77,29 +101,30 @@ object SRGAnalytics { } /** - * Send page view + * Sends a page view event to both Commanders Act and ComScore. * - * @param commandersAct The [CommandersActPageView] to send to CommandersAct. - * @param comScore The [ComScorePageView] to send to ComScore. + * @param commandersAct The page view data for Commanders Act. + * @param comScore The page view data for ComScore. */ fun sendPageView(commandersAct: CommandersActPageView, comScore: ComScorePageView) { instance?.sendPageView(commandersAct, comScore) } /** - * Send event to CommandersAct + * Sends an event to Commanders Act. * - * @param event the [CommandersActEvent] to send. + * @param event The event to send. */ fun sendEvent(event: CommandersActEvent) { instance?.sendEvent(event) } /** - * Put persistent labels + * Puts persistent labels for both Commanders Act and ComScore. These labels will be included in all subsequent tracking events until they are + * overwritten. * - * @param commandersActLabels CommandersAct specific persistent label. - * @param comScoreLabels ComScore specific persistent label. + * @param commandersActLabels A map representing the Commanders Act labels. + * @param comScoreLabels A map representing the ComScore labels. */ fun putPersistentLabels( commandersActLabels: Map, @@ -109,18 +134,18 @@ object SRGAnalytics { } /** - * Remove persistent label for CommandersAct and/or ComScore. + * Removes a persistent label from both Commanders Act and ComScore. * - * @param label The label to remove. + * @param label The name of the persistent label to remove. */ fun removePersistentLabel(label: String) { instance?.removePersistentLabel(label) } /** - * Remove multiple persistent labels. + * Removes the specified persistent labels from both Commanders Act and ComScore. * - * @param labels List of labels to remove. + * @param labels A list of persistent label names to remove. */ fun removePersistentLabels(labels: List) { instance?.let { analytics -> @@ -131,38 +156,43 @@ object SRGAnalytics { } /** - * Get ComScore persistent label + * Retrieves the ComScore persistent label associated with the given label. * - * @param label The label to get. - * @return associated ComScore label or null if not found. + * @param label The persistent label to retrieve. + * @return The ComScore label associated with the provided persistent label, or `null` if the label is not found. */ fun getComScorePersistentLabel(label: String): String? { return instance?.getComScorePersistentLabel(label) } /** - * Get CommandersAct persistent label + * Retrieves the Commanders Act persistent label associated with the given label. * - * @param label The label to get. - * @return associated CommandersAct label or null if not found. + * @param label The persistent label to retrieve. + * @return The Commanders Act label associated with the provided persistent label, or `null` if the label is not found. */ fun getCommandersActPersistentLabel(label: String): String? { return instance?.getCommandersActPermanentData(label) } /** - * Set user consent + * Sets the user consent for both Commanders Act and ComScore. * - * @param userConsent The user consent to apply. + * @param userConsent The [UserConsent] object containing the user consent settings. */ fun setUserConsent(userConsent: UserConsent) { instance?.setUserConsent(userConsent) } /** - * Init SRGAnalytics + * Initializes the [SRGAnalytics] instance. + * + * This method should be called only once, typically in your [Application]'s [onCreate()][Application.onCreate] method. It initializes the + * various analytics services like ComScore and Commanders Act based on the provided configuration. + * + * @param config The [AnalyticsConfig] object containing the configuration for the analytics services. * - * @param config The [AnalyticsConfig] to initialize with. + * @throws IllegalStateException If the [SRGAnalytics] instance is already initialized. */ fun Application.initSRGAnalytics(config: AnalyticsConfig) { init(this, config) @@ -180,7 +210,7 @@ object SRGAnalytics { fun sendEvent(commandersAct: CommandersActEvent) { this.commandersAct.sendEvent(commandersAct) - // Business decision to not send those event to comScore. + // Business decision to not send those events to comScore. } fun putPersistentLabels( diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/UserConsent.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/UserConsent.kt index a1be4956f..ce4a86391 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/UserConsent.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/UserConsent.kt @@ -7,10 +7,10 @@ package ch.srgssr.pillarbox.analytics import ch.srgssr.pillarbox.analytics.comscore.ComScoreUserConsent /** - * User consent + * Represents the user consent for various data collection and processing purposes. * - * @property comScore ComScore user consent. - * @property commandersActConsentServices CommandersAct consent services list. + * @property comScore The user consent for ComScore data collection. Defaults to [ComScoreUserConsent.UNKNOWN]. + * @property commandersActConsentServices A list of consent services for Commanders Act. Defaults to an empty list. */ data class UserConsent( val comScore: ComScoreUserConsent = ComScoreUserConsent.UNKNOWN, diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersAct.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersAct.kt index e295ce8ab..d55fa7d86 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersAct.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersAct.kt @@ -5,61 +5,68 @@ package ch.srgssr.pillarbox.analytics.commandersact /** - * Commanders act interface + * Interface for interacting with the Commanders Act SDK. + * + * This interface provides methods for sending data to Commanders Act, such as page views, events, and [TCMediaEvent]s. It also allows for managing + * permanent data and consent services. */ interface CommandersAct { /** - * Send page view + * Sends a page view event. * - * @param pageView the [CommandersActPageView] to send. + * @param pageView The [CommandersActPageView] to be sent. */ fun sendPageView(pageView: CommandersActPageView) /** - * Send event + * Sends an event. * - * @param event the [CommandersActEvent] to send. + * @param event The [CommandersActEvent] to be sent. */ fun sendEvent(event: CommandersActEvent) /** - * Send tc media event to TagCommander. + * Sends a [TCMediaEvent]. * - * @param event to send + * @param event The [TCMediaEvent] to be sent. */ fun sendTcMediaEvent(event: TCMediaEvent) /** - * Enable running in background + * Enables the tracking to continue running in the background. + * + * When the application is going to background, the ServerSide module sends all data that was already queued then stops. This helps preserve + * battery life and not use carrier data when not required. But some applications need to be able to continue sending data because they have real + * background activities, for example, listening to music. */ fun enableRunningInBackground() {} /** - * Put permanent data + * Puts the provided labels as permanent data. * - * @param labels The values to put. + * @param labels A map containing the labels. */ fun putPermanentData(labels: Map) /** - * Remove permanent data + * Removes permanent data associated with the given label. * * @param label The label to remove. */ fun removePermanentData(label: String) /** - * Get permanent label + * Retrieves a permanent data label associated with the given label. * - * @param label The label to get. - * @return null if not found. + * @param label The input label for which to retrieve the permanent data label. + * @return The permanent data label associated with the input label, or `null` if not found. */ fun getPermanentDataLabel(label: String): String? /** - * Set consent services + * Sets the list of consent services. * - * @param consentServices The list of consent services by the user. + * @param consentServices The list of consent services granted by the user. */ fun setConsentServices(consentServices: List) } diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActEvent.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActEvent.kt index 32f7319f3..2ac481202 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActEvent.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActEvent.kt @@ -4,16 +4,16 @@ */ package ch.srgssr.pillarbox.analytics.commandersact -import ch.srgssr.pillarbox.analytics.commandersact.TCEventExtensions.addAdditionalParameterIfNotBlank import com.tagcommander.lib.serverside.events.TCCustomEvent /** - * Analytics Event + * Represents an event to be sent to Commanders Act. * - * All properties are loosely defined, please discuss expected values for your application with your measurement team) + * @property name The name of the event. Must not be blank. + * @property labels A map of custom labels associated with the event. Defaults to an empty map. Please discuss the expected values for your + * application with your measurement team. * - * @property name The mandatory event name. - * @property labels The custom labels to send with. Blank value are not send. + * @throws IllegalArgumentException If [name] is blank. */ data class CommandersActEvent( val name: String, @@ -24,9 +24,9 @@ data class CommandersActEvent( } /** - * Convert into TagCommander event. + * Converts this event into a `TCCustomEvent`. * - * @return [TCCustomEvent] + * @return A `TCCustomEvent` instance populated with data from this instance. */ fun toTCCustomEvent(): TCCustomEvent { val event = TCCustomEvent(name) diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActLabels.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActLabels.kt index 23e7afc47..fb9577492 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActLabels.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActLabels.kt @@ -5,9 +5,9 @@ package ch.srgssr.pillarbox.analytics.commandersact /** - * Commanders act labels + * This enum defines the labels used for events sent to Commanders Act. * - * @property label the key property + * @property label The label used by Commanders Act. */ @Suppress("UndocumentedPublicProperty") enum class CommandersActLabels(val label: String) { diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActPageView.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActPageView.kt index e32e23e50..ae12ec017 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActPageView.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActPageView.kt @@ -5,16 +5,19 @@ package ch.srgssr.pillarbox.analytics.commandersact import ch.srgssr.pillarbox.analytics.AnalyticsConfig -import ch.srgssr.pillarbox.analytics.commandersact.TCEventExtensions.addAdditionalParameterIfNotBlank import com.tagcommander.lib.serverside.events.TCPageViewEvent /** - * Page event + * Represents a page view event for Commanders Act. * - * @property name The page event name. - * @property type The page event type ie (Articles). - * @property levels The page event levels. - * @property labels The custom labels to send with this page view event. Blank values are not send. + * This class encapsulates the data required to track a page view event, including the page name, type, navigation levels, and custom labels. + * + * @property name The name of the page being viewed. This property cannot be blank. + * @property type The type of the page. This property cannot be blank. + * @property levels A list of strings representing the navigation levels of the page. Defaults to an empty list. + * @property labels A map of custom labels to be associated with the page view event. Blank values are ignored and not sent. Defaults to an empty map. + * + * @throws IllegalArgumentException If [name] or [type] is blank. */ class CommandersActPageView( val name: String, @@ -28,9 +31,11 @@ class CommandersActPageView( } /** - * Convert to [TCPageViewEvent] + * Converts this event to a `TCPageViewEvent`. + * + * @param vendor The [vendor][AnalyticsConfig.Vendor] associated with this event. * - * @param vendor The vendor of this event. + * @return A `TCPageViewEvent` instance populated with data from this instance and the provided vendor. */ fun toTCPageViewEvent(vendor: AnalyticsConfig.Vendor): TCPageViewEvent { val tcEvent = TCPageViewEvent() diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrg.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrg.kt index 6aad567f3..379713518 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrg.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrg.kt @@ -73,14 +73,6 @@ internal class CommandersActSrg( tcServerSide.execute(event) } - /** - * Enable running in background - * - * While the application is going to background, the ServerSide's module sends all data that was already queued then stops. - * This is in order to preserve battery life and not use carrier data when not required. - * But some applications need to be able to continue sending data because they have real background activities. - * For example listening to music. - */ override fun enableRunningInBackground() { // on apple always one! Maybe tracker enable it. tcServerSide.enableRunningInBackground() diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/MediaEventType.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/MediaEventType.kt index 582128b14..079cec9b8 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/MediaEventType.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/MediaEventType.kt @@ -5,7 +5,10 @@ package ch.srgssr.pillarbox.analytics.commandersact /** - * CommandersAct [TCMediaEvent] Media event type + * Represents the type of media event for Commanders Act's [TCMediaEvent]. This enum defines the various events that can occur during media playback, + * such as play, pause, end of file, etc. + * + * These values are used to track and report user interactions with media content to Commanders Act for analytics purposes. */ @Suppress("UndocumentedPublicProperty") enum class MediaEventType { diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/TCEventExtensions.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/TCEventExtensions.kt index b8cdc40a7..ebd6f0bcd 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/TCEventExtensions.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/TCEventExtensions.kt @@ -7,19 +7,13 @@ package ch.srgssr.pillarbox.analytics.commandersact import com.tagcommander.lib.serverside.events.base.TCEvent /** - * CommandersAct event conversion + * Adds a parameter to this [TCEvent] if the provided data is not blank. + * + * @param key The key of the parameter. + * @param data The data of the parameter. If this value is `null` or blank, the parameter will not be added. */ -object TCEventExtensions { - - /** - * Add additional parameter if not blank - * - * @param key Key to add data. - * @param data Data to add if not null or blank. - */ - fun TCEvent.addAdditionalParameterIfNotBlank(key: String, data: String?) { - if (!data.isNullOrBlank()) { - addAdditionalProperty(key, data) - } +internal fun TCEvent.addAdditionalParameterIfNotBlank(key: String, data: String?) { + if (!data.isNullOrBlank()) { + addAdditionalProperty(key, data) } } diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/TCMediaEvent.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/TCMediaEvent.kt index 90508b27c..1961c9cdb 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/TCMediaEvent.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/TCMediaEvent.kt @@ -12,11 +12,11 @@ import kotlin.time.Duration import kotlin.time.DurationUnit /** - * CommandersAct media event + * Represents a media event to be sent to Commanders Act. This class extends `TCCustomEvent` and adds specific properties for media tracking. * - * @property eventType Media event type defined by Analytics team. - * @property assets Assets to populate with key,values. - * @property sourceId an optional sourceId. + * @property eventType The type of media event, defined by the Analytics team using the [MediaEventType] enum. + * @property assets A map representing additional data associated with the event. + * @property sourceId An optional identifier for the source of the event. */ class TCMediaEvent( val eventType: MediaEventType, @@ -24,37 +24,37 @@ class TCMediaEvent( val sourceId: String? = null ) : TCCustomEvent(eventType.toString()) { /** - * Current Media position + * Represents the current playback position. */ var mediaPosition: Duration = Duration.ZERO /** - * Time shift if applicable + * Represents the time shift applied if it is a live stream, `null` otherwise. */ var timeShift: Duration? = null /** - * Device volume in percentage + * Represents the device's volume level as a percentage. */ var deviceVolume: Float? = null /** - * Is subtitles on + * Indicates whether subtitles are enabled. */ var isSubtitlesOn: Boolean = false /** - * Selected subtitle language if any + * Represents the language of the currently selected subtitle track. */ var subtitleSelectionLanguage: String? = null /** - * Selected audio language if any + * Represents the language of the currently selected audio track. */ var audioTrackLanguage: String? = null /** - * Audio track has audio description + * Indicates whether the current audio track has an associated audio description. */ var audioTrackHasAudioDescription: Boolean = false diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScore.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScore.kt index b978e3f7b..20f51d6e0 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScore.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScore.kt @@ -5,43 +5,44 @@ package ch.srgssr.pillarbox.analytics.comscore /** - * ComScore + * Interface for interacting with the ComScore SDK. * - * @constructor Create empty Com score + * This interface provides methods for sending page view to ComScore. It also allows for managing permanent data and user consent. */ interface ComScore { /** - * Send page view to ComScore - * @param pageView The [ComScorePageView] to send. + * Sends a page view event to ComScore. + * + * @param pageView The [ComScorePageView] to be sent. */ fun sendPageView(pageView: ComScorePageView) /** - * Put persistent labels + * Puts the provided labels as persistent data. * - * @param labels The values to put. + * @param labels A map containing the labels. */ fun putPersistentLabels(labels: Map) /** - * Remove persistent label + * Removes a persistent label. * * @param label The label to remove. */ fun removePersistentLabel(label: String) /** - * Get persistent label + * Retrieves the persistent value associated with the given label. * - * @param label The label to get. - * @return null if not found. + * @param label The label used to identify the persistent value. + * @return The persistent value associated with the label, or `null` if not found. */ fun getPersistentLabel(label: String): String? /** - * Set user consent + * Sets the user consent. * - * @param userConsent + * @param userConsent The user consent level, represented by a [ComScoreUserConsent] enum entry. */ fun setUserConsent(userConsent: ComScoreUserConsent) } diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScorePageView.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScorePageView.kt index ebb3ab2d2..e7bc6f47a 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScorePageView.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScorePageView.kt @@ -5,10 +5,14 @@ package ch.srgssr.pillarbox.analytics.comscore /** - * ComScore page view + * Represents a page view event for ComScore. * - * @property name The name of the page view. - * @property labels The custom labels to send with this page view event. Blank values are not send. + * This class encapsulates the data required to track a page view event, including the page name and custom labels. + * + * @property name The name of the page being viewed. This property cannot be blank. + * @property labels A map of custom labels to be associated with the page view event. Blank values are ignored and not sent. Defaults to an empty map. + * + * @throws IllegalArgumentException If [name] is blank. */ data class ComScorePageView( val name: String, @@ -19,7 +23,9 @@ data class ComScorePageView( } /** - * Labels as a Map usable by ComScore. + * Converts this object's properties into a [Map] of labels suitable for ComScore. + * + * @return A [Map] containing the labels, ready to be used by ComScore. */ fun toLabels(): Map { val labels = HashMap() diff --git a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreUserConsent.kt b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreUserConsent.kt index 080d5ad93..04b699695 100644 --- a/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreUserConsent.kt +++ b/pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreUserConsent.kt @@ -5,27 +5,22 @@ package ch.srgssr.pillarbox.analytics.comscore /** - * Com score user consent + * Represents the user consent status for ComScore. */ enum class ComScoreUserConsent { /** - * Unknown - * - * User has not taken an action. + * Represents a status that is unknown or has not yet been determined. This typically serves as a default or initial state before an action is + * taken. */ UNKNOWN, /** - * Accepted - * - * User has given consent. + * Indicates that the user has explicitly given consent. */ ACCEPTED, /** - * Declined - * - * User has not given consent or has opted out. + * Indicates that the user has explicitly declined the request or opted out. */ DECLINED, } diff --git a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/commandersact/TCEventExtensionsTest.kt b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/commandersact/TCEventExtensionsTest.kt index 85688b1e7..be9676d94 100644 --- a/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/commandersact/TCEventExtensionsTest.kt +++ b/pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/commandersact/TCEventExtensionsTest.kt @@ -4,7 +4,6 @@ */ package ch.srgssr.pillarbox.analytics.commandersact -import ch.srgssr.pillarbox.analytics.commandersact.TCEventExtensions.addAdditionalParameterIfNotBlank import com.tagcommander.lib.serverside.events.TCCustomEvent import kotlin.test.Test import kotlin.test.assertEquals