1- package com.getcode.manager
1+ package com.getcode.analytics
22
33import com.getcode.api.BuildConfig
44import com.getcode.model.CurrencyCode
@@ -15,31 +15,29 @@ import timber.log.Timber
1515import javax.inject.Inject
1616import javax.inject.Singleton
1717
18- interface AnalyticsService {
19- fun open (screen : AnalyticsManager .Screen )
20- fun login (ownerPublicKey : String , autoCompleteCount : Int , inputChangeCount : Int )
21- fun logout ()
22- fun track (event : AnalyticsManager .Name , vararg properties : Pair <AnalyticsManager .Property , String >)
23- }
24-
25- class AnalyticsServiceNull : AnalyticsService {
26- override fun open (screen : AnalyticsManager .Screen ) = Unit
27-
28- override fun login (ownerPublicKey : String , autoCompleteCount : Int , inputChangeCount : Int ) = Unit
29-
30- override fun logout () = Unit
31-
32- override fun track (
33- event : AnalyticsManager .Name ,
34- vararg properties : Pair <AnalyticsManager .Property , String >
35- ) = Unit
36- }
37-
3818@Singleton
39- class AnalyticsManager @Inject constructor(private val mixpanelAPI : MixpanelAPI ): AnalyticsService {
19+ class AnalyticsManager @Inject constructor(
20+ private val mixpanelAPI : MixpanelAPI
21+ ) : AnalyticsService {
4022 private var grabStartMillis: Long = 0L
4123 private var cashLinkGrabStartMillis: Long = 0L
4224
25+ private var traceAppInit: Trace ? = null
26+ private var timeAppInit: Long? = null
27+
28+ override fun onAppStart () {
29+ timeAppInit = System .currentTimeMillis()
30+ traceAppInit = Firebase .performance.newTrace(" Init" )
31+ traceAppInit?.start()
32+ }
33+
34+ override fun onAppStarted () {
35+ traceAppInit ? : return
36+ traceAppInit?.stop()
37+ traceAppInit = null
38+ Timber .i(" App init time: " + (System .currentTimeMillis() - (timeAppInit ? : 0 )))
39+ }
40+
4341 override fun open (screen : Screen ) {
4442 track(Name .Open , Pair (Property .Screen , screen.value))
4543 }
@@ -57,15 +55,19 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
5755 )
5856 }
5957
60- fun createAccount (isSuccessful : Boolean , ownerPublicKey : String? ) {
58+ override fun createAccount (isSuccessful : Boolean , ownerPublicKey : String? ) {
6159 track(
6260 Name .CreateAccount ,
6361 Pair (Property .Result , isSuccessful.toString()),
6462 Pair (Property .OwnerPublicKey , ownerPublicKey.orEmpty())
6563 )
6664 }
6765
68- fun billTimeoutReached (kin : Kin , currencyCode : CurrencyCode , animation : BillPresentationStyle ) {
66+ override fun billTimeoutReached (
67+ kin : Kin ,
68+ currencyCode : CurrencyCode ,
69+ animation : BillPresentationStyle
70+ ) {
6971 track(
7072 Name .Bill ,
7173 Pair (Property .State , StringValue .TimedOut .value),
@@ -75,7 +77,7 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
7577 )
7678 }
7779
78- fun billShown (kin : Kin , currencyCode : CurrencyCode , animation : BillPresentationStyle ) {
80+ override fun billShown (kin : Kin , currencyCode : CurrencyCode , animation : BillPresentationStyle ) {
7981 track(
8082 Name .Bill ,
8183 Pair (Property .State , StringValue .Shown .value),
@@ -85,7 +87,7 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
8587 )
8688 }
8789
88- fun billHidden (kin : Kin , currencyCode : CurrencyCode , animation : BillPresentationStyle ) {
90+ override fun billHidden (kin : Kin , currencyCode : CurrencyCode , animation : BillPresentationStyle ) {
8991 track(
9092 Name .Bill ,
9193 Pair (Property .State , StringValue .Hidden .value),
@@ -95,7 +97,7 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
9597 )
9698 }
9799
98- fun transfer (amount : KinAmount , successful : Boolean ) {
100+ override fun transfer (amount : KinAmount , successful : Boolean ) {
99101 track(
100102 Name .Transfer ,
101103 Property .State to if (successful) StringValue .Success .value else StringValue .Failure .value,
@@ -106,19 +108,47 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
106108 )
107109 }
108110
109- fun recomputed (fxIn : Double , fxOut : Double ) {
111+ override fun transferForRequest (amount : KinAmount , successful : Boolean ) {
112+ track(
113+ Name .RequestPayment ,
114+ Property .State to if (successful) StringValue .Success .value else StringValue .Failure .value,
115+ Property .Amount to amount.kin.toKin().toInt().toString(),
116+ Property .Fiat to amount.fiat.toString(),
117+ Property .Fx to amount.rate.fx.toString(),
118+ Property .Currency to amount.rate.currency.name,
119+ )
120+ }
121+
122+ override fun remoteSendOutgoing (kin : Kin , currencyCode : CurrencyCode ) {
123+ track(
124+ Name .RemoteSendOutgoing ,
125+ Property .Amount to kin.toKin().toInt().toString(),
126+ Property .Currency to currencyCode.name
127+ )
128+ }
129+
130+ override fun remoteSendIncoming (kin : Kin , currencyCode : CurrencyCode , isVoiding : Boolean ) {
131+ track(
132+ Name .RemoteSendIncoming ,
133+ Property .VoidingSend to if (isVoiding) StringValue .Yes .value else StringValue .No .value,
134+ Property .Amount to kin.toKin().toInt().toString(),
135+ Property .Currency to currencyCode.name
136+ )
137+ }
138+
139+ override fun recomputed (fxIn : Double , fxOut : Double ) {
110140 val delta = ((fxOut / fxIn) - 1 ) * 100
111141 track(
112142 Name .Recompute ,
113143 Property .PercentDelta to delta.toString()
114144 )
115145 }
116146
117- fun grabStart () {
147+ override fun grabStart () {
118148 grabStartMillis = System .currentTimeMillis()
119149 }
120150
121- fun grab (kin : Kin , currencyCode : CurrencyCode ) {
151+ override fun grab (kin : Kin , currencyCode : CurrencyCode ) {
122152 if (grabStartMillis == 0L ) return
123153 val millisecondsToGrab = System .currentTimeMillis() - grabStartMillis
124154 track(
@@ -130,7 +160,7 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
130160 grabStartMillis = 0
131161 }
132162
133- fun requestShown (amount : KinAmount ) {
163+ override fun requestShown (amount : KinAmount ) {
134164 track(
135165 Name .Request ,
136166 Property .State to StringValue .Shown .value,
@@ -140,7 +170,7 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
140170 )
141171 }
142172
143- fun requestHidden (amount : KinAmount ) {
173+ override fun requestHidden (amount : KinAmount ) {
144174 track(
145175 Name .Request ,
146176 Property .State to StringValue .Hidden .value,
@@ -150,11 +180,11 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
150180 )
151181 }
152182
153- fun cashLinkGrabStart () {
183+ override fun cashLinkGrabStart () {
154184 cashLinkGrabStartMillis = System .currentTimeMillis()
155185 }
156186
157- fun cashLinkGrab (kin : Kin , currencyCode : CurrencyCode ) {
187+ override fun cashLinkGrab (kin : Kin , currencyCode : CurrencyCode ) {
158188 if (cashLinkGrabStartMillis == 0L ) return
159189 val millisecondsToGrab = System .currentTimeMillis() - cashLinkGrabStartMillis
160190 track(
@@ -166,43 +196,30 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
166196 cashLinkGrabStartMillis = 0
167197 }
168198
169- fun migration (amount : Kin ) {
199+ override fun migration (amount : Kin ) {
170200 track(
171201 Name .PrivacyMigration ,
172202 Pair (Property .Amount , amount.toKin().toInt().toString())
173203 )
174204 }
175205
176- fun upgradePrivacy (successful : Boolean , intentId : PublicKey , actionCount : Int ) {
206+ override fun upgradePrivacy (successful : Boolean , intentId : PublicKey , actionCount : Int ) {
177207 track(
178208 Name .UpgradePrivacy ,
179- Pair (Property .State , if (successful) StringValue .Success .value else StringValue .Failure .value),
209+ Pair (
210+ Property .State ,
211+ if (successful) StringValue .Success .value else StringValue .Failure .value
212+ ),
180213 Pair (Property .IntentId , intentId.base58()),
181214 Pair (Property .ActionCount , actionCount.toString())
182215 )
183216 }
184217
185- private var traceAppInit: Trace ? = null
186- private var timeAppInit: Long? = null
187-
188- fun onAppStart () {
189- timeAppInit = System .currentTimeMillis()
190- traceAppInit = Firebase .performance.newTrace(" Init" )
191- traceAppInit?.start()
192- }
193-
194- fun onAppStarted () {
195- traceAppInit ? : return
196- traceAppInit?.stop()
197- traceAppInit = null
198- Timber .i(" App init time: " + (System .currentTimeMillis() - (timeAppInit ? : 0 )))
199- }
200-
201- fun onBillReceived () {
218+ override fun onBillReceived () {
202219 Timber .i(" Bill scanned. From start: " + (System .currentTimeMillis() - (timeAppInit ? : 0 )))
203220 }
204221
205- override fun track (event : Name , vararg properties : Pair <Property , String >) {
222+ private fun track (event : Name , vararg properties : Pair <Property , String >) {
206223 if (BuildConfig .DEBUG ) {
207224 Timber .d(" debug track $event , ${properties.map { " ${it.first.name} , ${it.second} " }} " )
208225 return
@@ -231,14 +248,16 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
231248 // Transfer
232249 Transfer (" Transfer" ),
233250 RequestPayment (" Request Payment" ),
251+ RemoteSendOutgoing (" Remote Send Outgoing" ),
252+ RemoteSendIncoming (" Remote Send Incoming" ),
234253 Grab (" Grab" ),
235254 CashLinkGrab (" CashLinkGrab" ),
236- Validation (" Validation" ),
237-
238- PrivacyMigration (" Privacy Migration" ),
239255 UpgradePrivacy (" Upgrade Privacy" ),
240- ErrorRequest (" Error Request" ),
256+ ClaimGetFreeKin (" Claim Get Free Kin" ),
257+ PrivacyMigration (" Privacy Migration" ),
241258
259+ // Errors
260+ ErrorRequest (" Error Request" ),
242261
243262 Recompute (" Recompute" ),
244263 }
@@ -272,6 +291,9 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
272291 IntentId (" Intent ID" ),
273292 ActionCount (" Action Count" ),
274293
294+ // Remote Send
295+ VoidingSend (" Voiding Send" ),
296+
275297 PercentDelta (" Percent Delta" ),
276298
277299 }
@@ -305,6 +327,8 @@ class AnalyticsManager @Inject constructor(private val mixpanelAPI: MixpanelAPI)
305327 enum class StringValue (val value : String ) {
306328 Success (" Success" ),
307329 Failure (" Failure" ),
330+ Yes (" Yes" ),
331+ No (" No" ),
308332 Shown (" Shown" ),
309333 Hidden (" Hidden" ),
310334 TimedOut (" Timed Out" ),
0 commit comments