-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
61 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 28 additions & 0 deletions
28
Alkitab/src/main/java/yuku/alkitab/tracking/Analytics.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package yuku.alkitab.tracking; | ||
|
||
import androidx.annotation.NonNull; | ||
|
||
public final class Analytics { | ||
public static class Param { | ||
@NonNull | ||
public static final String START_DATE = "start_date"; | ||
@NonNull | ||
public static final String ITEM_CATEGORY = "item_category"; | ||
@NonNull | ||
public static final String ITEM_NAME = "item_name"; | ||
@NonNull | ||
public static final String METHOD = "method"; | ||
@NonNull | ||
public static final String SUCCESS = "success"; | ||
@NonNull | ||
public static final String ITEM_VARIANT = "item_variant"; | ||
} | ||
|
||
public static class Event { | ||
@NonNull | ||
public static final String LOGIN = "login"; | ||
@NonNull | ||
public static final String SIGN_UP = "sign_up"; | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,12 @@ | ||
package yuku.alkitab.tracking | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import com.google.firebase.analytics.FirebaseAnalytics | ||
import java.util.concurrent.Executors | ||
import yuku.alkitab.base.util.AppLog | ||
|
||
object Tracker { | ||
private lateinit var fa: FirebaseAnalytics | ||
|
||
@JvmStatic | ||
fun init(context: Context) { | ||
if (!::fa.isInitialized) { | ||
fa = FirebaseAnalytics.getInstance(context) | ||
} | ||
} | ||
private const val TAG = "Tracker" | ||
|
||
@JvmStatic | ||
fun trackEvent(category: String, vararg paramPairs: Any) { | ||
var bundle: Bundle? = null | ||
if (paramPairs.isNotEmpty()) { | ||
if (paramPairs.size % 2 != 0) { | ||
throw IllegalArgumentException("Param pairs should have even number of elements. Got: $paramPairs") | ||
} | ||
|
||
bundle = Bundle() | ||
for (i in paramPairs.indices step 2) { | ||
val key = paramPairs[i] as String | ||
when (val value = paramPairs[i + 1]) { | ||
is Int -> bundle.putInt(key, value) | ||
is Double -> bundle.putDouble(key, value) | ||
is Float -> bundle.putDouble(key, value.toDouble()) | ||
else -> bundle.putString(key, value.toString()) | ||
} | ||
} | ||
} | ||
|
||
fa.logEvent(category, bundle) | ||
AppLog.d(TAG, "$category: $paramPairs") | ||
} | ||
} |