Skip to content

Commit 7eb7745

Browse files
authored
895 avoid arbitrary source keys (#900)
1 parent 6d03707 commit 7eb7745

File tree

9 files changed

+41
-15
lines changed

9 files changed

+41
-15
lines changed

pillarbox-analytics/docs/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MyApplication : Application() {
3131
val config = AnalyticsConfig(
3232
vendor = AnalyticsConfig.Vendor.SRG,
3333
appSiteName = "Your AppSiteName here",
34-
sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG,
34+
sourceKey = SourceKey.SRG_DEBUG,
3535
nonLocalizedApplicationName = "Your non-localized AppSiteName here",
3636
)
3737

@@ -56,7 +56,7 @@ val userConsent = UserConsent(
5656
val config = AnalyticsConfig(
5757
vendor = AnalyticsConfig.Vendor.SRG,
5858
appSiteName = "Your AppSiteName here",
59-
sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG,
59+
sourceKey = SourceKey.SRG_DEBUG,
6060
nonLocalizedApplicationName = "Your non-localized AppSiteName here",
6161
userConsent = userConsent,
6262
)

pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/AnalyticsConfig.kt

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
*/
55
package ch.srgssr.pillarbox.analytics
66

7-
import ch.srgssr.pillarbox.analytics.AnalyticsConfig.Companion.SOURCE_KEY_SRG_DEBUG
8-
import ch.srgssr.pillarbox.analytics.AnalyticsConfig.Companion.SOURCE_KEY_SRG_PROD
97
import ch.srgssr.pillarbox.analytics.SRGAnalytics.initSRGAnalytics
108

119
/**
@@ -17,8 +15,8 @@ import ch.srgssr.pillarbox.analytics.SRGAnalytics.initSRGAnalytics
1715
*
1816
* @property vendor The vendor to which the application belongs to.
1917
* @property appSiteName The name of the app/site being tracked, given by the analytics team.
20-
* @property sourceKey The CommandersAct source key. Production apps should use [SOURCE_KEY_SRG_PROD], and apps in development should use
21-
* [SOURCE_KEY_SRG_DEBUG].
18+
* @property sourceKey The CommandersAct source key. Production apps should use [SourceKey.SRG_PROD], and apps in development should use
19+
* [SourceKey.SRG_DEBUG].
2220
* @property nonLocalizedApplicationName The non-localized name of the application. By default, the application name defined in the manifest is used.
2321
* @property userConsent The user consent to transmit to ComScore and CommandersAct.
2422
* @property comScorePersistentLabels The initial persistent labels for ComScore analytics.
@@ -27,7 +25,7 @@ import ch.srgssr.pillarbox.analytics.SRGAnalytics.initSRGAnalytics
2725
data class AnalyticsConfig(
2826
val vendor: Vendor,
2927
val appSiteName: String,
30-
val sourceKey: String,
28+
val sourceKey: SourceKey,
3129
val nonLocalizedApplicationName: String? = null,
3230
val userConsent: UserConsent = UserConsent(),
3331
val comScorePersistentLabels: Map<String, String>? = null,
@@ -48,14 +46,17 @@ data class AnalyticsConfig(
4846

4947
@Suppress("UndocumentedPublicClass")
5048
companion object {
49+
5150
/**
5251
* The source key for SRG SSR apps in production.
5352
*/
54-
const val SOURCE_KEY_SRG_PROD = "3909d826-0845-40cc-a69a-6cec1036a45c"
53+
@Deprecated("Use [SourceKey.SRG_PROD] instead.", ReplaceWith("SourceKey.SRG_PROD"))
54+
val SOURCE_KEY_SRG_PROD = SourceKey.SRG_PROD
5555

5656
/**
5757
* The source key for SRG SSR apps in development.
5858
*/
59-
const val SOURCE_KEY_SRG_DEBUG = "6f6bf70e-4129-4e47-a9be-ccd1737ba35f"
59+
@Deprecated("Use [SourceKey.SRG_DEBUG] instead.", ReplaceWith("SourceKey.SRG_DEBUG"))
60+
val SOURCE_KEY_SRG_DEBUG = SourceKey.SRG_DEBUG
6061
}
6162
}

pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/SRGAnalytics.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ import ch.srgssr.pillarbox.analytics.comscore.NoOpComScore
3434
* val config = AnalyticsConfig(
3535
* vendor = AnalyticsConfig.Vendor.SRG,
3636
* appSiteName = "Your AppSiteName here",
37-
* sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG,
37+
* sourceKey = SourceKey.SRG_DEBUG,
3838
* nonLocalizedApplicationName = "Your non-localized AppSiteName here",
3939
* )
4040
*
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) SRG SSR. All rights reserved.
3+
* License information is available from the LICENSE file.
4+
*/
5+
package ch.srgssr.pillarbox.analytics
6+
7+
/**
8+
* CommandersAct source key.
9+
*
10+
* @property key the CommandersAct source key.
11+
*/
12+
enum class SourceKey(val key: String) {
13+
/**
14+
* The source key for SRG SSR apps in production.
15+
*/
16+
SRG_PROD("3909d826-0845-40cc-a69a-6cec1036a45c"),
17+
18+
/**
19+
* The source key for SRG SSR apps in development.
20+
*/
21+
SRG_DEBUG("6f6bf70e-4129-4e47-a9be-ccd1737ba35f"),
22+
}

