Skip to content

Commit

Permalink
Add impression pixels
Browse files Browse the repository at this point in the history
  • Loading branch information
karlenDimla committed Aug 5, 2024
1 parent 06104d5 commit 6b5f123
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,16 @@ internal fun SubscriptionFeedbackCategory.asParams(): String {
}
}

internal fun SubscriptionFeedbackSubCategory.asParams(): String {
return when (this) {
is SubscriptionFeedbackVpnSubCategory -> this.asParams()
is SubscriptionFeedbackSubsSubCategory -> this.asParams()
is SubscriptionFeedbackPirSubCategory -> this.asParams()
is SubscriptionFeedbackItrSubCategory -> this.asParams()
else -> "unknown"
}
}

internal fun SubscriptionFeedbackVpnSubCategory.asParams(): String {
return when (this) {
FAILS_TO_CONNECT -> "failsToConnect"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import com.duckduckgo.subscriptions.impl.feedback.SubscriptionFeedbackVpnSubCate
import com.duckduckgo.subscriptions.impl.feedback.SubscriptionFeedbackVpnSubCategory.FAILS_TO_CONNECT
import com.duckduckgo.subscriptions.impl.feedback.SubscriptionFeedbackVpnSubCategory.ISSUES_WITH_APPS_OR_WEBSITES
import com.duckduckgo.subscriptions.impl.feedback.SubscriptionFeedbackVpnSubCategory.SLOW_CONNECTION
import com.duckduckgo.subscriptions.impl.feedback.pixels.PrivacyProUnifiedFeedbackPixelSender
import javax.inject.Inject
import kotlinx.coroutines.channels.BufferOverflow.DROP_OLDEST
import kotlinx.coroutines.channels.Channel
Expand All @@ -56,7 +57,9 @@ import kotlinx.coroutines.launch
import logcat.logcat

@ContributesViewModel(ActivityScope::class)
class SubscriptionFeedbackViewModel @Inject constructor() : ViewModel() {
class SubscriptionFeedbackViewModel @Inject constructor(
private val pixelSender: PrivacyProUnifiedFeedbackPixelSender,
) : ViewModel() {
private val viewState = MutableStateFlow(ViewState())
private val command = Channel<Command>(1, DROP_OLDEST)
internal fun viewState(): Flow<ViewState> = viewState.asStateFlow()
Expand All @@ -74,9 +77,17 @@ class SubscriptionFeedbackViewModel @Inject constructor() : ViewModel() {
isForward = true,
),
)

emitImpressionPixelForActionScreen(viewState.value.feedbackMetadata)
}
}

private fun emitImpressionPixelForActionScreen(metadata: FeedbackMetadata) {
pixelSender.reportPproFeedbackActionsScreenShown(
mapOf(PARAMS_KEY_SOURCE to metadata.source!!.asParams()),
)
}

fun onReportTypeSelected(reportType: SubscriptionFeedbackReportType) {
viewModelScope.launch {
val previousFragmentState = viewState.value.currentFragmentState
Expand All @@ -92,6 +103,13 @@ class SubscriptionFeedbackViewModel @Inject constructor() : ViewModel() {
isForward = true,
),
)

pixelSender.reportPproFeedbackCategoryScreenShown(
mapOf(
PARAMS_KEY_SOURCE to newMetadata.source!!.asParams(),
PARAMS_KEY_REPORT_TYPE to newMetadata.reportType!!.asParams(),
),
)
}
}

Expand All @@ -116,6 +134,18 @@ class SubscriptionFeedbackViewModel @Inject constructor() : ViewModel() {
isForward = true,
),
)

if (nextState is FeedbackSubCategory) {
pixelSender.reportPproFeedbackSubcategoryScreenShown(
mapOf(
PARAMS_KEY_SOURCE to newMetadata.source!!.asParams(),
PARAMS_KEY_REPORT_TYPE to newMetadata.reportType!!.asParams(),
PARAMS_KEY_CATEGORY to newMetadata.category!!.asParams(),
),
)
} else {
emitImpressionPixelForSubmit(newMetadata)
}
}
}

