diff --git a/app/build.gradle b/app/build.gradle index a0f268eb6..45b8abb92 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -106,6 +106,13 @@ dependencies { implementation 'androidx.core:core-splashscreen:1.0.1' + // 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" + 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" diff --git a/app/src/main/java/org/openedx/app/AnalyticsManager.kt b/app/src/main/java/org/openedx/app/AnalyticsManager.kt index 4f152677c..d2604ca1d 100644 --- a/app/src/main/java/org/openedx/app/AnalyticsManager.kt +++ b/app/src/main/java/org/openedx/app/AnalyticsManager.kt @@ -1,10 +1,9 @@ package org.openedx.app import android.content.Context -import android.os.Bundle -import androidx.core.os.bundleOf import org.openedx.app.analytics.Analytics import org.openedx.app.analytics.FirebaseAnalytics +import org.openedx.app.analytics.SegmentAnalytics import org.openedx.auth.presentation.AuthAnalytics import org.openedx.core.config.Config import org.openedx.course.presentation.CourseAnalytics @@ -16,23 +15,27 @@ import org.openedx.profile.presentation.ProfileAnalytics class AnalyticsManager( context: Context, config: Config, -) : DashboardAnalytics, AuthAnalytics, AppAnalytics, - DiscoveryAnalytics, ProfileAnalytics, CourseAnalytics, DiscussionAnalytics { +) : DashboardAnalytics, AuthAnalytics, AppAnalytics, DiscoveryAnalytics, ProfileAnalytics, + CourseAnalytics, DiscussionAnalytics { private val services: ArrayList = arrayListOf() init { // Initialise all the analytics libraries here - if (config.getFirebaseConfig().projectId.isNotEmpty()) { + if (config.getFirebaseConfig().projectId.isNotBlank()) { addAnalyticsTracker(FirebaseAnalytics(context = context)) } + val segmentConfig = config.getSegmentConfig() + if (segmentConfig.enabled && segmentConfig.segmentWriteKey.isNotBlank()) { + addAnalyticsTracker(SegmentAnalytics(context = context, config = config)) + } } private fun addAnalyticsTracker(analytic: Analytics) { services.add(analytic) } - private fun logEvent(event: Event, params: Bundle = bundleOf()) { + private fun logEvent(event: Event, params: Map = mapOf()) { services.forEach { analytics -> analytics.logEvent(event.eventName, params) } @@ -45,22 +48,16 @@ class AnalyticsManager( } override fun dashboardCourseClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.DASHBOARD_COURSE_CLICKED, - bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.DASHBOARD_COURSE_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun userLoginEvent(method: String) { - logEvent( - Event.USER_LOGIN, - bundleOf( - Key.METHOD.keyName to method - ) - ) + logEvent(Event.USER_LOGIN, buildMap { + put(Key.METHOD.keyName, method) + }) } override fun signUpClickedEvent() { @@ -68,17 +65,13 @@ class AnalyticsManager( } override fun createAccountClickedEvent(provider: String) { - logEvent( - Event.CREATE_ACCOUNT_CLICKED, - bundleOf(Key.PROVIDER.keyName to provider) - ) + logEvent(Event.CREATE_ACCOUNT_CLICKED, buildMap { + put(Key.PROVIDER.keyName, provider) + }) } override fun registrationSuccessEvent(provider: String) { - logEvent( - Event.REGISTRATION_SUCCESS, - bundleOf(Key.PROVIDER.keyName to provider) - ) + logEvent(Event.REGISTRATION_SUCCESS, buildMap { put(Key.PROVIDER.keyName, provider) }) } override fun forgotPasswordClickedEvent() { @@ -86,19 +79,13 @@ class AnalyticsManager( } override fun resetPasswordClickedEvent(success: Boolean) { - logEvent( - Event.RESET_PASSWORD_CLICKED, bundleOf( - Key.SUCCESS.keyName to success - ) - ) + logEvent(Event.RESET_PASSWORD_CLICKED, buildMap { put(Key.SUCCESS.keyName, success) }) } override fun logoutEvent(force: Boolean) { - logEvent( - Event.USER_LOGOUT, bundleOf( - Key.FORCE.keyName to force - ) - ) + logEvent(Event.USER_LOGOUT, buildMap { + put(Key.FORCE.keyName, force) + }) } override fun discoveryTabClickedEvent() { @@ -126,21 +113,17 @@ class AnalyticsManager( } override fun discoveryCourseSearchEvent(label: String, coursesCount: Int) { - logEvent( - Event.DISCOVERY_COURSE_SEARCH, bundleOf( - Key.LABEL.keyName to label, - Key.COURSE_COUNT.keyName to coursesCount - ) - ) + logEvent(Event.DISCOVERY_COURSE_SEARCH, buildMap { + put(Key.LABEL.keyName, label) + put(Key.COURSE_COUNT.keyName, coursesCount) + }) } override fun discoveryCourseClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.DISCOVERY_COURSE_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.DISCOVERY_COURSE_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun profileEditClickedEvent() { @@ -184,226 +167,166 @@ class AnalyticsManager( } override fun courseEnrollClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.COURSE_ENROLL_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - ) - ) + logEvent(Event.COURSE_ENROLL_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun courseEnrollSuccessEvent(courseId: String, courseName: String) { - logEvent( - Event.COURSE_ENROLL_SUCCESS, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - ) - ) + logEvent(Event.COURSE_ENROLL_SUCCESS, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun viewCourseClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.VIEW_COURSE_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - ) - ) + logEvent(Event.VIEW_COURSE_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun resumeCourseTappedEvent(courseId: String, courseName: String, blockId: String) { - logEvent( - Event.RESUME_COURSE_TAPPED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - Key.BLOCK_ID.keyName to blockId - ) - ) + logEvent(Event.RESUME_COURSE_TAPPED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + put(Key.BLOCK_ID.keyName, blockId) + }) } override fun sequentialClickedEvent( - courseId: String, - courseName: String, - blockId: String, - blockName: String + courseId: String, courseName: String, blockId: String, blockName: String ) { - logEvent( - Event.SEQUENTIAL_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - Key.BLOCK_ID.keyName to blockId, - Key.BLOCK_NAME.keyName to blockName, - ) - ) + logEvent(Event.SEQUENTIAL_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + put(Key.BLOCK_ID.keyName, blockId) + put(Key.BLOCK_NAME.keyName, blockName) + }) } override fun verticalClickedEvent( - courseId: String, - courseName: String, - blockId: String, - blockName: String + courseId: String, courseName: String, blockId: String, blockName: String ) { - logEvent( - Event.VERTICAL_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - Key.BLOCK_ID.keyName to blockId, - Key.BLOCK_NAME.keyName to blockName, - ) - ) + logEvent(Event.VERTICAL_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + put(Key.BLOCK_ID.keyName, blockId) + put(Key.BLOCK_NAME.keyName, blockName) + }) } override fun nextBlockClickedEvent( - courseId: String, - courseName: String, - blockId: String, - blockName: String + courseId: String, courseName: String, blockId: String, blockName: String ) { - logEvent( - Event.NEXT_BLOCK_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - Key.BLOCK_ID.keyName to blockId, - Key.BLOCK_NAME.keyName to blockName, - ) - ) + logEvent(Event.NEXT_BLOCK_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + put(Key.BLOCK_ID.keyName, blockId) + put(Key.BLOCK_NAME.keyName, blockName) + }) } override fun prevBlockClickedEvent( - courseId: String, - courseName: String, - blockId: String, - blockName: String + courseId: String, courseName: String, blockId: String, blockName: String ) { - logEvent( - Event.PREV_BLOCK_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - Key.BLOCK_ID.keyName to blockId, - Key.BLOCK_NAME.keyName to blockName, - ) - ) + logEvent(Event.PREV_BLOCK_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + put(Key.BLOCK_ID.keyName, blockId) + put(Key.BLOCK_NAME.keyName, blockName) + }) } override fun finishVerticalClickedEvent( - courseId: String, - courseName: String, - blockId: String, - blockName: String + courseId: String, courseName: String, blockId: String, blockName: String ) { - logEvent( - Event.FINISH_VERTICAL_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - Key.BLOCK_ID.keyName to blockId, - Key.BLOCK_NAME.keyName to blockName, - ) - ) + logEvent(Event.FINISH_VERTICAL_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + put(Key.BLOCK_ID.keyName, blockId) + put(Key.BLOCK_NAME.keyName, blockName) + }) } override fun finishVerticalNextClickedEvent( - courseId: String, - courseName: String, - blockId: String, - blockName: String + courseId: String, courseName: String, blockId: String, blockName: String ) { - logEvent( - Event.FINISH_VERTICAL_NEXT_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - Key.BLOCK_ID.keyName to blockId, - Key.BLOCK_NAME.keyName to blockName, - ) - ) + logEvent(Event.FINISH_VERTICAL_NEXT_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + put(Key.BLOCK_ID.keyName, blockId) + put(Key.BLOCK_NAME.keyName, blockName) + }) } override fun finishVerticalBackClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.FINISH_VERTICAL_BACK_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.FINISH_VERTICAL_BACK_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun courseTabClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.COURSE_TAB_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.COURSE_TAB_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun videoTabClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.VIDEO_TAB_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.VIDEO_TAB_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun discussionTabClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.DISCUSSION_TAB_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.DISCUSSION_TAB_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun datesTabClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.DATES_TAB_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.DATES_TAB_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun handoutsTabClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.HANDOUTS_TAB_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.HANDOUTS_TAB_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun discussionAllPostsClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.DISCUSSION_ALL_POSTS_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.DISCUSSION_ALL_POSTS_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun discussionFollowingClickedEvent(courseId: String, courseName: String) { - logEvent( - Event.DISCUSSION_FOLLOWING_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName - ) - ) + logEvent(Event.DISCUSSION_FOLLOWING_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + }) } override fun discussionTopicClickedEvent( - courseId: String, - courseName: String, - topicId: String, - topicName: String + courseId: String, courseName: String, topicId: String, topicName: String ) { - logEvent( - Event.DISCUSSION_TOPIC_CLICKED, bundleOf( - Key.COURSE_ID.keyName to courseId, - Key.COURSE_NAME.keyName to courseName, - Key.TOPIC_ID.keyName to topicId, - Key.TOPIC_NAME.keyName to topicName - ) - ) + logEvent(Event.DISCUSSION_TOPIC_CLICKED, buildMap { + put(Key.COURSE_ID.keyName, courseId) + put(Key.COURSE_NAME.keyName, courseName) + put(Key.TOPIC_ID.keyName, topicId) + put(Key.TOPIC_NAME.keyName, topicName) + }) } - } private enum class Event(val eventName: String) { diff --git a/app/src/main/java/org/openedx/app/analytics/Analytics.kt b/app/src/main/java/org/openedx/app/analytics/Analytics.kt index ed34ec41a..01ac01860 100644 --- a/app/src/main/java/org/openedx/app/analytics/Analytics.kt +++ b/app/src/main/java/org/openedx/app/analytics/Analytics.kt @@ -1,9 +1,7 @@ package org.openedx.app.analytics -import android.os.Bundle - interface Analytics { - fun logScreenEvent(screenName: String, bundle: Bundle) - fun logEvent(eventName: String, bundle: Bundle) + fun logScreenEvent(screenName: String, params: Map) + fun logEvent(eventName: String, params: Map) fun logUserId(userId: Long) } diff --git a/app/src/main/java/org/openedx/app/analytics/FirebaseAnalytics.kt b/app/src/main/java/org/openedx/app/analytics/FirebaseAnalytics.kt index 6e4db40a0..503f3d1ef 100644 --- a/app/src/main/java/org/openedx/app/analytics/FirebaseAnalytics.kt +++ b/app/src/main/java/org/openedx/app/analytics/FirebaseAnalytics.kt @@ -1,30 +1,35 @@ package org.openedx.app.analytics import android.content.Context -import android.os.Bundle -import android.util.Log import com.google.firebase.analytics.FirebaseAnalytics +import org.openedx.core.extension.toBundle +import org.openedx.core.utils.Logger class FirebaseAnalytics(context: Context) : Analytics { - private var tracker: FirebaseAnalytics? = null + private val logger = Logger(TAG) + private var tracker: FirebaseAnalytics init { tracker = FirebaseAnalytics.getInstance(context) - Log.d("Analytics", "Firebase Builder Initialised") + logger.d { "Firebase Analytics Builder Initialised" } } - override fun logScreenEvent(screenName: String, bundle: Bundle) { - Log.d("Analytics", "Firebase log Screen Event: $screenName + $bundle") + override fun logScreenEvent(screenName: String, params: Map) { + logger.d { "Firebase Analytics log Screen Event: $screenName + $params" } } - override fun logEvent(eventName: String, bundle: Bundle) { - tracker?.logEvent(eventName, bundle) - Log.d("Analytics", "Firebase log Event $eventName: $bundle") + override fun logEvent(eventName: String, params: Map) { + tracker.logEvent(eventName, params.toBundle()) + logger.d { "Firebase Analytics log Event $eventName: $params" } } override fun logUserId(userId: Long) { - tracker?.setUserId(userId.toString()) - Log.d("Analytics", "Firebase User Id log Event") + tracker.setUserId(userId.toString()) + logger.d { "Firebase Analytics User Id log Event" } + } + + private companion object { + const val TAG = "FirebaseAnalytics" } } diff --git a/app/src/main/java/org/openedx/app/analytics/SegmentAnalytics.kt b/app/src/main/java/org/openedx/app/analytics/SegmentAnalytics.kt new file mode 100644 index 000000000..3a9532a71 --- /dev/null +++ b/app/src/main/java/org/openedx/app/analytics/SegmentAnalytics.kt @@ -0,0 +1,56 @@ +package org.openedx.app.analytics + +import android.content.Context +import com.segment.analytics.kotlin.destinations.braze.BrazeDestination +import com.segment.analytics.kotlin.destinations.firebase.FirebaseDestination +import org.openedx.app.BuildConfig +import org.openedx.core.config.Config +import org.openedx.core.utils.Logger +import com.segment.analytics.kotlin.android.Analytics as SegmentAnalyticsBuilder +import com.segment.analytics.kotlin.core.Analytics as SegmentTracker + +class SegmentAnalytics(context: Context, config: Config) : Analytics { + + private val logger = Logger(TAG) + private var tracker: SegmentTracker + + init { + // Create an analytics client with the given application context and Segment write key. + tracker = SegmentAnalyticsBuilder(config.getSegmentConfig().segmentWriteKey, context) { + // Automatically track Lifecycle events + trackApplicationLifecycleEvents = true + flushAt = 20 + flushInterval = 30 + } + if (config.getFirebaseConfig().isSegmentAnalyticsSource()) { + tracker.add(plugin = FirebaseDestination(context = context)) + } + + if (config.getFirebaseConfig() + .isSegmentAnalyticsSource() && config.getBrazeConfig().isEnabled + ) { + tracker.add(plugin = BrazeDestination(context)) + } + SegmentTracker.debugLogsEnabled = BuildConfig.DEBUG + logger.d { "Segment Analytics Builder Initialised" } + } + + override fun logScreenEvent(screenName: String, params: Map) { + logger.d { "Segment Analytics log Screen Event: $screenName + $params" } + tracker.screen(screenName, params) + } + + override fun logEvent(eventName: String, params: Map) { + logger.d { "Segment Analytics log Event $eventName: $params" } + tracker.track(eventName, params) + } + + override fun logUserId(userId: Long) { + logger.d { "Segment Analytics User Id log Event: $userId" } + tracker.identify(userId.toString()) + } + + private companion object { + const val TAG = "SegmentAnalytics" + } +} diff --git a/core/src/main/java/org/openedx/core/config/AnalyticsSource.kt b/core/src/main/java/org/openedx/core/config/AnalyticsSource.kt new file mode 100644 index 000000000..b3ee82211 --- /dev/null +++ b/core/src/main/java/org/openedx/core/config/AnalyticsSource.kt @@ -0,0 +1,11 @@ +package org.openedx.core.config + +import com.google.gson.annotations.SerializedName + +enum class AnalyticsSource { + @SerializedName("segment") + SEGMENT, + + @SerializedName("none") + NONE, +} diff --git a/core/src/main/java/org/openedx/core/config/BrazeConfig.kt b/core/src/main/java/org/openedx/core/config/BrazeConfig.kt new file mode 100644 index 000000000..62bb2e9be --- /dev/null +++ b/core/src/main/java/org/openedx/core/config/BrazeConfig.kt @@ -0,0 +1,11 @@ +package org.openedx.core.config + +import com.google.gson.annotations.SerializedName + +data class BrazeConfig( + @SerializedName("ENABLED") + val isEnabled: Boolean = false, + + @SerializedName("PUSH_NOTIFICATIONS_ENABLED") + val isPushNotificationsEnabled: Boolean = false +) diff --git a/core/src/main/java/org/openedx/core/config/Config.kt b/core/src/main/java/org/openedx/core/config/Config.kt index 8739c4cfa..cc1f37269 100644 --- a/core/src/main/java/org/openedx/core/config/Config.kt +++ b/core/src/main/java/org/openedx/core/config/Config.kt @@ -57,6 +57,14 @@ class Config(context: Context) { return getObjectOrNewInstance(FIREBASE, FirebaseConfig::class.java) } + fun getSegmentConfig(): SegmentConfig { + return getObjectOrNewInstance(SEGMENT_IO, SegmentConfig::class.java) + } + + fun getBrazeConfig(): BrazeConfig { + return getObjectOrNewInstance(BRAZE, BrazeConfig::class.java) + } + fun getFacebookConfig(): FacebookConfig { return getObjectOrNewInstance(FACEBOOK, FacebookConfig::class.java) } @@ -148,6 +156,8 @@ class Config(context: Context) { private const val WHATS_NEW_ENABLED = "WHATS_NEW_ENABLED" private const val SOCIAL_AUTH_ENABLED = "SOCIAL_AUTH_ENABLED" private const val FIREBASE = "FIREBASE" + private const val SEGMENT_IO = "SEGMENT_IO" + private const val BRAZE = "BRAZE" private const val FACEBOOK = "FACEBOOK" private const val GOOGLE = "GOOGLE" private const val MICROSOFT = "MICROSOFT" diff --git a/core/src/main/java/org/openedx/core/config/FirebaseConfig.kt b/core/src/main/java/org/openedx/core/config/FirebaseConfig.kt index b003c3230..e659ef2ce 100644 --- a/core/src/main/java/org/openedx/core/config/FirebaseConfig.kt +++ b/core/src/main/java/org/openedx/core/config/FirebaseConfig.kt @@ -6,6 +6,9 @@ data class FirebaseConfig( @SerializedName("ENABLED") val enabled: Boolean = false, + @SerializedName("ANALYTICS_SOURCE") + val analyticsSource: AnalyticsSource = AnalyticsSource.NONE, + @SerializedName("PROJECT_ID") val projectId: String = "", @@ -17,4 +20,8 @@ data class FirebaseConfig( @SerializedName("GCM_SENDER_ID") val gcmSenderId: String = "", -) +) { + fun isSegmentAnalyticsSource(): Boolean { + return enabled && analyticsSource == AnalyticsSource.SEGMENT + } +} diff --git a/core/src/main/java/org/openedx/core/config/SegmentConfig.kt b/core/src/main/java/org/openedx/core/config/SegmentConfig.kt new file mode 100644 index 000000000..ffa43e8bc --- /dev/null +++ b/core/src/main/java/org/openedx/core/config/SegmentConfig.kt @@ -0,0 +1,11 @@ +package org.openedx.core.config + +import com.google.gson.annotations.SerializedName + +data class SegmentConfig( + @SerializedName("ENABLED") + val enabled: Boolean = false, + + @SerializedName("SEGMENT_IO_WRITE_KEY") + val segmentWriteKey: String = "", +) diff --git a/core/src/main/java/org/openedx/core/extension/MapExt.kt b/core/src/main/java/org/openedx/core/extension/MapExt.kt new file mode 100644 index 000000000..f985d119d --- /dev/null +++ b/core/src/main/java/org/openedx/core/extension/MapExt.kt @@ -0,0 +1,13 @@ +package org.openedx.core.extension + +import android.os.Bundle + +fun Map.toBundle(): Bundle { + val bundle = Bundle() + for ((key, value) in this.entries) { + value?.let { + bundle.putString(key, it.toString()) + } + } + return bundle +} diff --git a/default_config/dev/config.yaml b/default_config/dev/config.yaml index f074ddd9d..7de39893a 100644 --- a/default_config/dev/config.yaml +++ b/default_config/dev/config.yaml @@ -28,6 +28,23 @@ PROGRAM: PROGRAM_URL: '' PROGRAM_DETAIL_URL_TEMPLATE: '' +FIREBASE: + ENABLED: false + ANALYTICS_SOURCE: '' # segment | none + CLOUD_MESSAGING_ENABLED: false + PROJECT_ID: "" + APPLICATION_ID: "" + API_KEY: "" + GCM_SENDER_ID: "" + +SEGMENT_IO: + ENABLED: false + SEGMENT_IO_WRITE_KEY: '' + +BRAZE: + ENABLED: false + PUSH_NOTIFICATIONS_ENABLED: false + GOOGLE: ENABLED: false CLIENT_ID: '' diff --git a/default_config/prod/config.yaml b/default_config/prod/config.yaml index 25df957a0..ef70aeae7 100644 --- a/default_config/prod/config.yaml +++ b/default_config/prod/config.yaml @@ -28,6 +28,23 @@ PROGRAM: PROGRAM_URL: '' PROGRAM_DETAIL_URL_TEMPLATE: '' +FIREBASE: + ENABLED: false + ANALYTICS_SOURCE: '' # segment | none + CLOUD_MESSAGING_ENABLED: false + PROJECT_ID: "" + APPLICATION_ID: "" + API_KEY: "" + GCM_SENDER_ID: "" + +SEGMENT_IO: + ENABLED: false + SEGMENT_IO_WRITE_KEY: '' + +BRAZE: + ENABLED: false + PUSH_NOTIFICATIONS_ENABLED: false + GOOGLE: ENABLED: false CLIENT_ID: '' diff --git a/default_config/stage/config.yaml b/default_config/stage/config.yaml index 25df957a0..ef70aeae7 100644 --- a/default_config/stage/config.yaml +++ b/default_config/stage/config.yaml @@ -28,6 +28,23 @@ PROGRAM: PROGRAM_URL: '' PROGRAM_DETAIL_URL_TEMPLATE: '' +FIREBASE: + ENABLED: false + ANALYTICS_SOURCE: '' # segment | none + CLOUD_MESSAGING_ENABLED: false + PROJECT_ID: "" + APPLICATION_ID: "" + API_KEY: "" + GCM_SENDER_ID: "" + +SEGMENT_IO: + ENABLED: false + SEGMENT_IO_WRITE_KEY: '' + +BRAZE: + ENABLED: false + PUSH_NOTIFICATIONS_ENABLED: false + GOOGLE: ENABLED: false CLIENT_ID: ''