From 7aeb5f072da1b7c523523c1ae40f6d527bf88245 Mon Sep 17 00:00:00 2001 From: Jeff Boek Date: Fri, 14 Feb 2020 14:09:14 -0800 Subject: [PATCH] For #7295 - Adds more documentation for the installation metrics --- app/metrics.yaml | 24 +++++++++---------- app/pings.yaml | 6 ++--- .../metrics/AdjustMetricsService.kt | 5 +--- .../components/metrics/InstallationPing.kt | 16 +++++++------ .../java/org/mozilla/fenix/utils/Settings.kt | 5 ---- .../metrics/InstallationPingTest.kt | 10 ++------ docs/metrics.md | 12 +++++----- 7 files changed, 33 insertions(+), 45 deletions(-) diff --git a/app/metrics.yaml b/app/metrics.yaml index 4cbf1b3ee..4e18979af 100644 --- a/app/metrics.yaml +++ b/app/metrics.yaml @@ -1796,11 +1796,11 @@ installation: send_in_pings: - installation description: > - Campaign + The name of the campaign that is responsible for this installation. bugs: - https://github.com/mozilla-mobile/fenix/issues/7295 data_reviews: - - TODO + - https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202 notification_emails: - fenix-core@mozilla.com expires: "2020-09-01" @@ -1809,11 +1809,11 @@ installation: send_in_pings: - installation description: > - Network + The name of the Network that sourced this installation. bugs: - https://github.com/mozilla-mobile/fenix/issues/7295 data_reviews: - - TODO + - https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202 notification_emails: - fenix-core@mozilla.com expires: "2020-09-01" @@ -1822,11 +1822,11 @@ installation: send_in_pings: - installation description: > - AdGroup + The name of the AdGroup that was used to source this installation. bugs: - - https://github.com/mozilla-mobile/fenix/issues/7295 + - https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202 data_reviews: - - TODO + - https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586480836 notification_emails: - fenix-core@mozilla.com expires: "2020-09-01" @@ -1835,24 +1835,24 @@ installation: - installation type: string description: > - Creative + The identifier of the creative material that the user interacted with. bugs: - https://github.com/mozilla-mobile/fenix/issues/7295 data_reviews: - - TODO + - https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202 notification_emails: - fenix-core@mozilla.com expires: "2020-09-01" timestamp: send_in_pings: - installation - type: string + type: datetime description: > - Timestamp + The date and time of the installation. bugs: - https://github.com/mozilla-mobile/fenix/issues/7295 data_reviews: - - TODO + - https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202 notification_emails: - fenix-core@mozilla.com expires: "2020-09-01" diff --git a/app/pings.yaml b/app/pings.yaml index 25091f481..5aa95833e 100644 --- a/app/pings.yaml +++ b/app/pings.yaml @@ -21,11 +21,11 @@ activation: installation: description: > - Intended for counting user installs. + This ping is intended to capture the source of the installation include_client_id: false bugs: - https://github.com/mozilla-mobile/fenix/issues/7295 data_reviews: - - TODO + - https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202 notification_emails: - - fenix-core@mozilla.com + - fenix-core@mozilla.com diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt index 28e8afd09..7bff20ded 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/AdjustMetricsService.kt @@ -54,10 +54,7 @@ class AdjustMetricsService(private val application: Application) : MetricsServic application.applicationContext.settings().adjustCampaignId = it.campaign } - if (application.applicationContext.settings().adjustInstallTimestamp.isEmpty()) { - application.applicationContext.settings().adjustInstallTimestamp = - System.currentTimeMillis().toString() - } + InstallationPing(application).checkAndSend() } diff --git a/app/src/main/java/org/mozilla/fenix/components/metrics/InstallationPing.kt b/app/src/main/java/org/mozilla/fenix/components/metrics/InstallationPing.kt index 4d444123e..384b086f8 100644 --- a/app/src/main/java/org/mozilla/fenix/components/metrics/InstallationPing.kt +++ b/app/src/main/java/org/mozilla/fenix/components/metrics/InstallationPing.kt @@ -54,13 +54,15 @@ class InstallationPing(private val context: Context) { */ @VisibleForTesting(otherwise = VisibleForTesting.PRIVATE) internal fun triggerPing() { - if (checkMetricsNotEmpty() - ) { - Installation.campaign.set(context.settings().adjustCampaignId) - Installation.adgroup.set(context.settings().adjustAdGroup) - Installation.creative.set(context.settings().adjustCreative) - Installation.network.set(context.settings().adjustNetwork) - Installation.timestamp.set(context.settings().adjustInstallTimestamp) + if (checkMetricsNotEmpty()) { + context.settings().also { + Installation.campaign.set(it.adjustCampaignId) + Installation.adgroup.set(it.adjustAdGroup) + Installation.creative.set(it.adjustCreative) + Installation.network.set(it.adjustNetwork) + Installation.timestamp.set() + } + CoroutineScope(Dispatchers.IO).launch { Pings.installation.submit() markAsTriggered() diff --git a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt index 61a9f5827..37c9e7e71 100644 --- a/app/src/main/java/org/mozilla/fenix/utils/Settings.kt +++ b/app/src/main/java/org/mozilla/fenix/utils/Settings.kt @@ -110,11 +110,6 @@ class Settings private constructor( default = "" ) - var adjustInstallTimestamp by stringPreference( - appContext.getPreferenceKey(R.string.pref_key_adjust_install_timestamp), - default = "" - ) - var openLinksInAPrivateTab by booleanPreference( appContext.getPreferenceKey(R.string.pref_key_open_links_in_a_private_tab), default = false diff --git a/app/src/test/java/org/mozilla/fenix/components/metrics/InstallationPingTest.kt b/app/src/test/java/org/mozilla/fenix/components/metrics/InstallationPingTest.kt index dce61eba6..752eeb337 100644 --- a/app/src/test/java/org/mozilla/fenix/components/metrics/InstallationPingTest.kt +++ b/app/src/test/java/org/mozilla/fenix/components/metrics/InstallationPingTest.kt @@ -12,20 +12,14 @@ import io.mockk.mockk import io.mockk.mockkStatic import io.mockk.spyk import io.mockk.verify -import kotlinx.coroutines.ExperimentalCoroutinesApi -import kotlinx.coroutines.test.runBlockingTest import org.junit.Test -import org.mozilla.fenix.TestApplication import org.mozilla.fenix.ext.settings import org.mozilla.fenix.utils.Settings -import org.robolectric.annotation.Config -@ExperimentalCoroutinesApi -@Config(application = TestApplication::class) internal class InstallationPingTest { @Test - fun `checkAndSend() triggers the ping if it wasn't marked as triggered`() = runBlockingTest { + fun `checkAndSend() triggers the ping if it wasn't marked as triggered`() { val mockedContext: Context = mockk(relaxed = true) val mockedSettings: Settings = mockk(relaxed = true) mockkStatic("org.mozilla.fenix.ext.ContextKt") @@ -40,7 +34,7 @@ internal class InstallationPingTest { verify(exactly = 1) { mockAp.triggerPing() } // Marking the ping as triggered happens in a co-routine off the main thread, // so wait a bit for it. - verify(exactly = 1) { mockAp.markAsTriggered() } + verify(timeout = 5000, exactly = 1) { mockAp.markAsTriggered() } } @Test diff --git a/docs/metrics.md b/docs/metrics.md index 20ec606d4..c44fcdbea 100644 --- a/docs/metrics.md +++ b/docs/metrics.md @@ -171,17 +171,17 @@ The following metrics are added to the ping: | user_specified_search_engines.custom_engine_deleted |[event](https://mozilla.github.io/glean/book/user/metrics/event.html) |A user deleted a custom search engine |[1](https://github.com/mozilla-mobile/fenix/pull/6918)||2020-09-01 | ## installation -Intended for counting user installs. +This ping is intended to capture the source of the installation The following metrics are added to the ping: | Name | Type | Description | Data reviews | Extras | Expiration | | --- | --- | --- | --- | --- | --- | -| installation.adgroup |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |AdGroup |[1](TODO)||2020-09-01 | -| installation.campaign |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |Campaign |[1](TODO)||2020-09-01 | -| installation.creative |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |Creative |[1](TODO)||2020-09-01 | -| installation.network |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |Network |[1](TODO)||2020-09-01 | -| installation.timestamp |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |Timestamp |[1](TODO)||2020-09-01 | +| installation.adgroup |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The name of the AdGroup that was used to source this installation. |[1](https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586480836)||2020-09-01 | +| installation.campaign |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The name of the campaign that is responsible for this installation. |[1](https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202)||2020-09-01 | +| installation.creative |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The identifier of the creative material that the user interacted with. |[1](https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202)||2020-09-01 | +| installation.network |[string](https://mozilla.github.io/glean/book/user/metrics/string.html) |The name of the Network that sourced this installation. |[1](https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202)||2020-09-01 | +| installation.timestamp |[datetime](https://mozilla.github.io/glean/book/user/metrics/datetime.html) |The date and time of the installation. |[1](https://github.com/mozilla-mobile/fenix/pull/8074#issuecomment-586512202)||2020-09-01 | ## metrics This is a built-in ping that is assembled out of the box by the Glean SDK.