Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/offline
Browse files Browse the repository at this point in the history
  • Loading branch information
PavloNetrebchuk committed Jul 9, 2024
2 parents 8019d86 + 6efdd76 commit 4263dc9
Show file tree
Hide file tree
Showing 39 changed files with 348 additions and 66 deletions.
16 changes: 16 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ 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'
apply plugin: 'fullstory'

if (firebaseEnabled) {
apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
Expand All @@ -25,6 +29,18 @@ 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
12 changes: 12 additions & 0 deletions app/src/main/java/org/openedx/app/AnalyticsManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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
Expand All @@ -29,10 +30,15 @@ class AnalyticsManager(
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) {
Expand All @@ -45,6 +51,12 @@ class AnalyticsManager(
}
}

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

override fun logEvent(event: String, params: Map<String, Any?>) {
services.forEach { analytics ->
analytics.logEvent(event, params)
Expand Down
39 changes: 18 additions & 21 deletions app/src/main/java/org/openedx/app/AppActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,20 @@ class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder {

private var _windowSize = WindowSize(WindowType.Compact, WindowType.Compact)

private val branchCallback =
BranchUniversalReferralInitListener { branchUniversalObject, _, error ->
if (branchUniversalObject?.contentMetadata?.customMetadata != null) {
branchLogger.i { "Branch init complete." }
branchLogger.i { branchUniversalObject.contentMetadata.customMetadata.toString() }
viewModel.makeExternalRoute(
fm = supportFragmentManager,
deepLink = DeepLink(branchUniversalObject.contentMetadata.customMetadata)
)
} else if (error != null) {
branchLogger.e { "Branch init failed. Caused by -" + error.message }
}
}

override fun onSaveInstanceState(outState: Bundle) {
outState.putInt(TOP_INSET, topInset)
outState.putInt(BOTTOM_INSET, bottomInset)
Expand Down Expand Up @@ -165,21 +179,8 @@ class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder {
super.onStart()

if (viewModel.isBranchEnabled) {
val callback = BranchUniversalReferralInitListener { branchUniversalObject, _, error ->
if (branchUniversalObject?.contentMetadata?.customMetadata != null) {
branchLogger.i { "Branch init complete." }
branchLogger.i { branchUniversalObject.contentMetadata.customMetadata.toString() }
viewModel.makeExternalRoute(
fm = supportFragmentManager,
deepLink = DeepLink(branchUniversalObject.contentMetadata.customMetadata)
)
} else if (error != null) {
branchLogger.e { "Branch init failed. Caused by -" + error.message }
}
}

Branch.sessionBuilder(this)
.withCallback(callback)
.withCallback(branchCallback)
.withData(this.intent.data)
.init()
}
Expand All @@ -196,13 +197,9 @@ class AppActivity : AppCompatActivity(), InsetHolder, WindowSizeHolder {

if (viewModel.isBranchEnabled) {
if (intent?.getBooleanExtra(BRANCH_FORCE_NEW_SESSION, false) == true) {
Branch.sessionBuilder(this).withCallback { referringParams, error ->
if (error != null) {
branchLogger.e { error.message }
} else if (referringParams != null) {
branchLogger.i { referringParams.toString() }
}
}.reInit()
Branch.sessionBuilder(this)
.withCallback(branchCallback)
.reInit()
}
}
}
Expand Down
9 changes: 1 addition & 8 deletions app/src/main/java/org/openedx/app/AppAnalytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ interface AppAnalytics {
fun logoutEvent(force: Boolean)
fun setUserIdForSession(userId: Long)
fun logEvent(event: String, params: Map<String, Any?>)
fun logScreenEvent(screenName: String, params: Map<String, Any?>)
}

enum class AppAnalyticsEvent(val eventName: String, val biValue: String) {
Expand All @@ -15,14 +16,6 @@ enum class AppAnalyticsEvent(val eventName: String, val biValue: String) {
"MainDashboard:Discover",
"edx.bi.app.main_dashboard.discover"
),
MY_COURSES(
"MainDashboard:My Courses",
"edx.bi.app.main_dashboard.my_course"
),
MY_PROGRAMS(
"MainDashboard:My Programs",
"edx.bi.app.main_dashboard.my_program"
),
PROFILE(
"MainDashboard:Profile",
"edx.bi.app.main_dashboard.profile"
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/org/openedx/app/MainFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class MainFragment : Fragment(R.layout.fragment_main) {
binding.bottomNavView.setOnItemSelectedListener {
when (it.itemId) {
R.id.fragmentLearn -> {
viewModel.logMyCoursesTabClickedEvent()
binding.viewPager.setCurrentItem(0, false)
}

Expand Down
15 changes: 6 additions & 9 deletions app/src/main/java/org/openedx/app/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,17 @@ class MainViewModel(
}

fun logDiscoveryTabClickedEvent() {
logEvent(AppAnalyticsEvent.DISCOVER)
}

fun logMyCoursesTabClickedEvent() {
logEvent(AppAnalyticsEvent.MY_COURSES)
logScreenEvent(AppAnalyticsEvent.DISCOVER)
}

fun logProfileTabClickedEvent() {
logEvent(AppAnalyticsEvent.PROFILE)
logScreenEvent(AppAnalyticsEvent.PROFILE)
}

private fun logEvent(event: AppAnalyticsEvent) {
analytics.logEvent(event.eventName,
buildMap {
private fun logScreenEvent(event: AppAnalyticsEvent) {
analytics.logScreenEvent(
screenName = event.eventName,
params = buildMap {
put(AppAnalyticsKey.NAME.key, event.biValue)
}
)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/org/openedx/app/OpenEdXApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ package org.openedx.app
import android.app.Application
import com.braze.Braze
import com.braze.configuration.BrazeConfig
import com.braze.ui.BrazeDeeplinkHandler
import com.google.firebase.FirebaseApp
import io.branch.referral.Branch
import org.koin.android.ext.android.inject
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
import org.openedx.app.deeplink.BranchBrazeDeeplinkHandler
import org.openedx.app.di.appModule
import org.openedx.app.di.networkingModule
import org.openedx.app.di.screenModule
Expand Down Expand Up @@ -36,6 +38,7 @@ class OpenEdXApp : Application() {
Branch.enableTestMode()
Branch.enableLogging()
}
Branch.expectDelayedSessionInitialization(true)
Branch.getAutoInstance(this)
}

Expand All @@ -50,6 +53,10 @@ class OpenEdXApp : Application() {
.setIsFirebaseMessagingServiceOnNewTokenRegistrationEnabled(true)
.build()
Braze.configure(this, brazeConfig)

if (config.getBranchConfig().enabled) {
BrazeDeeplinkHandler.setBrazeDeeplinkHandler(BranchBrazeDeeplinkHandler())
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class FirebaseAnalytics(context: Context) : Analytics {
}

override fun logScreenEvent(screenName: String, params: Map<String, Any?>) {
tracker.logEvent(screenName, params.toBundle())
logger.d { "Firebase Analytics log Screen Event: $screenName + $params" }
}

Expand Down
41 changes: 41 additions & 0 deletions app/src/main/java/org/openedx/app/analytics/FullstoryAnalytics.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package org.openedx.app.analytics

import com.fullstory.FS
import com.fullstory.FSSessionData
import org.openedx.core.utils.Logger

class FullstoryAnalytics : Analytics {

private val logger = Logger(TAG)

init {
FS.setReadyListener { sessionData: FSSessionData ->
val sessionUrl = sessionData.currentSessionURL
logger.d { "FullStory Session URL is: $sessionUrl" }
}
}

override fun logScreenEvent(screenName: String, params: Map<String, Any?>) {
logger.d { "Page : $screenName $params" }
FS.page(screenName, params).start()
}

override fun logEvent(eventName: String, params: Map<String, Any?>) {
logger.d { "Event: $eventName $params" }
FS.page(eventName, params).start()
}

override fun logUserId(userId: Long) {
logger.d { "Identify: $userId" }
FS.identify(
userId.toString(), mapOf(
DISPLAY_NAME to userId
)
)
}

private companion object {
const val TAG = "FullstoryAnalytics"
private const val DISPLAY_NAME = "displayName"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.openedx.app.deeplink

import android.content.Context
import android.content.Intent
import android.net.Uri
import com.braze.ui.BrazeDeeplinkHandler
import com.braze.ui.actions.UriAction
import org.openedx.app.AppActivity

internal class BranchBrazeDeeplinkHandler : BrazeDeeplinkHandler() {
override fun gotoUri(context: Context, uriAction: UriAction) {
val deeplink = uriAction.uri.toString()

if (deeplink.contains("app.link")) {
val intent = Intent(context, AppActivity::class.java).apply {
action = Intent.ACTION_VIEW
data = Uri.parse(deeplink)
flags = Intent.FLAG_ACTIVITY_NEW_TASK
putExtra("branch_force_new_session", true)
}
context.startActivity(intent)
} else {
super.gotoUri(context, uriAction)
}
}
}
2 changes: 1 addition & 1 deletion app/src/main/java/org/openedx/app/di/ScreenModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ val screenModule = module {
)
}
viewModel { AllEnrolledCoursesViewModel(get(), get(), get(), get(), get(), get(), get()) }
viewModel { LearnViewModel(get(), get()) }
viewModel { LearnViewModel(get(), get(), get()) }

factory { DiscoveryRepository(get(), get(), get()) }
factory { DiscoveryInteractor(get()) }
Expand Down
13 changes: 13 additions & 0 deletions auth/src/main/java/org/openedx/auth/presentation/AuthAnalytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,14 @@ package org.openedx.auth.presentation
interface AuthAnalytics {
fun setUserIdForSession(userId: Long)
fun logEvent(event: String, params: Map<String, Any?>)
fun logScreenEvent(screenName: String, params: Map<String, Any?>)
}

enum class AuthAnalyticsEvent(val eventName: String, val biValue: String) {
Logistration(
"Logistration",
"edx.bi.app.logistration"
),
DISCOVERY_COURSES_SEARCH(
"Logistration:Courses Search",
"edx.bi.app.logistration.courses_search"
Expand All @@ -14,6 +19,14 @@ enum class AuthAnalyticsEvent(val eventName: String, val biValue: String) {
"Logistration:Explore All Courses",
"edx.bi.app.logistration.explore.all.courses"
),
SIGN_IN(
"Logistration:Sign In",
"edx.bi.app.logistration.signin"
),
REGISTER(
"Logistration:Register",
"edx.bi.app.logistration.register"
),
REGISTER_CLICKED(
"Logistration:Register Clicked",
"edx.bi.app.logistration.register.clicked"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class LogistrationViewModel(

private val discoveryTypeWebView get() = config.getDiscoveryConfig().isViewTypeWebView()

init {
logLogistrationScreenEvent()
}

fun navigateToSignIn(parentFragmentManager: FragmentManager) {
router.navigateToSignIn(parentFragmentManager, courseId, null)
logEvent(AuthAnalyticsEvent.SIGN_IN_CLICKED)
Expand Down Expand Up @@ -62,4 +66,14 @@ class LogistrationViewModel(
}
)
}

private fun logLogistrationScreenEvent() {
val event = AuthAnalyticsEvent.Logistration
analytics.logScreenEvent(
screenName = event.eventName,
params = buildMap {
put(AuthAnalyticsKey.NAME.key, event.biValue)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class SignInViewModel(

init {
collectAppUpgradeEvent()
logSignInScreenEvent()
}

fun login(username: String, password: String) {
Expand Down Expand Up @@ -245,4 +246,14 @@ class SignInViewModel(
}
)
}

private fun logSignInScreenEvent() {
val event = AuthAnalyticsEvent.SIGN_IN
analytics.logScreenEvent(
screenName = event.eventName,
params = buildMap {
put(AuthAnalyticsKey.NAME.key, event.biValue)
}
)
}
}
Loading

0 comments on commit 4263dc9

Please sign in to comment.