|
1 | 1 | package org.openedx.app |
2 | 2 |
|
3 | | -import android.content.Context |
4 | | -import org.openedx.app.analytics.Analytics |
5 | | -import org.openedx.app.analytics.FirebaseAnalytics |
6 | | -import org.openedx.app.analytics.FullstoryAnalytics |
7 | | -import org.openedx.app.analytics.SegmentAnalytics |
8 | 3 | import org.openedx.auth.presentation.AuthAnalytics |
9 | | -import org.openedx.core.config.Config |
10 | 4 | import org.openedx.core.presentation.CoreAnalytics |
11 | 5 | import org.openedx.core.presentation.dialog.appreview.AppReviewAnalytics |
12 | 6 | import org.openedx.course.presentation.CourseAnalytics |
13 | 7 | import org.openedx.dashboard.presentation.DashboardAnalytics |
14 | 8 | import org.openedx.discovery.presentation.DiscoveryAnalytics |
15 | 9 | import org.openedx.discussion.presentation.DiscussionAnalytics |
| 10 | +import org.openedx.foundation.interfaces.Analytics |
16 | 11 | import org.openedx.profile.presentation.ProfileAnalytics |
17 | 12 | import org.openedx.whatsnew.presentation.WhatsNewAnalytics |
18 | 13 |
|
19 | | -class AnalyticsManager( |
20 | | - context: Context, |
21 | | - config: Config, |
22 | | -) : AppAnalytics, AppReviewAnalytics, AuthAnalytics, CoreAnalytics, CourseAnalytics, |
23 | | - DashboardAnalytics, DiscoveryAnalytics, DiscussionAnalytics, ProfileAnalytics, |
24 | | - WhatsNewAnalytics { |
| 14 | +class AnalyticsManager : AppAnalytics, AppReviewAnalytics, AuthAnalytics, CoreAnalytics, |
| 15 | + CourseAnalytics, DashboardAnalytics, DiscoveryAnalytics, DiscussionAnalytics, |
| 16 | + ProfileAnalytics, WhatsNewAnalytics { |
25 | 17 |
|
26 | | - private val services: ArrayList<Analytics> = arrayListOf() |
| 18 | + private val analytics: MutableList<Analytics> = mutableListOf() |
27 | 19 |
|
28 | | - init { |
29 | | - // Initialise all the analytics libraries here |
30 | | - if (config.getFirebaseConfig().enabled) { |
31 | | - addAnalyticsTracker(FirebaseAnalytics(context = context)) |
32 | | - } |
33 | | - |
34 | | - val segmentConfig = config.getSegmentConfig() |
35 | | - if (segmentConfig.enabled && segmentConfig.segmentWriteKey.isNotBlank()) { |
36 | | - addAnalyticsTracker(SegmentAnalytics(context = context, config = config)) |
37 | | - } |
38 | | - |
39 | | - if (config.getFullstoryConfig().isEnabled) { |
40 | | - addAnalyticsTracker(FullstoryAnalytics()) |
41 | | - } |
42 | | - } |
43 | | - |
44 | | - private fun addAnalyticsTracker(analytic: Analytics) { |
45 | | - services.add(analytic) |
| 20 | + fun addAnalyticsTracker(analytic: Analytics) { |
| 21 | + analytics.add(analytic) |
46 | 22 | } |
47 | 23 |
|
48 | 24 | private fun logEvent(event: Event, params: Map<String, Any?> = mapOf()) { |
49 | | - services.forEach { analytics -> |
| 25 | + analytics.forEach { analytics -> |
50 | 26 | analytics.logEvent(event.eventName, params) |
51 | 27 | } |
52 | 28 | } |
53 | 29 |
|
54 | 30 | override fun logScreenEvent(screenName: String, params: Map<String, Any?>) { |
55 | | - services.forEach { analytics -> |
| 31 | + analytics.forEach { analytics -> |
56 | 32 | analytics.logScreenEvent(screenName, params) |
57 | 33 | } |
58 | 34 | } |
59 | 35 |
|
60 | 36 | override fun logEvent(event: String, params: Map<String, Any?>) { |
61 | | - services.forEach { analytics -> |
| 37 | + analytics.forEach { analytics -> |
62 | 38 | analytics.logEvent(event, params) |
63 | 39 | } |
64 | 40 | } |
65 | 41 |
|
66 | 42 | private fun setUserId(userId: Long) { |
67 | | - services.forEach { analytics -> |
| 43 | + analytics.forEach { analytics -> |
68 | 44 | analytics.logUserId(userId) |
69 | 45 | } |
70 | 46 | } |
|
0 commit comments