|
@@ -6,7 +6,17 @@ import android.content.Context
|
|
|
import android.text.TextUtils
|
|
|
import cn.yyxx.eyuancomm.comm.entity.SdkChargeInfo
|
|
|
import cn.yyxx.eyuancomm.comm.entity.SdkEvent
|
|
|
+import cn.yyxx.eyuancomm.comm.entity.SdkLoginInfo
|
|
|
import cn.yyxx.eyuancomm.comm.internal.ITrace
|
|
|
+import cn.yyxx.eyuancomm.comm.utils.Logger
|
|
|
+import cn.yyxx.eyuancomm.comm.utils.MMKVManager
|
|
|
+import cn.yyxx.eyuancomm.comm.utils.ParamsUtils
|
|
|
+import cn.yyxx.support.JsonUtils
|
|
|
+import cn.yyxx.support.hawkeye.LogUtils
|
|
|
+import com.adjust.sdk.Adjust
|
|
|
+import com.adjust.sdk.AdjustConfig
|
|
|
+import com.adjust.sdk.AdjustEvent
|
|
|
+import com.adjust.sdk.LogLevel
|
|
|
import org.json.JSONObject
|
|
|
import java.io.BufferedReader
|
|
|
import java.io.InputStreamReader
|
|
@@ -22,69 +32,184 @@ class AdjustEventTrace(private val onIdRead: (String) -> Unit) : ITrace {
|
|
|
private var extConfig: JSONObject? = null
|
|
|
|
|
|
override fun onInitialize(application: Application) {
|
|
|
-// this.sdkConfig = getSdkLogJson(application)
|
|
|
-// this.extConfig = getExtLogJson(application)
|
|
|
-//
|
|
|
-// if (sdkConfig == null) {
|
|
|
-// Logger.e("adjust log 初始化失败,读取sdk_log.json异常")
|
|
|
-// return
|
|
|
-// }
|
|
|
-//
|
|
|
-// val appId = ParamsUtils.getAdjustAppId(application)
|
|
|
-// if (TextUtils.isEmpty(appId)) {
|
|
|
-// Logger.e("adjust log 初始化失败,app id为空")
|
|
|
-// isInitSuccess = false
|
|
|
-// return
|
|
|
-// }
|
|
|
-//
|
|
|
-// val environment = if (LogUtils.DEBUG) {
|
|
|
-// AdjustConfig.ENVIRONMENT_SANDBOX
|
|
|
-// } else {
|
|
|
-// AdjustConfig.ENVIRONMENT_PRODUCTION
|
|
|
-// }
|
|
|
-//
|
|
|
-// val config = AdjustConfig(application, appId, environment, true)
|
|
|
-// config.setLogLevel(LogLevel.VERBOSE)
|
|
|
-// config.setOnAttributionChangedListener {
|
|
|
-// onIdRead(it.adid)
|
|
|
-// }
|
|
|
-// Adjust.onCreate(config)
|
|
|
-// if (MMKVUtils.instance.eventKV.decodeBool("adjust_activities")) {
|
|
|
-// isInitSuccess = true
|
|
|
-// return
|
|
|
-// }
|
|
|
-// sdkConfig?.apply {
|
|
|
-// if (JsonUtils.hasJsonKey(this, "open_app")) {
|
|
|
-// Adjust.trackEvent(AdjustEvent(this.getString("open_app")))
|
|
|
-// Logger.d("adjust log open app success")
|
|
|
-// MMKVUtils.instance.eventKV.encode("adjust_activities", true)
|
|
|
-// isInitSuccess = true
|
|
|
-// }
|
|
|
-// }
|
|
|
+ this.sdkConfig = getSdkLogJson(application)
|
|
|
+ this.extConfig = getExtLogJson(application)
|
|
|
+
|
|
|
+ if (sdkConfig == null) {
|
|
|
+ Logger.e("adjust log 初始化失败,读取sdk_log.json异常")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ val appId = ParamsUtils.getAdjustAppId(application)
|
|
|
+ if (TextUtils.isEmpty(appId)) {
|
|
|
+ Logger.e("adjust log 初始化失败,app id为空")
|
|
|
+ isInitSuccess = false
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ val environment = if (LogUtils.DEBUG) {
|
|
|
+ AdjustConfig.ENVIRONMENT_SANDBOX
|
|
|
+ } else {
|
|
|
+ AdjustConfig.ENVIRONMENT_PRODUCTION
|
|
|
+ }
|
|
|
+
|
|
|
+ val config = AdjustConfig(application, appId, environment, true)
|
|
|
+ config.setLogLevel(LogLevel.VERBOSE)
|
|
|
+ config.setOnAttributionChangedListener {
|
|
|
+ onIdRead(it.adid)
|
|
|
+ }
|
|
|
+ Adjust.onCreate(config)
|
|
|
+ if (MMKVManager.instance.eventKV.decodeBool("adjust_activities")) {
|
|
|
+ isInitSuccess = true
|
|
|
+ return
|
|
|
+ }
|
|
|
+ sdkConfig?.apply {
|
|
|
+ if (JsonUtils.hasJsonKey(this, "open_app")) {
|
|
|
+ Adjust.trackEvent(AdjustEvent(this.getString("open_app")))
|
|
|
+ Logger.d("adjust log open app success")
|
|
|
+ MMKVManager.instance.eventKV.encode("adjust_activities", true)
|
|
|
+ isInitSuccess = true
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onLogin(context: Context) {
|
|
|
+ if (!isInitSuccess) {
|
|
|
+ Logger.e("adjust log failed , component initialize failed")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (TextUtils.isEmpty(SdkLoginInfo.instance.userId)) {
|
|
|
+ Logger.e("adjust log failed , user is null")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ sdkConfig?.apply {
|
|
|
+ if (JsonUtils.hasJsonKey(this, "login_success_account")) {
|
|
|
+ Adjust.trackEvent(AdjustEvent(this.getString("login_success_account")))
|
|
|
+ Logger.d("adjust log account login success")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onRegister(context: Context) {
|
|
|
+ if (!isInitSuccess) {
|
|
|
+ Logger.e("adjust log failed , component initialize failed")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (TextUtils.isEmpty(SdkLoginInfo.instance.userId)) {
|
|
|
+ Logger.e("adjust log failed , user is null")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ sdkConfig?.apply {
|
|
|
+ if (JsonUtils.hasJsonKey(this, "sign_up")) {
|
|
|
+ Adjust.trackEvent(AdjustEvent(this.getString("sign_up")))
|
|
|
+ Logger.d("adjust log register success")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onCharge(context: Context, chargeInfo: SdkChargeInfo) {
|
|
|
+ if (!isInitSuccess) {
|
|
|
+ Logger.e("adjust log failed , component initialize failed")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ if (TextUtils.isEmpty(SdkLoginInfo.instance.userId)) {
|
|
|
+ Logger.e("adjust log failed , user is null")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ sdkConfig?.apply {
|
|
|
+ if (!MMKVManager.instance.eventKV.decodeBool("adjust_first_purchase")) {
|
|
|
+ if (JsonUtils.hasJsonKey(this, "first_purchase")) {
|
|
|
+ val event = AdjustEvent(this.getString("first_purchase"))
|
|
|
+ event.setRevenue(chargeInfo.amount.toDouble() / 100, "USD")
|
|
|
+// event.setOrderId(chargeInfo.orderId)
|
|
|
+ Adjust.trackEvent(event)
|
|
|
+ Logger.d("adjust log first charge success")
|
|
|
+ MMKVManager.instance.eventKV.encode("adjust_first_purchase", true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (JsonUtils.hasJsonKey(this, "ecommerce_purchase")) {
|
|
|
+ val event = AdjustEvent(this.getString("ecommerce_purchase"))
|
|
|
+ event.setRevenue(chargeInfo.amount.toDouble() / 100, "USD")
|
|
|
+// event.setOrderId(chargeInfo.orderId)
|
|
|
+ Adjust.trackEvent(event)
|
|
|
+ Logger.d("adjust log charge success")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onCreate(activity: Activity) {
|
|
|
}
|
|
|
|
|
|
override fun onResume(activity: Activity) {
|
|
|
+ if (!isInitSuccess) {
|
|
|
+ Logger.e("adjust log failed , component initialize failed")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Adjust.onResume()
|
|
|
}
|
|
|
|
|
|
override fun onPause(activity: Activity) {
|
|
|
+ if (!isInitSuccess) {
|
|
|
+ Logger.e("adjust log failed , component initialize failed")
|
|
|
+ return
|
|
|
+ }
|
|
|
+ Adjust.onPause()
|
|
|
}
|
|
|
|
|
|
override fun onSdkEvent(context: Context, sdkEvent: SdkEvent) {
|
|
|
+ if (!isInitSuccess) {
|
|
|
+ Logger.e("adjust log failed , component initialize failed")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ sdkConfig?.apply {
|
|
|
+ if (JsonUtils.hasJsonKey(this, sdkEvent.eventName)) {
|
|
|
+ Adjust.trackEvent(AdjustEvent(this.getString(sdkEvent.eventName)))
|
|
|
+ Logger.d("adjust log sdk event ${sdkEvent.eventName} success")
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override fun onExtEvent(context: Context, sdkEvent: SdkEvent) {
|
|
|
+ if (!isInitSuccess) {
|
|
|
+ Logger.e("adjust log failed , component initialize failed")
|
|
|
+ return
|
|
|
+ }
|
|
|
+
|
|
|
+ extConfig?.apply {
|
|
|
+ if (JsonUtils.hasJsonKey(this, sdkEvent.eventName)) {
|
|
|
+ Adjust.trackEvent(AdjustEvent(this.getString(sdkEvent.eventName)))
|
|
|
+ Logger.d("adjust log ext event ${sdkEvent.eventName} success")
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private fun getSdkLogJson(context: Context): JSONObject? {
|
|
|
+ val path = "yyxx_game/sdk_log.json"
|
|
|
+ val sb = StringBuilder()
|
|
|
+ try {
|
|
|
+ val assetManager = context.assets
|
|
|
+ BufferedReader(InputStreamReader(assetManager.open(path))).use {
|
|
|
+ var line = ""
|
|
|
+ while (true) {
|
|
|
+ line = it.readLine() ?: break
|
|
|
+ sb.append(line)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!TextUtils.isEmpty(sb.toString())) {
|
|
|
+ return JSONObject(sb.toString())
|
|
|
+ }
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ return null
|
|
|
}
|
|
|
|
|
|
private fun getExtLogJson(context: Context): JSONObject? {
|