forked from quran/quran_android
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Track analytics for a few important events (quran#1472)
- Loading branch information
Showing
19 changed files
with
273 additions
and
16 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
2 changes: 1 addition & 1 deletion
2
...ran/labs/androidquran/BaseActivityTest.kt → ...abs/androidquran/base/BaseActivityTest.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
18 changes: 18 additions & 0 deletions
18
app/src/androidTest/java/com/quran/labs/androidquran/base/TestApplication.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,18 @@ | ||
package com.quran.labs.androidquran.base | ||
|
||
import com.quran.labs.androidquran.QuranApplication | ||
import com.quran.labs.androidquran.di.DaggerTestApplicationComponent | ||
import com.quran.labs.androidquran.di.component.application.ApplicationComponent | ||
import com.quran.labs.androidquran.di.module.application.ApplicationModule | ||
|
||
class TestApplication : QuranApplication() { | ||
|
||
override fun initializeInjector(): ApplicationComponent { | ||
return DaggerTestApplicationComponent.builder() | ||
.applicationModule(ApplicationModule(this)) | ||
.build() | ||
} | ||
|
||
override fun setupTimber() { | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/androidTest/java/com/quran/labs/androidquran/core/QuranTestRunner.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,17 @@ | ||
package com.quran.labs.androidquran.core | ||
|
||
import android.app.Application | ||
import android.content.Context | ||
import androidx.test.runner.AndroidJUnitRunner | ||
import com.quran.labs.androidquran.base.TestApplication | ||
|
||
class QuranTestRunner : AndroidJUnitRunner() { | ||
|
||
override fun newApplication( | ||
cl: ClassLoader?, | ||
className: String?, | ||
context: Context? | ||
): Application { | ||
return super.newApplication(cl, TestApplication::class.qualifiedName, context) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/androidTest/java/com/quran/labs/androidquran/di/TestApplicationComponent.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,29 @@ | ||
package com.quran.labs.androidquran.di | ||
|
||
import com.quran.analytics.provider.AnalyticsModule | ||
import com.quran.common.networking.NetworkModule | ||
import com.quran.data.page.provider.QuranPageModule | ||
import com.quran.labs.androidquran.core.worker.di.WorkerModule | ||
import com.quran.labs.androidquran.data.QuranDataModule | ||
import com.quran.labs.androidquran.di.component.application.ApplicationComponent | ||
import com.quran.labs.androidquran.di.module.application.ApplicationModule | ||
import com.quran.labs.androidquran.di.module.application.DatabaseModule | ||
import com.quran.labs.androidquran.di.module.widgets.BookmarksWidgetUpdaterModule | ||
import com.quran.labs.androidquran.di.quran.TestQuranActivityComponent | ||
import dagger.Component | ||
import javax.inject.Singleton | ||
|
||
@Singleton | ||
@Component( | ||
modules = [AnalyticsModule::class, | ||
ApplicationModule::class, | ||
DatabaseModule::class, | ||
NetworkModule::class, | ||
QuranDataModule::class, | ||
QuranPageModule::class, | ||
WorkerModule::class, | ||
BookmarksWidgetUpdaterModule::class] | ||
) | ||
interface TestApplicationComponent : ApplicationComponent { | ||
override fun quranActivityComponentBuilder(): TestQuranActivityComponent.Builder | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/androidTest/java/com/quran/labs/androidquran/di/quran/TestQuranActivityComponent.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,15 @@ | ||
package com.quran.labs.androidquran.di.quran | ||
|
||
import com.quran.labs.androidquran.di.ActivityScope | ||
import com.quran.labs.androidquran.di.component.activity.QuranActivityComponent | ||
import dagger.Subcomponent | ||
|
||
@ActivityScope | ||
@Subcomponent(modules = [TestQuranActivityModule::class]) | ||
interface TestQuranActivityComponent : QuranActivityComponent { | ||
|
||
@Subcomponent.Builder | ||
interface Builder : QuranActivityComponent.Builder { | ||
override fun build(): TestQuranActivityComponent | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
app/src/androidTest/java/com/quran/labs/androidquran/di/quran/TestQuranActivityModule.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 com.quran.labs.androidquran.di.quran | ||
|
||
import com.quran.labs.androidquran.presenter.data.QuranIndexEventLogger | ||
import dagger.Module | ||
import dagger.Provides | ||
|
||
@Module | ||
class TestQuranActivityModule { | ||
|
||
@Provides | ||
fun bindQuranIndexEventLogger(): QuranIndexEventLogger { | ||
return QuranIndexEventLogger { } | ||
} | ||
} |
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
17 changes: 17 additions & 0 deletions
17
...c/main/java/com/quran/labs/androidquran/di/component/activity/QuranActivityComponent.java
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,17 @@ | ||
package com.quran.labs.androidquran.di.component.activity; | ||
|
||
import com.quran.labs.androidquran.di.ActivityScope; | ||
import com.quran.labs.androidquran.di.module.activity.QuranActivityModule; | ||
import com.quran.labs.androidquran.ui.QuranActivity; | ||
import dagger.Subcomponent; | ||
|
||
@ActivityScope | ||
@Subcomponent(modules = QuranActivityModule.class) | ||
public interface QuranActivityComponent { | ||
void inject(QuranActivity quranActivity); | ||
|
||
@Subcomponent.Builder | ||
interface Builder { | ||
QuranActivityComponent build(); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
app/src/main/java/com/quran/labs/androidquran/di/module/activity/QuranActivityModule.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,12 @@ | ||
package com.quran.labs.androidquran.di.module.activity | ||
|
||
import com.quran.labs.androidquran.presenter.data.QuranIndexEventLogger | ||
import com.quran.labs.androidquran.presenter.data.QuranIndexEventLoggerImpl | ||
import dagger.Binds | ||
import dagger.Module | ||
|
||
@Module | ||
interface QuranActivityModule { | ||
@Binds | ||
fun bindQuranIndexEventLogger(impl: QuranIndexEventLoggerImpl): QuranIndexEventLogger | ||
} |
77 changes: 77 additions & 0 deletions
77
app/src/main/java/com/quran/labs/androidquran/presenter/data/QuranEventLogger.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,77 @@ | ||
package com.quran.labs.androidquran.presenter.data | ||
|
||
import com.quran.analytics.AnalyticsProvider | ||
import com.quran.labs.androidquran.common.audio.QariItem | ||
import com.quran.labs.androidquran.presenter.data.QuranEventLogger.AudioPlaybackSource.PAGE | ||
import com.quran.labs.androidquran.util.QuranSettings | ||
import dagger.Reusable | ||
import javax.inject.Inject | ||
|
||
@Reusable | ||
class QuranEventLogger @Inject constructor( | ||
private val analyticsProvider: AnalyticsProvider, | ||
private val quranSettings: QuranSettings | ||
) { | ||
|
||
fun logAnalytics(isDualPages: Boolean, showingTranslations: Boolean, isSplitScreen: Boolean) { | ||
val isLockOrientation = quranSettings.isLockOrientation | ||
val lockingOrientation = when { | ||
isLockOrientation && quranSettings.isLandscapeOrientation -> "landscape" | ||
isLockOrientation -> "portrait" | ||
else -> "no" | ||
} | ||
|
||
val params : Map<String, Any> = mapOf( | ||
"mode" to getScreenMode(isDualPages, showingTranslations, isSplitScreen), | ||
"pageType" to quranSettings.pageType, | ||
"isNightMode" to quranSettings.isNightMode, | ||
"isArabic" to quranSettings.isArabicNames, | ||
"background" to if (quranSettings.useNewBackground()) "default" else "legacy", | ||
"isLockingOrientation" to lockingOrientation, | ||
"overlayInfo" to quranSettings.shouldOverlayPageInfo(), | ||
"markerPopups" to quranSettings.shouldDisplayMarkerPopup(), | ||
"navigation" to if (quranSettings.navigateWithVolumeKeys()) "with_volume" else "default", | ||
"shouldHighlightBookmarks" to quranSettings.shouldHighlightBookmarks() | ||
) | ||
|
||
analyticsProvider.logEvent("quran_view", params) | ||
} | ||
|
||
fun logAudioPlayback( | ||
source: AudioPlaybackSource, | ||
qari: QariItem, | ||
isDualPages: Boolean, | ||
showingTranslations: Boolean, | ||
isSplitScreen: Boolean | ||
) { | ||
val params : Map<String, Any> = mapOf( | ||
"id" to qari.id, | ||
"path" to qari.path, | ||
"isGapless" to qari.isGapless, | ||
"source" to if (source == PAGE) { "page" } else { "ayah" }, | ||
"mode" to getScreenMode(isDualPages, showingTranslations, isSplitScreen) | ||
) | ||
analyticsProvider.logEvent("audio_playback", params) | ||
} | ||
|
||
fun switchToTranslationMode(translations: Int) { | ||
val params: Map<String, Any> = mutableMapOf("translations" to translations) | ||
analyticsProvider.logEvent("switch_to_translations", params) | ||
} | ||
|
||
private fun getScreenMode( | ||
isDualPages: Boolean, | ||
showingTranslations: Boolean, | ||
isSplitScreen: Boolean | ||
): String { | ||
return when { | ||
isDualPages && showingTranslations && isSplitScreen -> "split_quran_translation" | ||
isDualPages && showingTranslations -> "dual_translations" | ||
isDualPages -> "dual_quran" | ||
showingTranslations -> "translation" | ||
else -> "quran" | ||
} | ||
} | ||
|
||
enum class AudioPlaybackSource { PAGE, AYAH } | ||
} |
5 changes: 5 additions & 0 deletions
5
app/src/main/java/com/quran/labs/androidquran/presenter/data/QuranIndexEventLogger.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,5 @@ | ||
package com.quran.labs.androidquran.presenter.data | ||
|
||
fun interface QuranIndexEventLogger { | ||
fun logAnalytics() | ||
} |
28 changes: 28 additions & 0 deletions
28
app/src/main/java/com/quran/labs/androidquran/presenter/data/QuranIndexEventLoggerImpl.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,28 @@ | ||
package com.quran.labs.androidquran.presenter.data | ||
|
||
import com.quran.analytics.AnalyticsProvider | ||
import com.quran.labs.androidquran.util.QuranSettings | ||
import dagger.Reusable | ||
import javax.inject.Inject | ||
|
||
@Reusable | ||
class QuranIndexEventLoggerImpl @Inject constructor( | ||
private val analyticsProvider: AnalyticsProvider, | ||
private val quranSettings: QuranSettings | ||
): QuranIndexEventLogger { | ||
|
||
override fun logAnalytics() { | ||
val appLocation = quranSettings.appCustomLocation | ||
val pathType = if ("com.quran" in appLocation) { "external" } else { "sdcard" } | ||
|
||
val params: Map<String, Any> = mapOf( | ||
"pathType" to pathType, | ||
"sortOrder" to quranSettings.bookmarksSortOrder, | ||
"groupByTags" to quranSettings.bookmarksGroupedByTags, | ||
"showRecents" to quranSettings.showRecents, | ||
"showDate" to quranSettings.showDate | ||
) | ||
|
||
analyticsProvider.logEvent("quran_index_view", params) | ||
} | ||
} |
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.