... |
... |
@@ -8,10 +8,6 @@ import android.app.Activity |
8
|
8
|
import android.app.Application
|
9
|
9
|
import android.os.Bundle
|
10
|
10
|
import android.util.Log
|
11
|
|
-import com.adjust.sdk.Adjust
|
12
|
|
-import com.adjust.sdk.AdjustConfig
|
13
|
|
-import com.adjust.sdk.AdjustEvent
|
14
|
|
-import com.adjust.sdk.LogLevel
|
15
|
11
|
import kotlinx.coroutines.CoroutineDispatcher
|
16
|
12
|
import kotlinx.coroutines.CoroutineScope
|
17
|
13
|
import kotlinx.coroutines.Dispatchers
|
... |
... |
@@ -31,76 +27,16 @@ class AdjustMetricsService( |
31
|
27
|
override val type = MetricServiceType.Marketing
|
32
|
28
|
|
33
|
29
|
override fun start() {
|
34
|
|
- if ((BuildConfig.ADJUST_TOKEN.isNullOrBlank())) {
|
35
|
|
- Log.i(LOGTAG, "No adjust token defined")
|
36
|
|
-
|
37
|
|
- if (Config.channel.isReleased && !BuildConfig.DATA_COLLECTION_DISABLED) {
|
38
|
|
- throw IllegalStateException("No adjust token defined for release build")
|
39
|
|
- }
|
40
|
|
-
|
41
|
|
- return
|
42
|
|
- }
|
43
|
|
-
|
44
|
|
- val config = AdjustConfig(
|
45
|
|
- application,
|
46
|
|
- BuildConfig.ADJUST_TOKEN,
|
47
|
|
- AdjustConfig.ENVIRONMENT_PRODUCTION,
|
48
|
|
- true,
|
49
|
|
- )
|
50
|
|
- config.setPreinstallTrackingEnabled(true)
|
51
|
|
-
|
52
|
|
- val installationPing = FirstSessionPing(application)
|
53
|
|
-
|
54
|
|
- val timerId = FirstSession.adjustAttributionTime.start()
|
55
|
|
- config.setOnAttributionChangedListener {
|
56
|
|
- FirstSession.adjustAttributionTime.stopAndAccumulate(timerId)
|
57
|
|
- if (!it.network.isNullOrEmpty()) {
|
58
|
|
- application.applicationContext.settings().adjustNetwork =
|
59
|
|
- it.network
|
60
|
|
- }
|
61
|
|
- if (!it.adgroup.isNullOrEmpty()) {
|
62
|
|
- application.applicationContext.settings().adjustAdGroup =
|
63
|
|
- it.adgroup
|
64
|
|
- }
|
65
|
|
- if (!it.creative.isNullOrEmpty()) {
|
66
|
|
- application.applicationContext.settings().adjustCreative =
|
67
|
|
- it.creative
|
68
|
|
- }
|
69
|
|
- if (!it.campaign.isNullOrEmpty()) {
|
70
|
|
- application.applicationContext.settings().adjustCampaignId =
|
71
|
|
- it.campaign
|
72
|
|
- }
|
73
|
|
-
|
74
|
|
- installationPing.checkAndSend()
|
75
|
|
- }
|
76
|
|
-
|
77
|
|
- config.setLogLevel(LogLevel.SUPRESS)
|
78
|
|
- Adjust.onCreate(config)
|
79
|
|
- Adjust.setEnabled(true)
|
80
|
|
- application.registerActivityLifecycleCallbacks(AdjustLifecycleCallbacks())
|
|
30
|
+ /* noop */
|
81
|
31
|
}
|
82
|
32
|
|
83
|
33
|
override fun stop() {
|
84
|
|
- Adjust.setEnabled(false)
|
85
|
|
- Adjust.gdprForgetMe(application.applicationContext)
|
|
34
|
+ /* noop */
|
86
|
35
|
}
|
87
|
36
|
|
88
|
37
|
@Suppress("TooGenericExceptionCaught")
|
89
|
38
|
override fun track(event: Event) {
|
90
|
|
- CoroutineScope(dispatcher).launch {
|
91
|
|
- try {
|
92
|
|
- if (event is Event.GrowthData) {
|
93
|
|
- if (storage.shouldTrack(event)) {
|
94
|
|
- Adjust.trackEvent(AdjustEvent(event.tokenName))
|
95
|
|
- storage.updateSentState(event)
|
96
|
|
- } else {
|
97
|
|
- storage.updatePersistentState(event)
|
98
|
|
- }
|
99
|
|
- }
|
100
|
|
- } catch (e: Exception) {
|
101
|
|
- crashReporter.submitCaughtException(e)
|
102
|
|
- }
|
103
|
|
- }
|
|
39
|
+ /* noop */
|
104
|
40
|
}
|
105
|
41
|
|
106
|
42
|
override fun shouldTrack(event: Event): Boolean =
|
... |
... |
@@ -112,11 +48,11 @@ class AdjustMetricsService( |
112
|
48
|
|
113
|
49
|
private class AdjustLifecycleCallbacks : Application.ActivityLifecycleCallbacks {
|
114
|
50
|
override fun onActivityResumed(activity: Activity) {
|
115
|
|
- Adjust.onResume()
|
|
51
|
+ /* noop */
|
116
|
52
|
}
|
117
|
53
|
|
118
|
54
|
override fun onActivityPaused(activity: Activity) {
|
119
|
|
- Adjust.onPause()
|
|
55
|
+ /* noop */
|
120
|
56
|
}
|
121
|
57
|
|
122
|
58
|
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) { /* noop */ }
|