-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature-based analytics tracking, replace log with timber (#427)
* Replace log with timber * Replace log with timber * Replace log with timber * Replace log with timber * Fix linting * Add indent * Add matomo dependency * Introduce feature based tracking * Inject analytics tracker * Provide analytics instance with strings * Remove unused imports * Restructure folders * Track basic events * Track basic events: Resources, Settings screens * fix ktlint * fix ktlint --------- Co-authored-by: mdrlzy <mordeniusss@gmail.com>
- Loading branch information
Showing
29 changed files
with
434 additions
and
105 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
app/src/main/java/dev/arkbuilders/navigator/analytics/AnalyticsModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package dev.arkbuilders.navigator.analytics | ||
|
||
import android.content.Context | ||
import dagger.Module | ||
import dagger.Provides | ||
import dev.arkbuilders.navigator.analytics.folders.FoldersAnalytics | ||
import dev.arkbuilders.navigator.analytics.folders.FoldersAnalyticsImpl | ||
import dev.arkbuilders.navigator.analytics.gallery.GalleryAnalytics | ||
import dev.arkbuilders.navigator.analytics.gallery.GalleryAnalyticsImpl | ||
import dev.arkbuilders.navigator.analytics.resources.ResourcesAnalytics | ||
import dev.arkbuilders.navigator.analytics.resources.ResourcesAnalyticsImpl | ||
import dev.arkbuilders.navigator.analytics.settings.SettingsAnalytics | ||
import dev.arkbuilders.navigator.analytics.settings.SettingsAnalyticsImpl | ||
import org.matomo.sdk.Tracker | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
class AnalyticsModule { | ||
|
||
@Singleton | ||
@Provides | ||
fun provideFolderAnalytics( | ||
matomoTracker: Tracker, | ||
context: Context | ||
): FoldersAnalytics = | ||
FoldersAnalyticsImpl(matomoTracker = matomoTracker, context = context) | ||
|
||
@Singleton | ||
@Provides | ||
fun provideResourcesAnalytics( | ||
matomoTracker: Tracker | ||
): ResourcesAnalytics = ResourcesAnalyticsImpl(matomoTracker) | ||
|
||
@Singleton | ||
@Provides | ||
fun provideGalleryAnalytics( | ||
matomoTracker: Tracker, | ||
): GalleryAnalytics = GalleryAnalyticsImpl(matomoTracker) | ||
|
||
@Singleton | ||
@Provides | ||
fun provideSettingsAnalytics( | ||
matomoTracker: Tracker | ||
): SettingsAnalytics = SettingsAnalyticsImpl(matomoTracker) | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/dev/arkbuilders/navigator/analytics/Utils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package dev.arkbuilders.navigator.analytics | ||
|
||
import org.matomo.sdk.Tracker | ||
import org.matomo.sdk.extra.TrackHelper | ||
|
||
fun Tracker.trackScreen(build: TrackHelper.() -> TrackHelper.Screen) { | ||
val matomoTracker = this | ||
build(TrackHelper.track()).with(matomoTracker) | ||
} | ||
|
||
fun Tracker.trackEvent(build: TrackHelper.() -> TrackHelper.EventBuilder) { | ||
val matomoTracker = this | ||
build(TrackHelper.track()).with(matomoTracker) | ||
} |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/dev/arkbuilders/navigator/analytics/folders/FoldersAnalytics.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.arkbuilders.navigator.analytics.folders | ||
|
||
interface FoldersAnalytics { | ||
fun trackScreen() | ||
fun trackRootOpen() | ||
fun trackFavOpen() | ||
fun trackRootAdded() | ||
fun trackFavAdded() | ||
} |
32 changes: 32 additions & 0 deletions
32
app/src/main/java/dev/arkbuilders/navigator/analytics/folders/FoldersAnalyticsImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package dev.arkbuilders.navigator.analytics.folders | ||
|
||
import android.content.Context | ||
import dev.arkbuilders.navigator.analytics.trackEvent | ||
import dev.arkbuilders.navigator.analytics.trackScreen | ||
import org.matomo.sdk.Tracker | ||
import javax.inject.Inject | ||
|
||
class FoldersAnalyticsImpl @Inject constructor( | ||
private val matomoTracker: Tracker, | ||
private val context: Context | ||
) : FoldersAnalytics { | ||
|
||
override fun trackScreen() = matomoTracker | ||
.trackScreen { screen(SCREEN_NAME) } | ||
|
||
override fun trackRootOpen() = matomoTracker.trackScreenEvent("Root opened") | ||
|
||
override fun trackFavOpen() = matomoTracker.trackScreenEvent("Fav opened") | ||
|
||
override fun trackRootAdded() = matomoTracker.trackScreenEvent("Root added") | ||
|
||
override fun trackFavAdded() = matomoTracker.trackScreenEvent("Fav added") | ||
|
||
private fun Tracker.trackScreenEvent(action: String) = this.trackEvent { | ||
event(SCREEN_NAME, action) | ||
} | ||
|
||
companion object { | ||
private const val SCREEN_NAME = "Folders screen" | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
app/src/main/java/dev/arkbuilders/navigator/analytics/gallery/GalleryAnalytics.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.arkbuilders.navigator.analytics.gallery | ||
|
||
interface GalleryAnalytics { | ||
fun trackScreen() | ||
fun trackResOpen() | ||
fun trackResShare() | ||
fun trackResInfo() | ||
fun trackResEdit() | ||
fun trackResRemove() | ||
fun trackTagSelect() | ||
fun trackTagRemove() | ||
fun trackTagsEdit() | ||
} |
37 changes: 37 additions & 0 deletions
37
app/src/main/java/dev/arkbuilders/navigator/analytics/gallery/GalleryAnalyticsImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package dev.arkbuilders.navigator.analytics.gallery | ||
|
||
import dev.arkbuilders.navigator.analytics.trackEvent | ||
import dev.arkbuilders.navigator.analytics.trackScreen | ||
import org.matomo.sdk.Tracker | ||
|
||
class GalleryAnalyticsImpl( | ||
private val matomoTracker: Tracker | ||
) : GalleryAnalytics { | ||
override fun trackScreen() = matomoTracker.trackScreen { | ||
screen(SCREEN_NAME) | ||
} | ||
|
||
override fun trackResOpen() = matomoTracker.trackScreenEvent("Resource open") | ||
|
||
override fun trackResShare() = matomoTracker.trackScreenEvent("Resource share") | ||
|
||
override fun trackResInfo() = matomoTracker.trackScreenEvent("Resource info") | ||
|
||
override fun trackResEdit() = matomoTracker.trackScreenEvent("Resource edit") | ||
|
||
override fun trackResRemove() = matomoTracker.trackScreenEvent("Resource remove") | ||
|
||
override fun trackTagSelect() = matomoTracker.trackScreenEvent("Tag select") | ||
|
||
override fun trackTagRemove() = matomoTracker.trackScreenEvent("Tag remove") | ||
|
||
override fun trackTagsEdit() = matomoTracker.trackScreenEvent("Tags edit") | ||
|
||
private fun Tracker.trackScreenEvent(action: String) = this.trackEvent { | ||
event(SCREEN_NAME, action) | ||
} | ||
|
||
companion object { | ||
private const val SCREEN_NAME = "Gallery screen" | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/dev/arkbuilders/navigator/analytics/resources/ResourcesAnalytics.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.arkbuilders.navigator.analytics.resources | ||
|
||
import dev.arkbuilders.arklib.data.storage.StorageException | ||
import dev.arkbuilders.components.tagselector.QueryMode | ||
import dev.arkbuilders.components.tagselector.TagsSorting | ||
import dev.arkbuilders.navigator.data.utils.Sorting | ||
|
||
interface ResourcesAnalytics { | ||
fun trackScreen() | ||
fun trackResClick() | ||
fun trackMoveSelectedRes() | ||
fun trackCopySelectedRes() | ||
fun trackRemoveSelectedRes() | ||
fun trackShareSelectedRes() | ||
fun trackResShuffle() | ||
fun trackTagSortCriteria(tagsSorting: TagsSorting) | ||
fun trackResSortCriteria(sorting: Sorting) | ||
fun trackQueryModeChanged(queryMode: QueryMode) | ||
fun trackStorageProvideException(exception: StorageException) | ||
} |
59 changes: 59 additions & 0 deletions
59
app/src/main/java/dev/arkbuilders/navigator/analytics/resources/ResourcesAnalyticsImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
package dev.arkbuilders.navigator.analytics.resources | ||
|
||
import dev.arkbuilders.arklib.data.storage.StorageException | ||
import dev.arkbuilders.components.tagselector.QueryMode | ||
import dev.arkbuilders.components.tagselector.TagsSorting | ||
import dev.arkbuilders.navigator.analytics.trackEvent | ||
import dev.arkbuilders.navigator.analytics.trackScreen | ||
import dev.arkbuilders.navigator.data.utils.Sorting | ||
import org.matomo.sdk.Tracker | ||
import org.matomo.sdk.extra.TrackHelper | ||
|
||
class ResourcesAnalyticsImpl( | ||
private val matomoTracker: Tracker | ||
) : ResourcesAnalytics { | ||
override fun trackScreen() = matomoTracker.trackScreen { screen(SCREEN_NAME) } | ||
|
||
override fun trackResClick() = | ||
matomoTracker.trackScreenEvent("Resource Click") | ||
|
||
override fun trackMoveSelectedRes() = | ||
matomoTracker.trackScreenEvent("Move selected resources") | ||
|
||
override fun trackCopySelectedRes() = | ||
matomoTracker.trackScreenEvent("Copy selected resources") | ||
|
||
override fun trackRemoveSelectedRes() = | ||
matomoTracker.trackScreenEvent("Remove selected resources") | ||
|
||
override fun trackShareSelectedRes() = | ||
matomoTracker.trackScreenEvent("Share selected resources") | ||
|
||
override fun trackResShuffle() = | ||
matomoTracker.trackScreenEvent("Shuffle resources") | ||
|
||
override fun trackTagSortCriteria(tagsSorting: TagsSorting) = | ||
matomoTracker.trackScreenEvent("Tag sorting criteria: ${tagsSorting.name}") | ||
|
||
override fun trackResSortCriteria(sorting: Sorting) = | ||
matomoTracker.trackScreenEvent("Resources sorting criteria: ${sorting.name}") | ||
|
||
override fun trackQueryModeChanged(queryMode: QueryMode) = | ||
matomoTracker.trackScreenEvent("Query mode: ${queryMode.name}") | ||
|
||
override fun trackStorageProvideException(exception: StorageException) = | ||
TrackHelper | ||
.track() | ||
.exception(exception) | ||
.description("Storage provide") | ||
.fatal(false) | ||
.with(matomoTracker) | ||
|
||
private fun Tracker.trackScreenEvent(action: String) = this.trackEvent { | ||
event(SCREEN_NAME, action) | ||
} | ||
|
||
companion object { | ||
private const val SCREEN_NAME = "Resources screen" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/dev/arkbuilders/navigator/analytics/settings/SettingsAnalytics.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package dev.arkbuilders.navigator.analytics.settings | ||
|
||
interface SettingsAnalytics { | ||
fun trackScreen() | ||
fun trackBooleanPref(name: String, enabled: Boolean) | ||
} |
21 changes: 21 additions & 0 deletions
21
app/src/main/java/dev/arkbuilders/navigator/analytics/settings/SettingsAnalyticsImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package dev.arkbuilders.navigator.analytics.settings | ||
|
||
import dev.arkbuilders.navigator.analytics.trackEvent | ||
import dev.arkbuilders.navigator.analytics.trackScreen | ||
import org.matomo.sdk.Tracker | ||
|
||
class SettingsAnalyticsImpl( | ||
private val matomoTracker: Tracker | ||
) : SettingsAnalytics { | ||
override fun trackScreen() = matomoTracker.trackScreen { screen(SCREEN_NAME) } | ||
|
||
override fun trackBooleanPref(name: String, enabled: Boolean) { | ||
val enabledStr = if (enabled) "enabled" else "disabled" | ||
matomoTracker | ||
.trackEvent { event(SCREEN_NAME, "$name is $enabledStr") } | ||
} | ||
|
||
companion object { | ||
private const val SCREEN_NAME = "Settings screen" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.