firebase shushu 添加 super公用参数

This commit is contained in:
renhaoting 2026-01-22 15:49:26 +08:00
parent 7fff655e81
commit 68d4bc2948
3 changed files with 34 additions and 15 deletions

View File

@ -10,7 +10,6 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch import kotlinx.coroutines.launch
import org.json.JSONObject
object StatisticUtil { object StatisticUtil {
@ -62,16 +61,15 @@ object StatisticUtil {
fun reportEvents(eventKey: String, eventData: Map<String, Any>? = null) { fun reportEvents(eventKey: String, eventData: Map<String, Any>? = null) {
mBgScope.launch { 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) val superPropertiesMap = mapOf("Money_Num" to mCashFun.invoke(),
ShushuManager.instance().reportEvent(eventKey, eventData) "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) { if (BuildConfig.DEBUG) {
StatisticLogger.d("Events reported to shushu&Firebase: type=$eventKey") StatisticLogger.d("Events reported to shushu&Firebase: type=$eventKey")

View File

@ -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) { if (!::mFbAnalytics.isInitialized) {
throw IllegalStateException("FirebaseAnalyticsUtil not initialized. Call init() first.") 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) -> parameters?.forEach { (key, value) ->
when (value) { when (value) {

View File

@ -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 { val jsonObj = params?.let {
JSONObject(params) JSONObject(params)
} }
TDAnalytics.track(eventKey, jsonObj) TDAnalytics.track(eventKey, jsonObj)
} catch (e: Exception) {
e.printStackTrace()
}
} }