增加firebase埋点
This commit is contained in:
parent
4ea3175799
commit
3ed9e5e1c1
@ -160,7 +160,7 @@ dependencies {
|
||||
implementation("com.google.android.gms:play-services-ads-identifier:18.0.1")
|
||||
|
||||
// Debugger UI Tools
|
||||
// implementation ("com.anythink.sdk:debugger-ui:1.0.7")
|
||||
implementation ("com.anythink.sdk:debugger-ui:1.0.8")
|
||||
|
||||
//----------------------------------------------TopOn
|
||||
|
||||
|
||||
@ -7,10 +7,12 @@ import android.util.Log;
|
||||
|
||||
import com.anythink.core.api.ATSDK;
|
||||
import com.anythink.core.api.NetTrafficeCallback;
|
||||
import com.anythink.debug.api.ATDebuggerUITest;
|
||||
import com.anythink.interstitial.api.ATInterstitial;
|
||||
import com.key.coolkeyboard.data.Mydata;
|
||||
import com.key.coolkeyboard.data.MydataBase;
|
||||
import com.key.coolkeyboard.data.Otherdata;
|
||||
import com.key.coolkeyboard.firbase.FirebaseEvent;
|
||||
import com.key.coolkeyboard.tool.Mytool;
|
||||
import com.key.coolkeyboard.topon.AdManager;
|
||||
|
||||
@ -34,6 +36,8 @@ public class CoolKeyboardSkin extends Application {
|
||||
public static final String PRE_NAME = "Mypre";
|
||||
public static final String PRE_KEY = "isinsert";
|
||||
public static final String PRE_KEY_INIT = "isinit";
|
||||
|
||||
public static final String INSTALL_FIRST_OPEN = "first_open";
|
||||
public static final String TAG = "zzj";
|
||||
public static List<Otherdata> alllist = new ArrayList<>();
|
||||
public static List<Otherdata> lovelist = new ArrayList<>();
|
||||
@ -78,10 +82,11 @@ public class CoolKeyboardSkin extends Application {
|
||||
return superlist;
|
||||
}
|
||||
|
||||
private static final String TOP_ID = "h66a23adb0da69";
|
||||
private static final String TOP_KEY = "ad31a3e8504709d2642bc5c311c254bcd";
|
||||
private static final String TOP_DEBUG = "8a341b6aa5cc3fa453d7741f01a534c1d5dd766a";
|
||||
private static final String APP_ID = "h66a23adb0da69";
|
||||
private static final String APP_KEY = "ad31a3e8504709d2642bc5c311c254bcd";
|
||||
private static final String TOP_DEBUG = "4e26d6fdb6029c920a512f4d896f6331f47c82d0";
|
||||
public static List<ATInterstitial> ads;
|
||||
public static final String Firebase_Key = "install_source";
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
@ -132,13 +137,20 @@ public class CoolKeyboardSkin extends Application {
|
||||
|
||||
initKey();
|
||||
|
||||
boolean firstOpen = sp.getBoolean(INSTALL_FIRST_OPEN, true);
|
||||
if (firstOpen) {
|
||||
editor = sp.edit();
|
||||
editor.putBoolean(INSTALL_FIRST_OPEN, false);
|
||||
editor.apply();
|
||||
FirebaseEvent.getInstance(this).PostEvent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void initKey() {
|
||||
sp = getSharedPreferences(PRE_NAME, MODE_PRIVATE);
|
||||
init = sp.getBoolean(PRE_KEY, false);
|
||||
if (!init) {
|
||||
|
||||
Mytool.runIO(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
@ -154,17 +166,14 @@ public class CoolKeyboardSkin extends Application {
|
||||
private void initSdk() {
|
||||
// ATSDK.integrationChecking(context);
|
||||
|
||||
ATSDK.init(context, TOP_ID, TOP_KEY);
|
||||
ATSDK.init(context, APP_ID, APP_KEY);
|
||||
AdManager.loadAllAd();
|
||||
|
||||
// ATSDK.setNetworkLogDebug(true);
|
||||
|
||||
|
||||
// ATDebuggerUITest.showDebuggerUI(context,TOP_DEBUG);
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void initData() {
|
||||
Mytool.runIO(new Runnable() {
|
||||
@Override
|
||||
|
||||
@ -29,7 +29,7 @@ import com.key.coolkeyboard.tool.Adcallback;
|
||||
import com.key.coolkeyboard.tool.Mytool;
|
||||
import com.key.coolkeyboard.topon.AdManager;
|
||||
import com.key.coolkeyboard.topon.onActionListener;
|
||||
import com.vungle.ads.Ad;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -4,7 +4,7 @@ import androidx.room.Entity;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import com.key.coolkeyboard.CoolKeyboardSkin;
|
||||
import com.pgl.ssdk.S;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -0,0 +1,93 @@
|
||||
package com.key.coolkeyboard.firbase;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageInfo;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
import android.util.Log;
|
||||
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.key.coolkeyboard.CoolKeyboardSkin;
|
||||
|
||||
import java.io.File;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class FirebaseEvent {
|
||||
private static FirebaseEvent firebaseEventInstance;
|
||||
|
||||
private Context mContext;
|
||||
|
||||
public FirebaseEvent(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public static FirebaseEvent getInstance(Context context) {
|
||||
if (firebaseEventInstance == null) {
|
||||
synchronized (FirebaseEvent.class) {
|
||||
if (firebaseEventInstance == null) {
|
||||
firebaseEventInstance = new FirebaseEvent(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
return firebaseEventInstance;
|
||||
}
|
||||
|
||||
public void PostEvent(){
|
||||
FirebaseAnalytics instance = FirebaseAnalytics.getInstance(mContext);
|
||||
Bundle bundleEvent = new Bundle();
|
||||
String initiatingPackageName = "";
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||
try {
|
||||
initiatingPackageName = mContext.getPackageManager().getInstallSourceInfo(mContext.getApplicationInfo().packageName).getInitiatingPackageName();
|
||||
} catch (PackageManager.NameNotFoundException e) {
|
||||
Log.d(CoolKeyboardSkin.TAG, "-firstInstall----NameNotFoundException=" + e.getMessage());
|
||||
}
|
||||
} else {
|
||||
initiatingPackageName = mContext.getPackageManager().getInstallerPackageName(mContext.getApplicationInfo().packageName);
|
||||
}
|
||||
Log.d(CoolKeyboardSkin.TAG, "-firstInstall----initiatingPackageName=" + initiatingPackageName);
|
||||
bundleEvent.putString("installer_name", initiatingPackageName);
|
||||
try {
|
||||
PackageInfo packageInfo = mContext.getPackageManager().getPackageInfo("com.android.vending", 0);
|
||||
bundleEvent.putString("ps_version", packageInfo.versionName);
|
||||
bundleEvent.putInt("ps_version_code", packageInfo.versionCode);
|
||||
} catch (Throwable unused) {
|
||||
bundleEvent.putString("ps_version", "-1");
|
||||
bundleEvent.putInt("ps_version_code", -1);
|
||||
}
|
||||
|
||||
//开机日期的时间戳
|
||||
long timeString = System.currentTimeMillis()-SystemClock.elapsedRealtime();
|
||||
//开机累计毫秒数
|
||||
long millis = System.currentTimeMillis() - timeString;
|
||||
|
||||
String days = convertMillisToDaysHours(System.currentTimeMillis()-timeString);
|
||||
bundleEvent.putString("开机",days);
|
||||
|
||||
|
||||
long lastModified = new File(mContext.getApplicationInfo().sourceDir).lastModified();
|
||||
String formatLastModified = getTimeString(lastModified);
|
||||
bundleEvent.putString("安装",formatLastModified);
|
||||
|
||||
Log.d(CoolKeyboardSkin.TAG, "-firstInstall----开机=" + days+"----开机毫秒数=--"+millis+"----安装="+formatLastModified);
|
||||
instance.logEvent(CoolKeyboardSkin.Firebase_Key, bundleEvent);
|
||||
}
|
||||
|
||||
private String getTimeString(long tim) {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.getDefault());
|
||||
return simpleDateFormat.format(new Date(tim));
|
||||
}
|
||||
private String convertMillisToDaysHours(long milliseconds) {
|
||||
long minutes = TimeUnit.MILLISECONDS.toMinutes(milliseconds);
|
||||
long hours = TimeUnit.MILLISECONDS.toHours(milliseconds);
|
||||
long days = TimeUnit.MILLISECONDS.toDays(milliseconds);
|
||||
|
||||
return days + " 天 " + hours % 24 + " 小时 "+minutes % 60+" 分钟";
|
||||
}
|
||||
}
|
||||
@ -44,7 +44,7 @@ dependencyResolutionManagement {
|
||||
maven ("https://cboost.jfrog.io/artifactory/chartboost-mediation")
|
||||
|
||||
//TopOn集成测试工具
|
||||
// maven ( "https://jfrog.anythinktech.com/artifactory/debugger")
|
||||
maven ( "https://jfrog.anythinktech.com/artifactory/debugger")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user