Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/src/main/java/org/wikipedia/WikipediaApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import io.reactivex.rxjava3.schedulers.Schedulers
import org.wikipedia.analytics.InstallReferrerListener
import org.wikipedia.analytics.eventplatform.AppSessionEvent
import org.wikipedia.analytics.eventplatform.EventPlatformClient
import org.wikipedia.analytics.metricsplatform.SessionEvent
import org.wikipedia.appshortcuts.AppShortcuts
import org.wikipedia.auth.AccountUtil
import org.wikipedia.concurrency.RxBus
Expand Down Expand Up @@ -48,6 +49,7 @@ class WikipediaApp : Application() {
val mainThreadHandler by lazy { Handler(mainLooper) }
val languageState by lazy { AppLanguageState(this) }
val appSessionEvent by lazy { AppSessionEvent() }
val sessionEvent by lazy { SessionEvent() }

val userAgent by lazy {
var channel = ReleaseUtil.getChannel(this)
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/java/org/wikipedia/activity/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import org.wikipedia.WikipediaApp
import org.wikipedia.analytics.BreadcrumbsContextHelper
import org.wikipedia.analytics.eventplatform.BreadCrumbLogEvent
import org.wikipedia.analytics.eventplatform.NotificationInteractionEvent
import org.wikipedia.analytics.metricsplatform.BreadcrumbLogEvent
import org.wikipedia.appshortcuts.AppShortcuts
import org.wikipedia.auth.AccountUtil
import org.wikipedia.connectivity.ConnectionStateMonitor
Expand Down Expand Up @@ -74,6 +75,7 @@ abstract class BaseActivity : AppCompatActivity(), ConnectionStateMonitor.Callba
supportActionBar?.setDisplayHomeAsUpEnabled(true)
if (savedInstanceState == null) {
NotificationInteractionEvent.processIntent(intent)
org.wikipedia.analytics.metricsplatform.NotificationInteractionEvent.processIntent(intent)
}

// Conditionally execute all recurring tasks
Expand Down Expand Up @@ -112,13 +114,16 @@ abstract class BaseActivity : AppCompatActivity(), ConnectionStateMonitor.Callba

override fun onStop() {
WikipediaApp.instance.appSessionEvent.persistSession()
WikipediaApp.instance.sessionEvent.persistSession()
super.onStop()
}

override fun onResume() {
super.onResume()
WikipediaApp.instance.appSessionEvent.touchSession()
WikipediaApp.instance.sessionEvent.touchSession()
BreadCrumbLogEvent.logScreenShown(this)
BreadcrumbLogEvent().logScreenShown(this)

// allow this activity's exclusive bus methods to override any existing ones.
unregisterExclusiveBusMethods()
Expand All @@ -139,6 +144,7 @@ abstract class BaseActivity : AppCompatActivity(), ConnectionStateMonitor.Callba
override fun onBackPressed() {
super.onBackPressed()
BreadCrumbLogEvent.logBackPress(this)
BreadcrumbLogEvent().logBackPress(this)
}

override fun dispatchTouchEvent(event: MotionEvent): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.wikipedia.analytics
import android.view.*
import android.widget.TextView
import org.wikipedia.analytics.eventplatform.BreadCrumbLogEvent
import org.wikipedia.analytics.metricsplatform.BreadcrumbLogEvent
import org.wikipedia.page.LinkMovementMethodExt
import org.wikipedia.views.ViewUtil
import kotlin.math.abs
Expand Down Expand Up @@ -36,8 +37,10 @@ object BreadcrumbsContextHelper {
} else {
if (touchMillis > ViewConfiguration.getLongPressTimeout()) {
BreadCrumbLogEvent.logLongClick(window.context, it)
BreadcrumbLogEvent().logLongClick(window.context, it)
} else {
BreadCrumbLogEvent.logClick(window.context, it)
BreadcrumbLogEvent().logClick(window.context, it)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,11 @@ class InstallReferrerListener : InstallReferrerStateListener {
InstallReferrerEvent.PARAM_UTM_CAMPAIGN -> refUtmCampaign = item[1]
InstallReferrerEvent.PARAM_UTM_SOURCE -> refUtmSource = item[1]
InstallReferrerEvent.PARAM_CHANNEL -> refChannel = item[1]
org.wikipedia.analytics.metricsplatform.InstallReferrerEvent.PARAM_REFERRER_URL -> refUrl = item[1]
org.wikipedia.analytics.metricsplatform.InstallReferrerEvent.PARAM_UTM_MEDIUM -> refUtmMedium = item[1]
org.wikipedia.analytics.metricsplatform.InstallReferrerEvent.PARAM_UTM_CAMPAIGN -> refUtmCampaign = item[1]
org.wikipedia.analytics.metricsplatform.InstallReferrerEvent.PARAM_UTM_SOURCE -> refUtmSource = item[1]
org.wikipedia.analytics.metricsplatform.InstallReferrerEvent.PARAM_CHANNEL -> refChannel = item[1]
}
}
} catch (e: Exception) {
Expand All @@ -120,6 +125,7 @@ class InstallReferrerListener : InstallReferrerStateListener {
if (!refUrl.isNullOrEmpty() || !refUtmMedium.isNullOrEmpty() ||
!refUtmCampaign.isNullOrEmpty() || !refUtmSource.isNullOrEmpty()) {
InstallReferrerEvent.logInstall(refUrl, refUtmMedium, refUtmCampaign, refUtmSource)
org.wikipedia.analytics.metricsplatform.InstallReferrerEvent.logInstall(refUrl, refUtmMedium, refUtmCampaign, refUtmSource)
}
if (!refUrl.isNullOrEmpty() && ShareUtil.canOpenUrlInApp(WikipediaApp.instance, refUrl)) {
openPageFromUrl(WikipediaApp.instance, refUrl)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.wikipedia.WikipediaApp
import org.wikipedia.analytics.metricsplatform.BreadcrumbLogEvent
import org.wikipedia.auth.AccountUtil
import org.wikipedia.dataclient.ServiceFactory
import org.wikipedia.page.PageTitle
Expand Down Expand Up @@ -92,6 +93,7 @@ class MachineGeneratedArticleDescriptionsAnalyticsHelper {
return
}
EventPlatformClient.submit(BreadCrumbLogEvent(BreadCrumbViewUtil.getReadableScreenName(context), logString))
BreadcrumbLogEvent().log(context, logString)
}

private fun getOrderString(wasChosen: Boolean, suggestion: String): String {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.wikipedia.analytics.metricsplatform

import android.content.Context
import android.view.MenuItem
import android.view.View
import android.widget.Checkable
import android.widget.TextView
import androidx.fragment.app.Fragment
import org.wikipedia.analytics.eventplatform.BreadCrumbViewUtil
import org.wikipedia.settings.SettingsActivity
import org.wikipedia.util.log.L

class BreadcrumbLogEvent : MetricsEvent() {
fun log(context: Context, logString: String) {
submitEvent(BreadCrumbViewUtil.getReadableScreenName(context), logString)
}

fun logClick(context: Context, view: View) {
if (context is SettingsActivity) {
return
}
val viewReadableName = BreadCrumbViewUtil.getReadableNameForView(view)
val str = "$viewReadableName." + when (view) {
is Checkable -> if (!view.isChecked) "on" else "off"
else -> "click"
}
submitEvent(BreadCrumbViewUtil.getReadableScreenName(context), str)
}

fun logClick(context: Context, item: MenuItem) {
submitEvent(
BreadCrumbViewUtil.getReadableScreenName(context),
context.resources.getResourceEntryName(item.itemId) + ".click"
)
}

fun logLongClick(context: Context, view: View) {
val viewReadableName = BreadCrumbViewUtil.getReadableNameForView(view)
submitEvent(
BreadCrumbViewUtil.getReadableScreenName(context),
"$viewReadableName.longclick"
)
}

fun logScreenShown(context: Context, fragment: Fragment? = null) {
submitEvent(BreadCrumbViewUtil.getReadableScreenName(context, fragment), "show")
}

fun logBackPress(context: Context) {
submitEvent(BreadCrumbViewUtil.getReadableScreenName(context), "back")
}

fun logTooltipShown(context: Context, anchor: View) {
val viewReadableName = BreadCrumbViewUtil.getReadableNameForView(anchor)
submitEvent(context.javaClass.simpleName.orEmpty(), "$viewReadableName.tooltip")
}

fun logSettingsSelection(context: Context, title: String, newValue: Any? = null) {
val str =
title + "." + if (newValue is Boolean) (if (newValue == true) "on" else "off") else "click"
submitEvent(context.javaClass.simpleName.orEmpty(), str)
}

fun logInputField(context: Context, view: View) {
val viewReadableName = BreadCrumbViewUtil.getReadableNameForView(view)
val str = "$viewReadableName." + (view as TextView).text
submitEvent(BreadCrumbViewUtil.getReadableScreenName(context), str)
}

private fun submitEvent(context: String, action: String) {
L.d(">>> metrics_platform.breadcrumbs_event.$context.$action")
submitEvent(
"breadcrumbs_event.$context",
mapOf(
"action" to action
)
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package org.wikipedia.analytics.metricsplatform

import android.content.Context
import android.content.pm.PackageManager
import org.wikipedia.WikipediaApp
import java.util.concurrent.TimeUnit

class DailyStatsEvent : MetricsEvent() {
fun log(app: WikipediaApp) {
submitEvent(
"daily_stats",
mapOf(
"install_age_days" to getInstallAgeDays(app)
)
)
}

private fun getInstallAgeDays(context: Context): Long {
return TimeUnit.MILLISECONDS.toDays(getInstallAge(context))
}

private fun getInstallAge(context: Context): Long {
return System.currentTimeMillis() - getInstallTime(context)
}

private fun getInstallTime(context: Context): Long {
return try {
context.packageManager.getPackageInfo(context.packageName, 0).firstInstallTime
} catch (e: PackageManager.NameNotFoundException) {
throw RuntimeException(e)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
package org.wikipedia.analytics.metricsplatform

import org.wikimedia.metrics_platform.context.PageData
import org.wikipedia.diff.ArticleEditDetailsViewModel
import org.wikipedia.page.PageTitle
import org.wikipedia.page.edithistory.EditHistoryListViewModel

class EditHistoryInteractionEvent : TimedMetricsEvent {
private val pageData: PageData?

constructor(viewModel: ArticleEditDetailsViewModel) {
this.pageData = getPageData(viewModel, viewModel.revisionFromId)
}

constructor(viewModel: EditHistoryListViewModel) {
this.pageData = getPageData(viewModel)
}

constructor(pageTitle: PageTitle, pageId: Int, revisionId: Long) {
this.pageData = getPageData(pageTitle, pageId, revisionId)
}

fun logShowHistory() {
submitEvent("show_history")
}

fun logRevision() {
submitEvent("revision_view")
}

// User tapped 'Compare' on the edit History screen to start selecting the revisions to compare
fun logCompare1() {
submitEvent("compare1")
}

// User has selected a second revision and tapped the 'Compare' button, navigating them to the comparison screen
fun logCompare2() {
submitEvent("compare2")
}

fun logThankTry() {
submitEvent("thank_try")
}

fun logThankCancel() {
submitEvent("thank_cancel")
}

fun logThankSuccess() {
submitEvent("thank_success")
}

fun logThankFail() {
submitEvent("thank_fail")
}

fun logSearchClick() {
submitEvent("search_click")
}

fun logFilterClick() {
submitEvent("filter_click")
}

fun logFilterSelection(selection: String) {
submitEvent("filter_selection_" + selection)
}

fun logUndoTry() {
submitEvent("undo_try")
}

fun logUndoCancel() {
submitEvent("undo_cancel")
}

fun logUndoSuccess() {
submitEvent("undo_success")
}

fun logUndoFail() {
submitEvent("undo_fail")
}

fun logOlderEditChevronClick() {
submitEvent("older_edit_click")
}

fun logNewerEditChevronClick() {
submitEvent("newer_edit_click")
}

fun logShareClick() {
submitEvent("share_click")
}

fun logWatchClick() {
submitEvent("watch_click")
}

fun logUnwatchClick() {
submitEvent("unwatch_click")
}

private fun submitEvent(action: String) {
submitEvent(
"edit_history_interaction",
mapOf(
"action" to action,
"time_spent_ms" to timer.elapsedMillis
),
pageData
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package org.wikipedia.analytics.metricsplatform

class InstallReferrerEvent(
private val referrerUrl: String,
private val campaignId: String,
private val utfMedium: String,
private val utfCampaign: String,
private val utfSource: String
) {

companion object : MetricsEvent() {
const val PARAM_REFERRER_URL = "referrer_url"
const val PARAM_UTM_MEDIUM = "utm_medium"
const val PARAM_UTM_CAMPAIGN = "utm_campaign"
const val PARAM_UTM_SOURCE = "utm_source"
const val PARAM_CHANNEL = "channel"

fun logInstall(referrerUrl: String?, utfMedium: String?, utfCampaign: String?, utfSource: String?) {
submitEvent(
"install_referrer_event",
mapOf(
"referrer_url" to referrerUrl.orEmpty(),
"utm_medium" to utfMedium.toString(),
"utm_campaign" to utfCampaign.toString(),
"utm_source" to utfSource.toString(),
"campaign_id" to "android"
)
)
}
}
}
Loading