pillarbox-analytics/src/main/java/ch/srgssr/pillarbox/analytics/commandersact/CommandersActSrg.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ internal class CommandersActSrg(
4848
config: AnalyticsConfig,
4949
appContext: Context
5050
) : this(
51-
tcServerSide = TCServerSide(SITE_SRG, config.sourceKey, appContext),
51+
tcServerSide = TCServerSide(SITE_SRG, config.sourceKey.key, appContext),
5252
config = config,
5353
navigationDevice = appContext.getString(R.string.tc_analytics_device)
5454
) {

pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/SRGAnalyticsSingletonTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class SRGAnalyticsSingletonTest {
2222
private val config = AnalyticsConfig(
2323
vendor = AnalyticsConfig.Vendor.SRG,
2424
appSiteName = "pillarbox-test-android",
25-
sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG
25+
sourceKey = SourceKey.SRG_DEBUG
2626
)
2727

2828
private lateinit var context: Context

pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/commandersact/TestUtils.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
package ch.srgssr.pillarbox.analytics.commandersact
66

77
import ch.srgssr.pillarbox.analytics.AnalyticsConfig
8+
import ch.srgssr.pillarbox.analytics.SourceKey
89

910
object TestUtils {
1011
val analyticsConfig = AnalyticsConfig(
1112
vendor = AnalyticsConfig.Vendor.SRG,
1213
appSiteName = "pillarbox-test-android",
13-
sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG
14+
sourceKey = SourceKey.SRG_DEBUG
1415
)
1516
}

pillarbox-analytics/src/test/java/ch/srgssr/pillarbox/analytics/comscore/ComScoreSrgTest.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import android.content.Context
88
import androidx.test.core.app.ApplicationProvider
99
import androidx.test.ext.junit.runners.AndroidJUnit4
1010
import ch.srgssr.pillarbox.analytics.AnalyticsConfig
11+
import ch.srgssr.pillarbox.analytics.SourceKey
1112
import com.comscore.Analytics
1213
import com.comscore.PublisherConfiguration
1314
import io.mockk.clearAllMocks
@@ -27,7 +28,7 @@ class ComScoreSrgTest {
2728
private val config = AnalyticsConfig(
2829
vendor = AnalyticsConfig.Vendor.SRG,
2930
appSiteName = "pillarbox-test-android",
30-
sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG
31+
sourceKey = SourceKey.SRG_DEBUG
3132
)
3233

3334
private lateinit var context: Context

pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/DemoApplication.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ package ch.srgssr.pillarbox.demo
77
import android.app.Application
88
import ch.srgssr.pillarbox.analytics.AnalyticsConfig
99
import ch.srgssr.pillarbox.analytics.SRGAnalytics.initSRGAnalytics
10+
import ch.srgssr.pillarbox.analytics.SourceKey
1011
import ch.srgssr.pillarbox.analytics.UserConsent
1112
import ch.srgssr.pillarbox.analytics.comscore.ComScoreUserConsent
1213
import ch.srgssr.pillarbox.player.network.PillarboxOkHttp
@@ -33,7 +34,7 @@ class DemoApplication : Application(), SingletonImageLoader.Factory {
3334
vendor = AnalyticsConfig.Vendor.SRG,
3435
nonLocalizedApplicationName = "Pillarbox",
3536
appSiteName = "pillarbox-demo-android",
36-
sourceKey = AnalyticsConfig.SOURCE_KEY_SRG_DEBUG,
37+
sourceKey = SourceKey.SRG_DEBUG,
3738
userConsent = initialUserConsent
3839
)
3940
initSRGAnalytics(config = config)

0 commit comments

Comments
 (0)