firebase shushu 添加 super公用参数
This commit is contained in:
parent
7fff655e81
commit
68d4bc2948
|
|
@ -10,7 +10,6 @@ import kotlinx.coroutines.CoroutineScope
|
|||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.launch
|
||||
import org.json.JSONObject
|
||||
|
||||
object StatisticUtil {
|
||||
|
||||
|
|
@ -62,16 +61,15 @@ object StatisticUtil {
|
|||
|
||||
fun reportEvents(eventKey: String, eventData: Map<String, Any>? = null) {
|
||||
mBgScope.launch {
|
||||
val superProperties = JSONObject().apply {
|
||||
put("Money_Num", mCashFun.invoke())
|
||||
put("Coin_Num", mGoldFun.invoke())
|
||||
put("RV_Times_Coins", mGoldTimesFun.invoke())
|
||||
put("RV_Times_Money", mCashTimesFun.invoke())
|
||||
put("ad_network", AdjustManager.instance().getNetwork())
|
||||
}
|
||||
|
||||
FireBaseManager.instance().reportEvent(eventKey, eventData)
|
||||
ShushuManager.instance().reportEvent(eventKey, eventData)
|
||||
val superPropertiesMap = mapOf("Money_Num" to mCashFun.invoke(),
|
||||
"Coin_Num" to mGoldFun.invoke(),
|
||||
"RV_Times_Coins" to mGoldTimesFun.invoke(),
|
||||
"RV_Times_Money" to mCashTimesFun.invoke(),
|
||||
"ad_network" to AdjustManager.instance().getNetwork()
|
||||
)
|
||||
FireBaseManager.instance().reportEvent(eventKey, eventData, superPropertiesMap)
|
||||
ShushuManager.instance().reportEvent(eventKey, eventData, superPropertiesMap)
|
||||
|
||||
if (BuildConfig.DEBUG) {
|
||||
StatisticLogger.d("Events reported to shushu&Firebase: type=$eventKey")
|
||||
|
|
|
|||
|
|
@ -48,7 +48,11 @@ class FireBaseManager private constructor() {
|
|||
}
|
||||
}
|
||||
|
||||
fun reportEvent(eventName: String, parameters: Map<String, Any>? = null) {
|
||||
fun reportEvent(
|
||||
eventName: String,
|
||||
parameters: Map<String, Any>? = null,
|
||||
superPropertiesMap: Map<String, Any>
|
||||
) {
|
||||
if (!::mFbAnalytics.isInitialized) {
|
||||
throw IllegalStateException("FirebaseAnalyticsUtil not initialized. Call init() first.")
|
||||
}
|
||||
|
|
@ -66,6 +70,17 @@ class FireBaseManager private constructor() {
|
|||
}
|
||||
}
|
||||
|
||||
superPropertiesMap.forEach { (key, value) ->
|
||||
when (value) {
|
||||
is String -> putString(key, value)
|
||||
is Int -> putInt(key, value)
|
||||
is Long -> putLong(key, value)
|
||||
is Double -> putDouble(key, value)
|
||||
is Float -> putFloat(key, value)
|
||||
is Boolean -> putBoolean(key, value)
|
||||
}
|
||||
}
|
||||
|
||||
// 本次事件特定参数添加
|
||||
parameters?.forEach { (key, value) ->
|
||||
when (value) {
|
||||
|
|
|
|||
|
|
@ -53,11 +53,17 @@ class ShushuManager private constructor() {
|
|||
* 记录用户的具体行为事件。
|
||||
* 用户点击按钮、浏览页面、完成购买等。
|
||||
*/
|
||||
fun reportEvent(eventKey: String, params: Map<String, Any>?) {
|
||||
fun reportEvent(eventKey: String, params: Map<String, Any>?, superProperties: Map<String, Any>) {
|
||||
try {
|
||||
TDAnalytics.setSuperProperties(JSONObject(superProperties))
|
||||
val jsonObj = params?.let {
|
||||
JSONObject(params)
|
||||
}
|
||||
TDAnalytics.track(eventKey, jsonObj)
|
||||
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue