From e818301a74835a6687ccdf23f679f9b342d1094a Mon Sep 17 00:00:00 2001 From: Craig Russell Date: Mon, 26 Feb 2024 10:14:53 +0000 Subject: [PATCH] Add pixel for process creation, for both main and VPN processes (#4208) Task/Issue URL: https://app.asana.com/0/488551667048375/1206681496516579/f ### Description Adds process creation pixels, for both main app and VPN process. ### Steps to test this PR - [x] Add logcat filter `message~:"m_process_created"` **Main app process** - [x] Launch the app; verify you see `m_process_created_main` - [x] Background and restore the app; verify you do **not** see it again - [x] Kill the app and relaunch it; verify you **do** see it again **VPN process** - [x] onboard through AppTP - [x] verify you see `m_process_created_vpn` in the logs --- .../com/duckduckgo/app/pixels/AppPixelName.kt | 2 + .../app/pixels/ProcessCreationPixelSender.kt | 54 +++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 app/src/main/java/com/duckduckgo/app/pixels/ProcessCreationPixelSender.kt diff --git a/app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt b/app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt index be98c17e3d04..5cb969803778 100644 --- a/app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt +++ b/app/src/main/java/com/duckduckgo/app/pixels/AppPixelName.kt @@ -20,6 +20,8 @@ import com.duckduckgo.app.statistics.pixels.Pixel enum class AppPixelName(override val pixelName: String) : Pixel.PixelName { APP_LAUNCH("ml"), + PROCESS_CREATED_MAIN("m_process_created_main"), + PROCESS_CREATED_VPN("m_process_created_vpn"), FORGET_ALL_PRESSED_BROWSING("mf_bp"), FORGET_ALL_PRESSED_TABSWITCHING("mf_tp"), diff --git a/app/src/main/java/com/duckduckgo/app/pixels/ProcessCreationPixelSender.kt b/app/src/main/java/com/duckduckgo/app/pixels/ProcessCreationPixelSender.kt new file mode 100644 index 000000000000..db77bdf9ba39 --- /dev/null +++ b/app/src/main/java/com/duckduckgo/app/pixels/ProcessCreationPixelSender.kt @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2024 DuckDuckGo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.duckduckgo.app.pixels + +import androidx.lifecycle.LifecycleOwner +import com.duckduckgo.app.lifecycle.MainProcessLifecycleObserver +import com.duckduckgo.app.lifecycle.VpnProcessLifecycleObserver +import com.duckduckgo.app.statistics.pixels.Pixel +import com.duckduckgo.di.scopes.AppScope +import com.squareup.anvil.annotations.ContributesMultibinding +import dagger.SingleInstanceIn +import javax.inject.Inject + +@ContributesMultibinding( + scope = AppScope::class, + boundType = MainProcessLifecycleObserver::class, +) +@SingleInstanceIn(AppScope::class) +class ProcessCreationMainPixelSender @Inject constructor( + private val pixel: Pixel, +) : MainProcessLifecycleObserver { + + override fun onCreate(owner: LifecycleOwner) { + pixel.fire(AppPixelName.PROCESS_CREATED_MAIN) + } +} + +@ContributesMultibinding( + scope = AppScope::class, + boundType = VpnProcessLifecycleObserver::class, +) +@SingleInstanceIn(AppScope::class) +class ProcessCreationVpnPixelSender @Inject constructor( + private val pixel: Pixel, +) : VpnProcessLifecycleObserver { + + override fun onVpnProcessCreated() { + pixel.fire(AppPixelName.PROCESS_CREATED_VPN) + } +}