diff --git a/StatisticReporter/src/main/java/com/gamedog/statisticreporter/StatisticUtil.kt b/StatisticReporter/src/main/java/com/gamedog/statisticreporter/StatisticUtil.kt index 9bb4b47..9a0d465 100644 --- a/StatisticReporter/src/main/java/com/gamedog/statisticreporter/StatisticUtil.kt +++ b/StatisticReporter/src/main/java/com/gamedog/statisticreporter/StatisticUtil.kt @@ -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? = 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") diff --git a/StatisticReporter/src/main/java/com/gamedog/statisticreporter/firbase/FireBaseManager.kt b/StatisticReporter/src/main/java/com/gamedog/statisticreporter/firbase/FireBaseManager.kt index d080bea..e10d2d1 100644 --- a/StatisticReporter/src/main/java/com/gamedog/statisticreporter/firbase/FireBaseManager.kt +++ b/StatisticReporter/src/main/java/com/gamedog/statisticreporter/firbase/FireBaseManager.kt @@ -48,7 +48,11 @@ class FireBaseManager private constructor() { } } - fun reportEvent(eventName: String, parameters: Map? = null) { + fun reportEvent( + eventName: String, + parameters: Map? = null, + superPropertiesMap: Map + ) { 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) { diff --git a/StatisticReporter/src/main/java/com/gamedog/statisticreporter/shushu/ShushuManager.kt b/StatisticReporter/src/main/java/com/gamedog/statisticreporter/shushu/ShushuManager.kt index b2208bf..948197f 100644 --- a/StatisticReporter/src/main/java/com/gamedog/statisticreporter/shushu/ShushuManager.kt +++ b/StatisticReporter/src/main/java/com/gamedog/statisticreporter/shushu/ShushuManager.kt @@ -53,11 +53,17 @@ class ShushuManager private constructor() { * 记录用户的具体行为事件。 * 用户点击按钮、浏览页面、完成购买等。 */ - fun reportEvent(eventKey: String, params: Map?) { - val jsonObj = params?.let { - JSONObject(params) + fun reportEvent(eventKey: String, params: Map?, superProperties: Map) { + try { + TDAnalytics.setSuperProperties(JSONObject(superProperties)) + val jsonObj = params?.let { + JSONObject(params) + } + TDAnalytics.track(eventKey, jsonObj) + + } catch (e: Exception) { + e.printStackTrace() } - TDAnalytics.track(eventKey, jsonObj) }