Skip to content

Commit

Permalink
feat: foundation lib and analytic plugin implementation (openedx#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloNetrebchuk authored Nov 4, 2024
1 parent a005e85 commit e61523e
Show file tree
Hide file tree
Showing 216 changed files with 917 additions and 1,786 deletions.
2 changes: 0 additions & 2 deletions Documentation/ConfigurationManagement.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ TOKEN_TYPE: "JWT"

FIREBASE:
ENABLED: false
ANALYTICS_SOURCE: ''
CLOUD_MESSAGING_ENABLED: false
PROJECT_NUMBER: ''
PROJECT_ID: ''
Expand Down Expand Up @@ -82,7 +81,6 @@ android:
- **Facebook:** Sign in and Sign up via Facebook
- **Branch:** Deeplinks
- **Braze:** Cloud Messaging
- **SegmentIO:** Analytics

## Available Feature Flags
- **PRE_LOGIN_EXPERIENCE_ENABLED:** Enables the pre login courses discovery experience.
Expand Down
41 changes: 8 additions & 33 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,12 @@ def appId = config.getOrDefault("APPLICATION_ID", "org.openedx.app")
def themeDirectory = config.getOrDefault("THEME_DIRECTORY", "openedx")
def firebaseConfig = config.get('FIREBASE')
def firebaseEnabled = firebaseConfig?.getOrDefault('ENABLED', false)
def fullstoryConfig = config.get("FULLSTORY")
def fullstoryEnabled = fullstoryConfig?.getOrDefault('ENABLED', false)

apply plugin: 'com.android.application'
apply plugin: 'org.jetbrains.kotlin.android'
apply plugin: 'kotlin-parcelize'
apply plugin: 'kotlin-kapt'

if (fullstoryEnabled) {
apply plugin: 'fullstory'
}
apply plugin: 'com.google.devtools.ksp'
apply plugin: 'org.jetbrains.kotlin.plugin.compose'

if (firebaseEnabled) {
apply plugin: 'com.google.gms.google-services'
Expand All @@ -32,18 +27,6 @@ if (firebaseEnabled) {
preBuild.dependsOn(removeGoogleServicesJson)
}

if (fullstoryEnabled) {
def fullstoryOrgId = fullstoryConfig?.get("ORG_ID")

fullstory {
org fullstoryOrgId
composeEnabled true
composeSelectorVersion 4
enabledVariants 'debug|release'
logcatLevel 'error'
}
}

android {
compileSdk 34

Expand Down Expand Up @@ -117,9 +100,6 @@ android {
compose true
buildConfig true
}
composeOptions {
kotlinCompilerExtensionVersion = "$compose_compiler_version"
}
bundle {
language {
enableSplit = false
Expand All @@ -146,29 +126,24 @@ dependencies {
implementation project(path: ':discussion')
implementation project(path: ':whatsnew')

kapt "androidx.room:room-compiler:$room_version"
ksp "androidx.room:room-compiler:$room_version"

implementation 'androidx.core:core-splashscreen:1.0.1'

api platform("com.google.firebase:firebase-bom:$firebase_version")
api "com.google.firebase:firebase-messaging"

// Segment Library
implementation "com.segment.analytics.kotlin:android:1.14.2"
// Segment's Firebase integration
implementation 'com.segment.analytics.kotlin.destinations:firebase:1.5.2'
// Braze SDK Integration
implementation "com.braze:braze-segment-kotlin:1.4.2"
implementation "com.braze:android-sdk-ui:30.2.0"

androidTestImplementation 'androidx.test.ext:junit:1.1.5'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation "androidx.compose.ui:ui-test-junit4:$compose_version"
debugImplementation "androidx.compose.ui:ui-test-manifest:$compose_version"
// Plugins
implementation("com.github.openedx:openedx-app-firebase-analytics-android:1.0.0")

androidTestImplementation 'androidx.test.ext:junit:1.2.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
testImplementation "junit:junit:$junit_version"
testImplementation "io.mockk:mockk:$mockk_version"
testImplementation "io.mockk:mockk-android:$mockk_version"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
testImplementation "androidx.arch.core:core-testing:$android_arch_version"
}

Expand Down
2 changes: 0 additions & 2 deletions app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
-dontwarn com.google.crypto.tink.subtle.Ed25519Sign
-dontwarn com.google.crypto.tink.subtle.Ed25519Verify
-dontwarn com.google.crypto.tink.subtle.X25519
-dontwarn com.segment.analytics.kotlin.core.platform.plugins.logger.LogFilterKind
-dontwarn com.segment.analytics.kotlin.core.platform.plugins.logger.LogTargetKt
-dontwarn edu.umd.cs.findbugs.annotations.NonNull
-dontwarn edu.umd.cs.findbugs.annotations.Nullable
-dontwarn edu.umd.cs.findbugs.annotations.SuppressFBWarnings
Expand Down
46 changes: 11 additions & 35 deletions app/src/main/java/org/openedx/app/AnalyticsManager.kt
Original file line number Diff line number Diff line change
@@ -1,70 +1,46 @@
package org.openedx.app

import android.content.Context
import org.openedx.app.analytics.Analytics
import org.openedx.app.analytics.FirebaseAnalytics
import org.openedx.app.analytics.FullstoryAnalytics
import org.openedx.app.analytics.SegmentAnalytics
import org.openedx.auth.presentation.AuthAnalytics
import org.openedx.core.config.Config
import org.openedx.core.presentation.CoreAnalytics
import org.openedx.core.presentation.dialog.appreview.AppReviewAnalytics
import org.openedx.course.presentation.CourseAnalytics
import org.openedx.dashboard.presentation.DashboardAnalytics
import org.openedx.discovery.presentation.DiscoveryAnalytics
import org.openedx.discussion.presentation.DiscussionAnalytics
import org.openedx.foundation.interfaces.Analytics
import org.openedx.profile.presentation.ProfileAnalytics
import org.openedx.whatsnew.presentation.WhatsNewAnalytics

class AnalyticsManager(
context: Context,
config: Config,
) : AppAnalytics, AppReviewAnalytics, AuthAnalytics, CoreAnalytics, CourseAnalytics,
DashboardAnalytics, DiscoveryAnalytics, DiscussionAnalytics, ProfileAnalytics,
WhatsNewAnalytics {
class AnalyticsManager : AppAnalytics, AppReviewAnalytics, AuthAnalytics, CoreAnalytics,
CourseAnalytics, DashboardAnalytics, DiscoveryAnalytics, DiscussionAnalytics,
ProfileAnalytics, WhatsNewAnalytics {

private val services: ArrayList<Analytics> = arrayListOf()
private val analytics: MutableList<Analytics> = mutableListOf()

init {
// Initialise all the analytics libraries here
if (config.getFirebaseConfig().enabled) {
addAnalyticsTracker(FirebaseAnalytics(context = context))
}

val segmentConfig = config.getSegmentConfig()
if (segmentConfig.enabled && segmentConfig.segmentWriteKey.isNotBlank()) {
addAnalyticsTracker(SegmentAnalytics(context = context, config = config))
}

if (config.getFullstoryConfig().isEnabled) {
addAnalyticsTracker(FullstoryAnalytics())
}
}

private fun addAnalyticsTracker(analytic: Analytics) {
services.add(analytic)
fun addAnalyticsTracker(analytic: Analytics) {
analytics.add(analytic)
}

private fun logEvent(event: Event, params: Map<String, Any?> = mapOf()) {
services.forEach { analytics ->
analytics.forEach { analytics ->
analytics.logEvent(event.eventName, params)
}
}

override fun logScreenEvent(screenName: String, params: Map<String, Any?>) {
services.forEach { analytics ->
analytics.forEach { analytics ->
analytics.logScreenEvent(screenName, params)
}
}

override fun logEvent(event: String, params: Map<String, Any?>) {
services.forEach { analytics ->
analytics.forEach { analytics ->
analytics.logEvent(event, params)
}
}

private fun setUserId(userId: Long) {
services.forEach { analytics ->
analytics.forEach { analytics ->
analytics.logUserId(userId)
}
}
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/openedx/app/AppActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ import org.openedx.app.deeplink.DeepLink
import org.openedx.auth.presentation.logistration.LogistrationFragment
import org.openedx.auth.presentation.signin.SignInFragment
import org.openedx.core.data.storage.CorePreferences
import org.openedx.core.extension.requestApplyInsetsWhenAttached
import org.openedx.core.presentation.global.InsetHolder
import org.openedx.core.presentation.global.WindowSizeHolder
import org.openedx.core.ui.WindowSize
import org.openedx.core.ui.WindowType
import org.openedx.core.utils.Logger
import org.openedx.core.worker.CalendarSyncScheduler
import org.openedx.course.presentation.download.DownloadDialogManager
import org.openedx.foundation.extension.requestApplyInsetsWhenAttached
import org.openedx.foundation.presentation.WindowSize
import org.openedx.foundation.presentation.WindowType
import org.openedx.profile.presentation.ProfileRouter
import org.openedx.whatsnew.WhatsNewManager
import org.openedx.whatsnew.presentation.whatsnew.WhatsNewFragment
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/java/org/openedx/app/AppViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import org.openedx.app.deeplink.DeepLink
import org.openedx.app.deeplink.DeepLinkRouter
import org.openedx.app.system.push.RefreshFirebaseTokenWorker
import org.openedx.app.system.push.SyncFirebaseTokenWorker
import org.openedx.core.BaseViewModel
import org.openedx.core.SingleEventLiveData
import org.openedx.core.config.Config
import org.openedx.core.data.model.User
import org.openedx.core.data.storage.CorePreferences
Expand All @@ -28,8 +26,10 @@ import org.openedx.core.system.notifier.DownloadNotifier
import org.openedx.core.system.notifier.app.AppNotifier
import org.openedx.core.system.notifier.app.LogoutEvent
import org.openedx.core.system.notifier.app.SignInEvent
import org.openedx.core.utils.FileUtil

import org.openedx.core.utils.Directories
import org.openedx.foundation.presentation.BaseViewModel
import org.openedx.foundation.presentation.SingleEventLiveData
import org.openedx.foundation.utils.FileUtil

@SuppressLint("StaticFieldLeak")
class AppViewModel(
Expand Down Expand Up @@ -104,7 +104,7 @@ class AppViewModel(
}

private fun resetAppDirectory() {
fileUtil.deleteOldAppDirectory()
fileUtil.deleteOldAppDirectory(Directories.VIDEOS.name)
preferencesManager.canResetAppDirectory = false
}

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import org.openedx.core.BaseViewModel
import org.openedx.core.config.Config
import org.openedx.core.system.notifier.DiscoveryNotifier
import org.openedx.core.system.notifier.NavigationToDiscovery
import org.openedx.discovery.presentation.DiscoveryNavigator
import org.openedx.foundation.presentation.BaseViewModel

class MainViewModel(
private val config: Config,
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/java/org/openedx/app/OpenEdXApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import org.openedx.app.di.appModule
import org.openedx.app.di.networkingModule
import org.openedx.app.di.screenModule
import org.openedx.core.config.Config
import org.openedx.firebase.OEXFirebaseAnalytics

class OpenEdXApp : Application() {

private val config by inject<Config>()
private val pluginManager by inject<PluginManager>()

override fun onCreate() {
super.onCreate()
Expand Down Expand Up @@ -58,5 +60,13 @@ class OpenEdXApp : Application() {
BrazeDeeplinkHandler.setBrazeDeeplinkHandler(BranchBrazeDeeplinkHandler())
}
}

initPlugins()
}

private fun initPlugins() {
if (config.getFirebaseConfig().enabled) {
pluginManager.addPlugin(OEXFirebaseAnalytics(context = this))
}
}
}
12 changes: 12 additions & 0 deletions app/src/main/java/org/openedx/app/PluginManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.openedx.app

import org.openedx.foundation.interfaces.Analytics

class PluginManager(
private val analyticsManager: AnalyticsManager
) {

fun addPlugin(analytics: Analytics) {
analyticsManager.addAnalyticsTracker(analytics)
}
}
7 changes: 0 additions & 7 deletions app/src/main/java/org/openedx/app/analytics/Analytics.kt

This file was deleted.

36 changes: 0 additions & 36 deletions app/src/main/java/org/openedx/app/analytics/FirebaseAnalytics.kt

This file was deleted.

41 changes: 0 additions & 41 deletions app/src/main/java/org/openedx/app/analytics/FullstoryAnalytics.kt

This file was deleted.

Loading

0 comments on commit e61523e

Please sign in to comment.