Skip to content

Commit

Permalink
Release 0.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Oct 29, 2021
1 parent 2534264 commit cf37935
Show file tree
Hide file tree
Showing 11 changed files with 522 additions and 88 deletions.
2 changes: 1 addition & 1 deletion android/SensorsdataUniPlugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ dependencies {
compileOnly fileTree(dir: 'libs', include: ['uniapp-v8-release.aar'])
compileOnly 'com.sensorsdata.analytics.android:SensorsAnalyticsSDK:5.4.5'
compileOnly 'com.alibaba:fastjson:1.1.46.android'

compileOnly 'com.sensorsdata.analytics.android:SensorsFocusSDK:0.4.5'
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,20 @@
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
import com.sensorsdata.sf.core.SensorsFocusAPI;
import com.sensorsdata.uniapp.property.UniPropertyManager;
import com.sensorsdata.uniapp.sf.UniCampaignListener;
import com.sensorsdata.uniapp.util.JSONUtils;

import java.util.Map;

import io.dcloud.feature.uniapp.annotation.UniJSMethod;
import io.dcloud.feature.uniapp.bridge.UniJSCallback;
import io.dcloud.feature.uniapp.common.UniDestroyableModule;

public class UniSensorsAnalyticsModule extends UniDestroyableModule {

public static final String VERSION = "0.0.3";
public static final String VERSION = "0.0.4";

private static final String MODULE_NAME = "UniSensorsAnalyticsModule";
private static final String LOG_TAG = "SA.UniModule";
Expand Down Expand Up @@ -721,8 +724,59 @@ public String getScreenOrientation() {
return "";
}

/**
* 注册弹窗成功的回调,预置弹窗和自定义会回调此接口
*
* @param callback callback
*/
@UniJSMethod()
public void popupLoadSuccess(UniJSCallback callback) {
UniCampaignListener.loadSuccessJSCallback = callback;
}

/**
* 注册弹窗失败的回调,预置弹窗和自定义会回调此接口
*
* @param callback callback
*/
@UniJSMethod()
public void popupLoadFailed(UniJSCallback callback) {
UniCampaignListener.loadFailedJSCallback = callback;
}

/**
* 注册弹窗点击的回调,预置弹窗会回调此接口
*
* @param callback callback
*/
@UniJSMethod()
public void popupClick(UniJSCallback callback) {
UniCampaignListener.clickJSCallback = callback;
}

/**
* 注册弹窗点击的回调,预置弹窗会回调此接口
*
* @param callback callback
*/
@UniJSMethod()
public void popupClose(UniJSCallback callback) {
UniCampaignListener.closeJSCallback = callback;
}

/**
* 运行弹窗,与初始化的 android_sfo_enable_popup 配合使用
*/
@UniJSMethod()
public void enablePopup() {
try {
SensorsFocusAPI.sharedInstance().enablePopup();
} catch (Exception e) {
Log.i(LOG_TAG, e.getMessage());
}
}

@Override
public void destroy() {
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,12 @@
import com.sensorsdata.analytics.android.sdk.SAConfigOptions;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
import com.sensorsdata.analytics.android.sdk.SensorsDataAPIEmptyImplementation;
import com.sensorsdata.sf.core.SFConfigOptions;
import com.sensorsdata.sf.core.SensorsFocusAPI;
import com.sensorsdata.uniapp.property.PluginVersionInterceptor;
import com.sensorsdata.uniapp.property.UniPropertyManager;
import com.sensorsdata.uniapp.sf.UniCampaignListener;
import com.sensorsdata.uniapp.sf.UniPopupListener;

import io.dcloud.feature.uniapp.UniAppHookProxy;

Expand All @@ -38,7 +42,15 @@ public class UniSensorsAnalyticsProxy implements UniAppHookProxy {
public void onCreate(Application application) {
try {
if (SensorsDataAPI.sharedInstance() instanceof SensorsDataAPIEmptyImplementation) {
initSensorsDataAPI(application);
ApplicationInfo appInfo = null;
try {
PackageManager pm = application.getPackageManager();
appInfo = pm.getApplicationInfo(application.getPackageName(), PackageManager.GET_META_DATA);
} catch (Exception e) {
Log.i(LOG_TAG, "ApplicationInfo get failed!");
}
initSensorsDataAPI(application, appInfo);
initSensorsFocusAPI(application, appInfo);
}
UniPropertyManager.addInterceptor(new PluginVersionInterceptor());
} catch (Exception e) {
Expand All @@ -54,104 +66,128 @@ public void onSubProcessCreate(Application application) {
/**
* 初始化 Sensors Analytics SDK
*/
private void initSensorsDataAPI(Application application) {
PackageManager pm = application.getPackageManager();
private void initSensorsDataAPI(Application application, ApplicationInfo appInfo) {
SAConfigOptions configOptions = new SAConfigOptions("");
try {
ApplicationInfo appInfo = pm.getApplicationInfo(application.getPackageName(), PackageManager.GET_META_DATA);
// 设置数据上报地址
String serverUrl = appInfo.metaData.getString("com.sensorsdata.analytics.uni.ServerUrl", "");
if (!TextUtils.isEmpty(serverUrl)) {
configOptions.setServerUrl(serverUrl);
}
// 设置全埋点采集内容
try {
int autoTrackType = appInfo.metaData.getInt("com.sensorsdata.analytics.uni.AutoTrackType", 0);
configOptions.setAutoTrackEventType(autoTrackType);
} catch (Exception ignored) {
if (appInfo != null) {
// 设置数据上报地址
String serverUrl = appInfo.metaData.getString("com.sensorsdata.analytics.uni.ServerUrl", "");
if (!TextUtils.isEmpty(serverUrl)) {
configOptions.setServerUrl(serverUrl);
}
// 设置全埋点采集内容
try {
int autoTrackType = appInfo.metaData.getInt("com.sensorsdata.analytics.uni.AutoTrackType", 0);
configOptions.setAutoTrackEventType(autoTrackType);
} catch (Exception ignored) {

}
// 日志打印
try {
boolean enableLog = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.EnableLogging", false);
if (enableLog) {
configOptions.enableLog(enableLog);
}
} catch (Exception ignored) {
// 日志打印
try {
boolean enableLog = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.EnableLogging", false);
if (enableLog) {
configOptions.enableLog(enableLog);
}
} catch (Exception ignored) {

}
// 设置本地缓存上限
try {
int maxCacheSize = appInfo.metaData.getInt("com.sensorsdata.analytics.uni.MaxCacheSize", 32);
if (maxCacheSize > 0) {
configOptions.setMaxCacheSize(maxCacheSize * 1024 * 1024);
}
} catch (Exception ignored) {
// 设置本地缓存上限
try {
int maxCacheSize = appInfo.metaData.getInt("com.sensorsdata.analytics.uni.MaxCacheSize", 32);
if (maxCacheSize > 0) {
configOptions.setMaxCacheSize(maxCacheSize * 1024 * 1024);
}
} catch (Exception ignored) {

}
// 设置是否开启加密
try {
boolean encrypt = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.Encrypt", false);
if (encrypt) {
configOptions.enableEncrypt(true);
}
} catch (Exception ignored) {
// 设置是否开启加密
try {
boolean encrypt = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.Encrypt", false);
if (encrypt) {
configOptions.enableEncrypt(true);
}
} catch (Exception ignored) {

}
// 设置数据采集
try {
boolean dataCollect = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.DataCollect", true);
if (!dataCollect) {
configOptions.disableDataCollect();
}
} catch (Exception ignored) {
// 设置数据采集
try {
boolean dataCollect = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.DataCollect", true);
if (!dataCollect) {
configOptions.disableDataCollect();
}
} catch (Exception ignored) {

}
// 小程序进程是否允许发送数据
try {
boolean isMPProcessFlush = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.MPProcessFlush", false);
if (isMPProcessFlush) {
configOptions.enableSubProcessFlushData();
}
} catch (Exception ignored) {
// 小程序进程是否允许发送数据
try {
boolean isMPProcessFlush = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.MPProcessFlush", false);
if (isMPProcessFlush) {
configOptions.enableSubProcessFlushData();
}
} catch (Exception ignored) {

}
// 设置是否开启日志
try {
boolean javaScriptBridge = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.JavaScriptBridge", false);
if (javaScriptBridge) {
// 设置是否开启日志
boolean isSupportJellyBean = false;
try {
isSupportJellyBean = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.JavaScriptBridgeSupportJellyBean", false);
} catch (Exception ignored) {
}
// 设置是否开启日志
try {
boolean javaScriptBridge = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.JavaScriptBridge", false);
if (javaScriptBridge) {
// 设置是否开启日志
boolean isSupportJellyBean = false;
try {
isSupportJellyBean = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.JavaScriptBridgeSupportJellyBean", false);
} catch (Exception ignored) {

}
configOptions.enableJavaScriptBridge(isSupportJellyBean);
}
} catch (Exception ignored) {

}
//设置远程配置请求地址
try {
String remoteConfigUrl = appInfo.metaData.getString("com.sensorsdata.analytics.uni.RemoteConfigUrl");
if (!TextUtils.isEmpty(remoteConfigUrl)) {
configOptions.setRemoteConfigUrl(remoteConfigUrl);
}
configOptions.enableJavaScriptBridge(isSupportJellyBean);
} catch (Exception ignored) {

}
} catch (Exception ignored) {
// 是否在手动埋点事件中自动添加渠道匹配信息,默认 false
try {
boolean enableAutoAddChannelCallbackEvent = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.EventAutoAddChannelCallbackEvent", false);
configOptions.enableAutoAddChannelCallbackEvent(enableAutoAddChannelCallbackEvent);
} catch (Exception ignored) {

}
}
//设置远程配置请求地址
try {
String remoteConfigUrl = appInfo.metaData.getString("com.sensorsdata.analytics.uni.RemoteConfigUrl");
if (!TextUtils.isEmpty(remoteConfigUrl)) {
configOptions.setRemoteConfigUrl(remoteConfigUrl);
} catch (Exception e) {
Log.i(LOG_TAG, e.getMessage());
}
SensorsDataAPI.startWithConfigOptions(application, configOptions);
}

private void initSensorsFocusAPI(Application application, ApplicationInfo appInfo) {
try {
if (appInfo != null) {
SFConfigOptions sfConfigOptions;
String sfBaseUrl = appInfo.metaData.getString("com.sensorsfocus.apibaseurl", "");
if (TextUtils.isEmpty(sfBaseUrl)) {
return;
}
} catch (Exception ignored) {
sfConfigOptions = new SFConfigOptions(sfBaseUrl);
try {
boolean enablePopup = appInfo.metaData.getBoolean("com.sensorsfocus.enablePopup", true);
sfConfigOptions.enablePopup(enablePopup);
} catch (Exception ignored) {

}
// 是否在手动埋点事件中自动添加渠道匹配信息,默认 false
try {
boolean enableAutoAddChannelCallbackEvent = appInfo.metaData.getBoolean("com.sensorsdata.analytics.uni.EventAutoAddChannelCallbackEvent", false);
configOptions.enableAutoAddChannelCallbackEvent(enableAutoAddChannelCallbackEvent);
} catch (Exception ignored) {
}

SensorsFocusAPI.startWithConfigOptions(application, sfConfigOptions
.setPopupListener(new UniPopupListener())
.setCampaignListener(new UniCampaignListener()));
}
} catch (PackageManager.NameNotFoundException e) {
Log.i(LOG_TAG, e.getMessage());
} catch (Exception ignored) {
Log.i(LOG_TAG, "SensorsFocus init failed!");
}

SensorsDataAPI.startWithConfigOptions(application, configOptions);
}
}
Loading

0 comments on commit cf37935

Please sign in to comment.