Expand All @@ -134,9 +164,21 @@ class SubscriptionFeedbackViewModel @Inject constructor() : ViewModel() {
isForward = true,
),
)
emitImpressionPixelForSubmit(newMetadata)
}
}

private fun emitImpressionPixelForSubmit(metadata: FeedbackMetadata) {
pixelSender.reportPproFeedbackSubmitScreenShown(
mapOf(
PARAMS_KEY_SOURCE to metadata.source!!.asParams(),
PARAMS_KEY_REPORT_TYPE to metadata.reportType!!.asParams(),
PARAMS_KEY_CATEGORY to metadata.category!!.asParams(),
PARAMS_KEY_SUBCATEGORY to metadata.subCategory!!.asParams(),
),
)
}

fun onSubmitFeedback(description: String) {
viewModelScope.launch {
val metadata = viewState.value.feedbackMetadata.copy(
Expand Down Expand Up @@ -174,19 +216,20 @@ class SubscriptionFeedbackViewModel @Inject constructor() : ViewModel() {
currentFragmentState = FeedbackGeneral,
),
)
// Emit shown pixel
pixelSender.reportPproFeedbackGeneralScreenShown()
}
}

fun allowUserToChooseReportType(source: PrivacyProFeedbackSource) {
viewModelScope.launch {
val metadata = FeedbackMetadata(source = source)
viewState.emit(
ViewState(
feedbackMetadata = FeedbackMetadata(source = source),
feedbackMetadata = metadata,
currentFragmentState = FeedbackAction,
),
)
// Emit shown pixel
emitImpressionPixelForActionScreen(metadata)
}
}

Expand All @@ -195,20 +238,21 @@ class SubscriptionFeedbackViewModel @Inject constructor() : ViewModel() {
appPackageName: String,
) {
viewModelScope.launch {
val metadata = FeedbackMetadata(
source = VPN_EXCLUDED_APPS,
reportType = REPORT_PROBLEM,
category = VPN,
subCategory = ISSUES_WITH_APPS_OR_WEBSITES,
appName = appName,
appPackageName = appPackageName,
)
viewState.emit(
ViewState(
feedbackMetadata = FeedbackMetadata(
source = VPN_EXCLUDED_APPS,
reportType = REPORT_PROBLEM,
category = VPN,
subCategory = ISSUES_WITH_APPS_OR_WEBSITES,
appName = appName,
appPackageName = appPackageName,
),
feedbackMetadata = metadata,
currentFragmentState = FeedbackSubmit(ISSUES_WITH_APPS_OR_WEBSITES.asTitle()),
),
)
// Emit shown pixel
emitImpressionPixelForSubmit(metadata)
}
}

Expand Down Expand Up @@ -360,4 +404,13 @@ class SubscriptionFeedbackViewModel @Inject constructor() : ViewModel() {

data class FeedbackSubmit(@StringRes override val title: Int) : FeedbackFragmentState(title)
}

companion object {
private const val PARAMS_KEY_SOURCE = "source"
private const val PARAMS_KEY_REPORT_TYPE = "reportType"
private const val PARAMS_KEY_CATEGORY = "category"
private const val PARAMS_KEY_SUBCATEGORY = "subcategory"
private const val PARAMS_KEY_DESC = "description"
private const val PARAMS_KEY_CUSTOM_METADATA = "customMetadata"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ enum class SubscriptionPixel(
types.associateWith { type -> if (withSuffix) "${baseName}_${type.pixelNameSuffix}" else baseName }
}

private val PixelType.pixelNameSuffix: String
internal val PixelType.pixelNameSuffix: String
get() = when (this) {
COUNT -> "c"
DAILY -> "d"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class SubscriptionPixelParamRemovalPlugin @Inject constructor() : PixelParamRemo
return listOf(
"m_subscribe" to PixelParameter.removeAtb(),
"m_subscribe" to PixelParameter.removeOSVersion(),
"m_ppro_feedback" to PixelParameter.removeAtb(),
)
}
}

0 comments on commit 6b5f123

Please sign in to comment.