Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
omerhabib26 committed Sep 11, 2024
1 parent 23fa96d commit 7d927e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
6 changes: 2 additions & 4 deletions app/src/main/java/org/openedx/app/analytics/AnalyticsUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,14 @@ object AnalyticsUtils {
}.toBundle()
}

fun formatFirebaseAnalyticsDataForSegment(`object`: Any): Properties {
val properties = `object` as Properties
val newProperties = buildJsonObject {
fun formatFirebaseAnalyticsDataForSegment(properties: Properties): Properties {
return buildJsonObject {
for ((key, value) in properties) {
put(
makeFirebaseAnalyticsKey(key),
value.toString().take(100)
)
}
}
return newProperties
}
}
30 changes: 12 additions & 18 deletions app/src/main/java/org/openedx/app/analytics/SegmentAnalytics.kt
Original file line number Diff line number Diff line change
Expand Up @@ -31,30 +31,24 @@ class SegmentAnalytics(context: Context, config: Config) : Analytics {
if (config.getFirebaseConfig().isSegmentAnalyticsSource()) {
tracker.add(plugin = FirebaseDestination(context = context))

// Override the default event plugin to format the event and properties
// according to Firebase Analytics guidelines
tracker.find(FirebaseDestination::class)?.add(object : EventPlugin {
override lateinit var analytics: SegmentTracker
override val type = Plugin.Type.Before

override fun execute(event: BaseEvent): BaseEvent {
when (event) {
is ScreenEvent -> {
event.apply {
name = AnalyticsUtils.makeFirebaseAnalyticsKey(name)
}
}

is TrackEvent -> {
event.apply {
this.event = AnalyticsUtils.makeFirebaseAnalyticsKey(this.event)
properties = AnalyticsUtils.formatFirebaseAnalyticsDataForSegment(properties)
}
}
override fun track(payload: TrackEvent): BaseEvent {
return payload.apply {
this.event = AnalyticsUtils.makeFirebaseAnalyticsKey(this.event)
properties =
AnalyticsUtils.formatFirebaseAnalyticsDataForSegment(properties)
}
}

else -> {
//do nothing
}
override fun screen(payload: ScreenEvent): BaseEvent {
return payload.apply {
name = AnalyticsUtils.makeFirebaseAnalyticsKey(name)
}
return event
}
})
}
Expand Down

0 comments on commit 7d927e9

Please sign in to comment.