Permalink
Browse files

Add analytics events for common user interactions

  • Loading branch information...
ianhanniballake committed Sep 30, 2018
1 parent 0f98c30 commit 8b57d0946d166b949c02fe59c94fd2f53487b882
@@ -36,6 +36,7 @@ import android.view.MenuItem
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.core.os.bundleOf
import androidx.core.view.isGone
import androidx.core.view.isVisible
import androidx.navigation.fragment.findNavController
@@ -122,8 +123,11 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
}
metadataView.setOnClickListener {
val context = requireContext()
coroutineScope.launch {
currentArtworkLiveData.value?.openArtworkInfo(requireContext())
FirebaseAnalytics.getInstance(context).logEvent("artwork_info_open", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to "art_detail"))
currentArtworkLiveData.value?.openArtworkInfo(context)
}
}
@@ -253,6 +257,17 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
if (id > 0) {
currentArtworkLiveData.value?.run {
GlobalScope.launch {
if (id == MuzeiArtSource.BUILTIN_COMMAND_ID_NEXT_ARTWORK) {
FirebaseAnalytics.getInstance(context).logEvent("next_artwork", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to "art_detail"))
} else {
FirebaseAnalytics.getInstance(context).logEvent(
FirebaseAnalytics.Event.SELECT_CONTENT, bundleOf(
FirebaseAnalytics.Param.ITEM_ID to id,
FirebaseAnalytics.Param.ITEM_NAME to menuItem.title,
FirebaseAnalytics.Param.ITEM_CATEGORY to "actions",
FirebaseAnalytics.Param.CONTENT_TYPE to "art_detail"))
}
sendAction(context, id)
}
}
@@ -276,6 +291,8 @@ class ArtDetailFragment : Fragment(), (Boolean) -> Unit {
nextButton = view.findViewById(R.id.next_button)
nextButton.setOnClickListener {
FirebaseAnalytics.getInstance(requireContext()).logEvent("next_artwork", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to "art_detail"))
ProviderManager.getInstance(requireContext()).nextArtwork()
showFakeLoading()
}
@@ -20,19 +20,24 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.support.v4.app.FragmentActivity
import androidx.core.os.bundleOf
import com.google.android.apps.muzei.room.MuzeiDatabase
import com.google.android.apps.muzei.room.openArtworkInfo
import com.google.android.apps.muzei.util.coroutineScope
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.experimental.launch
/**
* Open the Artwork Info associated with the current artwork
*/
class ArtworkInfoRedirectActivity : FragmentActivity() {
companion object {
fun getIntent(context: Context): Intent =
private const val EXTRA_FROM = "from"
fun getIntent(context: Context, from: String): Intent =
Intent(context, ArtworkInfoRedirectActivity::class.java).apply {
action = "com.google.android.apps.muzei.OPEN_ARTWORK_INFO"
putExtra(EXTRA_FROM, from)
}
}
@@ -42,7 +47,13 @@ class ArtworkInfoRedirectActivity : FragmentActivity() {
val artwork = MuzeiDatabase.getInstance(this@ArtworkInfoRedirectActivity)
.artworkDao()
.getCurrentArtwork()
artwork?.openArtworkInfo(this@ArtworkInfoRedirectActivity)
artwork?.run {
val from = intent?.getStringExtra(EXTRA_FROM) ?: "activity_shortcut"
FirebaseAnalytics.getInstance(this@ArtworkInfoRedirectActivity).logEvent(
"artwork_info_open", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to from))
openArtworkInfo(this@ArtworkInfoRedirectActivity)
}
finish()
}
}
@@ -208,12 +208,13 @@ class ChooseProviderFragment : Fragment() {
REQUEST_EXTENSION_SETUP -> {
val provider = startActivityProvider
if (resultCode == Activity.RESULT_OK && provider != null) {
FirebaseAnalytics.getInstance(requireContext()).logEvent(
FirebaseAnalytics.Event.SELECT_CONTENT, bundleOf(
FirebaseAnalytics.Param.ITEM_ID to provider,
FirebaseAnalytics.Param.CONTENT_TYPE to "providers"))
val context = requireContext()
GlobalScope.launch {
FirebaseAnalytics.getInstance(context).logEvent(
FirebaseAnalytics.Event.SELECT_CONTENT, bundleOf(
FirebaseAnalytics.Param.ITEM_ID to provider,
FirebaseAnalytics.Param.ITEM_CATEGORY to "providers",
FirebaseAnalytics.Param.CONTENT_TYPE to "after_setup"))
ProviderManager.select(context, provider)
}
}
@@ -269,7 +270,9 @@ class ChooseProviderFragment : Fragment() {
FirebaseAnalytics.getInstance(requireContext()).logEvent(
FirebaseAnalytics.Event.SELECT_CONTENT, bundleOf(
FirebaseAnalytics.Param.ITEM_ID to authority,
FirebaseAnalytics.Param.CONTENT_TYPE to "providers"))
FirebaseAnalytics.Param.ITEM_NAME to title,
FirebaseAnalytics.Param.ITEM_CATEGORY to "providers",
FirebaseAnalytics.Param.CONTENT_TYPE to "choose"))
val context = requireContext()
GlobalScope.launch {
ProviderManager.select(context, authority)
@@ -38,6 +38,7 @@ import android.view.GestureDetector
import android.view.MotionEvent
import android.view.SurfaceHolder
import android.view.ViewConfiguration
import androidx.core.os.bundleOf
import com.google.android.apps.muzei.featuredart.BuildConfig.FEATURED_ART_AUTHORITY
import com.google.android.apps.muzei.notifications.NotificationUpdater
import com.google.android.apps.muzei.render.ImageLoader
@@ -59,6 +60,7 @@ import com.google.android.apps.muzei.wallpaper.LockscreenObserver
import com.google.android.apps.muzei.wallpaper.WallpaperAnalytics
import com.google.android.apps.muzei.wearable.WearableController
import com.google.android.apps.muzei.widget.WidgetUpdater
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.Job
import kotlinx.coroutines.experimental.delay
@@ -304,16 +306,19 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {
val prefs = Prefs.getSharedPreferences(this@MuzeiWallpaperService)
val doubleTapValue = prefs.getString(Prefs.PREF_DOUBLE_TAP,
null) ?: Prefs.PREF_TAP_ACTION_TEMP
triggerTapAction(doubleTapValue)
triggerTapAction(doubleTapValue, "gesture_double_tap")
// Reset the flag
validDoubleTap = false
}
return super.onCommand(action, x, y, z, extras, resultRequested)
}
private fun triggerTapAction(action: String) {
private fun triggerTapAction(action: String, type: String) {
when (action) {
Prefs.PREF_TAP_ACTION_TEMP -> {
FirebaseAnalytics.getInstance(this@MuzeiWallpaperService).logEvent(
"temp_disable_effects", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to type))
// Temporarily toggle focused/blurred
queueEvent {
renderer.setIsBlurred(!renderer.isBlurred, false)
@@ -323,6 +328,9 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {
}
Prefs.PREF_TAP_ACTION_NEXT -> {
GlobalScope.launch {
FirebaseAnalytics.getInstance(this@MuzeiWallpaperService).logEvent(
"next_artwork", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to type))
SourceManager.nextArtwork(this@MuzeiWallpaperService)
}
}
@@ -332,7 +340,12 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {
.getInstance(this@MuzeiWallpaperService)
.artworkDao()
.getCurrentArtwork()
artwork?.openArtworkInfo(this@MuzeiWallpaperService)
artwork?.run {
FirebaseAnalytics.getInstance(this@MuzeiWallpaperService).logEvent(
"artwork_info_open", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to type))
openArtworkInfo(this@MuzeiWallpaperService)
}
}
}
}
@@ -353,7 +366,7 @@ class MuzeiWallpaperService : GLWallpaperService(), LifecycleOwner {
val threeFingerTapValue = prefs.getString(Prefs.PREF_THREE_FINGER_TAP,
null) ?: Prefs.PREF_TAP_ACTION_NONE
triggerTapAction(threeFingerTapValue)
triggerTapAction(threeFingerTapValue, "gesture_three_finger")
}
}
@@ -18,7 +18,9 @@ package com.google.android.apps.muzei
import android.app.Activity
import android.os.Bundle
import androidx.core.os.bundleOf
import com.google.android.apps.muzei.sources.SourceManager
import com.google.firebase.analytics.FirebaseAnalytics
import kotlinx.coroutines.experimental.GlobalScope
import kotlinx.coroutines.experimental.launch
@@ -29,6 +31,9 @@ class NextArtworkActivity : Activity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
GlobalScope.launch {
FirebaseAnalytics.getInstance(this@NextArtworkActivity).logEvent(
"next_artwork", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to "activity_shortcut"))
SourceManager.nextArtwork(this@NextArtworkActivity)
}
finish()
@@ -54,10 +54,11 @@ class PhotoSetAsTargetActivity : FragmentActivity() {
}
// If adding the artwork succeeded, select the single artwork provider
val bundle = bundleOf(FirebaseAnalytics.Param.ITEM_ID to
ComponentName(context, SingleArtProvider::class.java).flattenToShortString(),
FirebaseAnalytics.Param.CONTENT_TYPE to "providers")
FirebaseAnalytics.getInstance(context).logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundle)
FirebaseAnalytics.getInstance(context).logEvent(
FirebaseAnalytics.Event.SELECT_CONTENT, bundleOf(
FirebaseAnalytics.Param.ITEM_ID to SINGLE_AUTHORITY,
FirebaseAnalytics.Param.ITEM_CATEGORY to "providers",
FirebaseAnalytics.Param.CONTENT_TYPE to "set_as"))
ProviderManager.select(context, SINGLE_AUTHORITY)
startActivity(Intent.makeMainActivity(ComponentName(
context, MuzeiActivity::class.java))
@@ -31,12 +31,14 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import androidx.core.os.bundleOf
import androidx.core.widget.toast
import androidx.navigation.fragment.findNavController
import com.google.android.apps.muzei.room.Artwork
import com.google.android.apps.muzei.room.MuzeiDatabase
import com.google.android.apps.muzei.util.coroutineScope
import com.google.android.apps.muzei.util.observe
import com.google.firebase.analytics.FirebaseAnalytics
import com.squareup.picasso.Picasso
import kotlinx.coroutines.experimental.CoroutineScope
import kotlinx.coroutines.experimental.Dispatchers
@@ -122,6 +124,12 @@ class BrowseProviderFragment: Fragment() {
val context = it.context
coroutineScope.launch(Dispatchers.Main) {
withContext(Dispatchers.Default) {
FirebaseAnalytics.getInstance(context).logEvent(
FirebaseAnalytics.Event.SELECT_CONTENT, bundleOf(
FirebaseAnalytics.Param.ITEM_ID to artwork.id,
FirebaseAnalytics.Param.ITEM_NAME to artwork.title,
FirebaseAnalytics.Param.ITEM_CATEGORY to "artwork",
FirebaseAnalytics.Param.CONTENT_TYPE to "browse"))
MuzeiDatabase.getInstance(context).artworkDao()
.insert(artwork)
}
@@ -33,6 +33,7 @@ import android.support.v4.app.RemoteInput
import android.support.v4.content.ContextCompat
import android.util.Log
import androidx.core.content.edit
import androidx.core.os.bundleOf
import com.google.android.apps.muzei.ArtDetailOpenLiveData
import com.google.android.apps.muzei.ArtworkInfoRedirectActivity
import com.google.android.apps.muzei.render.ContentUriImageLoader
@@ -42,6 +43,7 @@ import com.google.android.apps.muzei.room.sendAction
import com.google.android.apps.muzei.sources.SourceManager
import com.google.android.apps.muzei.sources.allowsNextArtwork
import com.google.android.apps.muzei.util.goAsync
import com.google.firebase.analytics.FirebaseAnalytics
import net.nurik.roman.muzei.R
class NewWallpaperNotificationReceiver : BroadcastReceiver() {
@@ -205,7 +207,7 @@ class NewWallpaperNotificationReceiver : BroadcastReceiver() {
.build())
}
val viewPendingIntent = PendingIntent.getActivity(context, 0,
ArtworkInfoRedirectActivity.getIntent(context),
ArtworkInfoRedirectActivity.getIntent(context, "notification"),
PendingIntent.FLAG_UPDATE_CURRENT)
val viewAction = NotificationCompat.Action.Builder(
R.drawable.ic_notif_info,
@@ -304,7 +306,12 @@ class NewWallpaperNotificationReceiver : BroadcastReceiver() {
goAsync {
when (intent?.action) {
ACTION_MARK_NOTIFICATION_READ -> markNotificationRead(context)
ACTION_NEXT_ARTWORK -> SourceManager.nextArtwork(context)
ACTION_NEXT_ARTWORK -> {
FirebaseAnalytics.getInstance(context).logEvent(
"next_artwork", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to "notification"))
SourceManager.nextArtwork(context)
}
ACTION_USER_COMMAND -> triggerUserCommandFromRemoteInput(context, intent)
}
}
@@ -319,6 +326,12 @@ class NewWallpaperNotificationReceiver : BroadcastReceiver() {
if (artwork != null) {
val commands = artwork.getCommands(context)
commands.find { selectedCommand == it.title }?.run {
FirebaseAnalytics.getInstance(context).logEvent(
FirebaseAnalytics.Event.SELECT_CONTENT, bundleOf(
FirebaseAnalytics.Param.ITEM_ID to id,
FirebaseAnalytics.Param.ITEM_NAME to title,
FirebaseAnalytics.Param.ITEM_CATEGORY to "actions",
FirebaseAnalytics.Param.CONTENT_TYPE to "notification"))
artwork.sendAction(context, id)
}
}
@@ -30,6 +30,7 @@ import android.service.quicksettings.Tile
import android.service.quicksettings.TileService
import android.support.annotation.RequiresApi
import android.widget.Toast
import androidx.core.os.bundleOf
import androidx.core.widget.toast
import com.google.android.apps.muzei.MuzeiWallpaperService
import com.google.android.apps.muzei.room.MuzeiDatabase
@@ -108,9 +109,10 @@ class NextArtworkTileService : TileService(), LifecycleOwner {
qsTile?.run {
when (state) {
Tile.STATE_ACTIVE -> { // Active means we send the 'Next Artwork' command
FirebaseAnalytics.getInstance(context).logEvent(
"tile_next_artwork_click", null)
GlobalScope.launch {
FirebaseAnalytics.getInstance(context).logEvent(
"next_artwork", bundleOf(
FirebaseAnalytics.Param.CONTENT_TYPE to "tile"))
SourceManager.nextArtwork(context)
}
}
@@ -71,7 +71,7 @@ class ArtworkInfoShortcutController(
.setIcon(Icon.createWithResource(context,
R.drawable.ic_shortcut_artwork_info))
.setShortLabel(context.getString(R.string.action_artwork_info))
.setIntent(ArtworkInfoRedirectActivity.getIntent(context))
.setIntent(ArtworkInfoRedirectActivity.getIntent(context, "shortcut"))
.build()
shortcutManager.addDynamicShortcuts(
listOf(shortcutInfo))
@@ -213,7 +213,9 @@ class SourceSettingsActivity : AppCompatActivity() {
} else {
FirebaseAnalytics.getInstance(this).logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundleOf(
FirebaseAnalytics.Param.ITEM_ID to source.componentName.flattenToShortString(),
FirebaseAnalytics.Param.CONTENT_TYPE to "sources"))
FirebaseAnalytics.Param.ITEM_NAME to source.label,
FirebaseAnalytics.Param.ITEM_CATEGORY to "sources",
FirebaseAnalytics.Param.CONTENT_TYPE to "choose"))
GlobalScope.launch {
SourceManager.selectSource(this@SourceSettingsActivity, source.componentName)
}
@@ -252,7 +254,8 @@ class SourceSettingsActivity : AppCompatActivity() {
if (resultCode == Activity.RESULT_OK && setupSource != null) {
FirebaseAnalytics.getInstance(this).logEvent(FirebaseAnalytics.Event.SELECT_CONTENT, bundleOf(
FirebaseAnalytics.Param.ITEM_ID to setupSource.flattenToShortString(),
FirebaseAnalytics.Param.CONTENT_TYPE to "sources"))
FirebaseAnalytics.Param.CONTENT_TYPE to "sources",
FirebaseAnalytics.Param.CONTENT_TYPE to "after_setup"))
GlobalScope.launch {
SourceManager.selectSource(this@SourceSettingsActivity, setupSource)
}
Oops, something went wrong.

0 comments on commit 8b57d09

Please sign in to comment.