Skip to content

Commit

Permalink
Release 6.2.1
Browse files Browse the repository at this point in the history
  • Loading branch information
weiqiangliu committed Jan 20, 2022
1 parent 932dcac commit 667f279
Show file tree
Hide file tree
Showing 28 changed files with 1,730 additions and 575 deletions.
2 changes: 1 addition & 1 deletion SensorsAnalyticsSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apply plugin: 'com.android.library'
apply plugin: 'signing'
apply plugin: 'maven-publish'

version = "6.2.0"
version = "6.2.1"
def min_plugin_version = "3.4.0"

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
import com.sensorsdata.analytics.android.sdk.listener.SAEventListener;
import com.sensorsdata.analytics.android.sdk.listener.SAFunctionListener;
import com.sensorsdata.analytics.android.sdk.listener.SAJSListener;
import com.sensorsdata.analytics.android.sdk.plugin.property.SAPresetPropertyPlugin;
import com.sensorsdata.analytics.android.sdk.plugin.property.SensorsDataPropertyPluginManager;
import com.sensorsdata.analytics.android.sdk.remote.BaseSensorsDataSDKRemoteManager;
import com.sensorsdata.analytics.android.sdk.remote.SensorsDataRemoteManager;
import com.sensorsdata.analytics.android.sdk.util.AppInfoUtils;
Expand Down Expand Up @@ -184,7 +186,7 @@ public AbstractSensorsDataAPI(Context context, SAConfigOptions configOptions, Se
new Thread(mTrackTaskManagerThread, ThreadNameConstants.THREAD_TASK_QUEUE).start();
SensorsDataExceptionHandler.init();
initSAConfig(mSAConfigOptions.mServerUrl, packageName);
mSAContextManager = new SAContextManager(mContext, mDisableTrackDeviceId);
mSAContextManager = new SAContextManager(mContext);
mMessages = AnalyticsMessages.getInstance(mContext, (SensorsDataAPI) this);
mRemoteManager = new SensorsDataRemoteManager((SensorsDataAPI) this);
//先从缓存中读取 SDKConfig
Expand Down Expand Up @@ -216,6 +218,11 @@ public AbstractSensorsDataAPI(Context context, SAConfigOptions configOptions, Se
} catch (Throwable ex) {
SALog.d(TAG, ex.getMessage());
}
registerDefaultPropertiesPlugin();
}

private void registerDefaultPropertiesPlugin() {
SensorsDataPropertyPluginManager.getInstance().registerPropertyPlugin(new SAPresetPropertyPlugin(mContext, mDisableTrackDeviceId));
}

protected AbstractSensorsDataAPI() {
Expand Down Expand Up @@ -715,21 +722,22 @@ protected void trackEvent(final EventType eventType, String eventName, final JSO
}

try {
JSONObject sendProperties;

JSONObject sendProperties = new JSONObject();
if (eventType.isTrack()) {
Map<String, Object> deviceInfo = mSAContextManager.getDeviceInfo();
if (deviceInfo != null) {
sendProperties = new JSONObject(deviceInfo);
} else {
sendProperties = new JSONObject();
}
//之前可能会因为没有权限无法获取运营商信息,检测再次获取
getCarrier(sendProperties);
if (!"$AppEnd".equals(eventName) && !"$AppDeeplinkLaunch".equals(eventName)) {
//合并 $latest_utm 属性
SensorsDataUtils.mergeJSONObject(ChannelUtils.getLatestUtmProperties(), sendProperties);
}
}

// 将属性插件的属性合并到 sendProperties
sendProperties = SensorsDataUtils.mergeSuperJSONObject(
SensorsDataPropertyPluginManager.getInstance().properties(eventName, eventType, properties),
sendProperties);

if (eventType.isTrack()) {
mergerDynamicAndSuperProperties(sendProperties, dynamicProperty);

if (mReferrerScreenTitle != null) {
Expand Down Expand Up @@ -759,10 +767,10 @@ protected void trackEvent(final EventType eventType, String eventName, final JSO
} catch (Exception e) {
SALog.printStackTrace(e);
}
} else if (eventType.isProfile()) {
sendProperties = new JSONObject();
} else {
return;
if (!eventType.isProfile()) {
return;
}
}

// 禁用采集事件时,先计算基本信息存储到缓存中
Expand Down Expand Up @@ -849,19 +857,21 @@ protected void trackEventH5(String eventInfo) {
}
}

if (eventType.isTrack()) {
Map<String, Object> deviceInfo = mSAContextManager.getDeviceInfo();
if (deviceInfo != null) {
for (Map.Entry<String, Object> entry : deviceInfo.entrySet()) {
String key = entry.getKey();
if (!TextUtils.isEmpty(key)) {
if ("$lib".equals(key) || "$lib_version".equals(key)) {
continue;
}
propertiesObject.put(entry.getKey(), entry.getValue());
String eventName = eventObject.optString("event");
JSONObject deviceInfo = SensorsDataPropertyPluginManager.getInstance().properties(eventName, eventType, null);
if (deviceInfo != null) {
Iterator<String> iterator = deviceInfo.keys();
while (iterator.hasNext()) {
String key = iterator.next();
if (!TextUtils.isEmpty(key)) {
if ("$lib".equals(key) || "$lib_version".equals(key)) {
continue;
}
propertiesObject.put(key, deviceInfo.opt(key));
}
}
}
if (eventType.isTrack()) {
//之前可能会因为没有权限无法获取运营商信息,检测再次获取
getCarrier(propertiesObject);
// 当前网络状况
Expand Down Expand Up @@ -914,7 +924,6 @@ protected void trackEventH5(String eventInfo) {
propertiesObject.remove("$time");
}

String eventName = eventObject.optString("event");
if (eventType.isTrack()) {
// 校验 H5 事件名称
SADataHelper.assertEventName(eventName);
Expand Down Expand Up @@ -1508,7 +1517,7 @@ private void transformEventTaskQueue(final EventType eventType, final String eve
public void run() {
try {
if (eventType.isTrack()) {
JSONObject jsonObject = new JSONObject(mSAContextManager.getDeviceInfo());
JSONObject jsonObject = SensorsDataPropertyPluginManager.getInstance().properties(eventName, eventType, properties);
JSONUtils.mergeDistinctProperty(jsonObject, sendProperties);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import android.view.View;
import android.view.Window;

import com.sensorsdata.analytics.android.sdk.util.ViewUtil;
import com.sensorsdata.analytics.android.sdk.visual.ViewTreeStatusObservable;

import java.lang.ref.WeakReference;
Expand Down Expand Up @@ -160,6 +161,7 @@ public void onActivitySaveInstanceState(Activity activity, Bundle outState) {
@Override
public void onActivityDestroyed(Activity activity) {
ViewTreeStatusObservable.getInstance().clearWebViewCache();
ViewUtil.clear();
}

private void unRegisterViewTreeChange(View root) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
import com.sensorsdata.analytics.android.sdk.data.adapter.DbAdapter;
import com.sensorsdata.analytics.android.sdk.data.adapter.DbParams;
import com.sensorsdata.analytics.android.sdk.deeplink.SensorsDataDeepLinkCallback;
import com.sensorsdata.analytics.android.sdk.internal.rpc.SensorsDataContentObserver;
import com.sensorsdata.analytics.android.sdk.exceptions.InvalidDataException;
import com.sensorsdata.analytics.android.sdk.internal.beans.EventTimer;
import com.sensorsdata.analytics.android.sdk.internal.beans.EventType;
import com.sensorsdata.analytics.android.sdk.internal.rpc.SensorsDataContentObserver;
import com.sensorsdata.analytics.android.sdk.listener.SAFunctionListener;
import com.sensorsdata.analytics.android.sdk.remote.BaseSensorsDataSDKRemoteManager;
import com.sensorsdata.analytics.android.sdk.util.AopUtil;
Expand Down Expand Up @@ -1820,7 +1820,6 @@ public void run() {
mSAConfigOptions.isDataCollectEnable = true;
// 同意合规时重新判断当前进程是否主进程
mIsMainProcess = AppInfoUtils.isMainProcess(mContext, null);
mSAContextManager.getDeviceInfo();
mUserIdentityAPI.enableDataCollect(mSAContextManager.getAndroidId());
mTrackTaskManager.setDataCollectEnable(true);
// 同意合规时更新首日首次
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@ public enum EventType {
PROFILE_INCREMENT("profile_increment", false, true),
PROFILE_APPEND("profile_append", false, true),
PROFILE_DELETE("profile_delete", false, true),
REGISTER_SUPER_PROPERTIES("register_super_properties", false, false),
ITEM_SET("item_set", false, false),
ITEM_DELETE("item_delete", false, false),
DEFAULT("default", false, false);
DEFAULT("default", false, false),

/**
* 特殊枚举对象用于标记所有事件类型,不可用于触发事件设置类型
*/
ALL("all", false, false);

private String eventType;
private boolean track;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Created by luweibin on 2021/12/16.
* Copyright 2015-2021 Sensors Data Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.sensorsdata.analytics.android.sdk.plugin.property;

import com.sensorsdata.analytics.android.sdk.internal.beans.EventType;

import java.util.Map;
import java.util.Set;

interface ISAPropertyPlugin {
/**
* 向插件中添加静态属性
*
* @param properties 添加静态属性的 map 对象
*/
void appendProperties(Map<String, Object> properties);

/**
* 向插件中添加动态属性
*
* @param dynamicProperties 添加动态属性的 map 对象
*/
void appendDynamicProperties(Map<String, Object> dynamicProperties);

/**
* 指定插件允许添加属性的事件名
*
* @param eventNameFilter 添加事件名的 Set
*/
void eventNameFilter(Set<String> eventNameFilter);

/**
* 指定插件允许添加属性的事件类型
*
* @param eventTypeFilter 添加属性类型的对象
*/
void eventTypeFilter(Set<EventType> eventTypeFilter);

/**
* 指定插件允许添加属性,当事件已有的属性包含 Set 中任意一条属性名的时候,添加该插件的属性
* 例如:调用 SensorsDataAPI.track(String eventName, JSONObject properties) 接口
* 如果 properties 属性含有 propertyKeyFilter 中的任意一条属性 Key,就视为插件成功匹配
*
* @param propertyKeyFilter 已有属性名的 Set
*/
void propertyKeyFilter(Set<String> propertyKeyFilter);

/**
* 给插件指定属性的优先级
*
* @return 属性的优先级枚举对象
*/
SAPropertyPluginPriority priority();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* Created by luweibin on 2021/12/16.
* Copyright 2015-2021 Sensors Data Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.sensorsdata.analytics.android.sdk.plugin.property;

import android.content.Context;
import android.text.TextUtils;

import com.sensorsdata.analytics.android.sdk.SensorsDataAPI;
import com.sensorsdata.analytics.android.sdk.internal.beans.EventType;
import com.sensorsdata.analytics.android.sdk.util.AppInfoUtils;
import com.sensorsdata.analytics.android.sdk.util.Base64Coder;
import com.sensorsdata.analytics.android.sdk.util.DeviceUtils;
import com.sensorsdata.analytics.android.sdk.util.SensorsDataUtils;
import com.sensorsdata.analytics.android.sdk.util.TimeUtils;

import java.util.Map;
import java.util.Set;

/**
* 预置属性插件
*/
public final class SAPresetPropertyPlugin extends SAPropertyPlugin {
private final Context mContext;
private final boolean mDisableTrackDeviceId;

public SAPresetPropertyPlugin(Context context, boolean disableTrackDeviceId) {
this.mContext = context;
this.mDisableTrackDeviceId = disableTrackDeviceId;
}

@Override
public void appendProperties(Map<String, Object> properties) {
if (!SensorsDataAPI.getConfigOptions().isDataCollectEnable()) {
return;
}
String osVersion = DeviceUtils.getHarmonyOSVersion();
if (!TextUtils.isEmpty(osVersion)) {
properties.put("$os", "HarmonyOS");
properties.put("$os_version", osVersion);
} else {
properties.put("$os", "Android");
properties.put("$os_version", DeviceUtils.getOS());
}

properties.put("$lib", "Android");
properties.put("$lib_version", SensorsDataAPI.sharedInstance().getSDKVersion());
properties.put("$manufacturer", DeviceUtils.getManufacturer());
properties.put("$model", DeviceUtils.getModel());
properties.put("$brand", DeviceUtils.getBrand());
properties.put("$app_version", AppInfoUtils.getAppVersionName(mContext));
int[] size = DeviceUtils.getDeviceSize(mContext);
properties.put("$screen_width", size[0]);
properties.put("$screen_height", size[1]);

String carrier = SensorsDataUtils.getCarrier(mContext);
if (!TextUtils.isEmpty(carrier)) {
properties.put("$carrier", carrier);
}

Integer zone_offset = TimeUtils.getZoneOffset();
if (zone_offset != null) {
properties.put("$timezone_offset", zone_offset);
}

properties.put("$app_id", AppInfoUtils.getProcessName(mContext));
properties.put("$app_name", AppInfoUtils.getAppName(mContext));
String mAndroidId = SensorsDataUtils.getAndroidID(mContext);
if (!mDisableTrackDeviceId && !TextUtils.isEmpty(mAndroidId)) {
properties.put("$anonymization_id", Base64Coder.encodeString(mAndroidId));
}
}

@Override
public void appendDynamicProperties(Map<String, Object> dynamicProperties) {

}

@Override
public void eventNameFilter(Set<String> eventNameFilter) {

}

@Override
public void eventTypeFilter(Set<EventType> eventTypeFilter) {
eventTypeFilter.add(EventType.TRACK);
eventTypeFilter.add(EventType.TRACK_SIGNUP);
eventTypeFilter.add(EventType.TRACK_ID_BIND);
eventTypeFilter.add(EventType.TRACK_ID_UNBIND);
}

@Override
public void propertyKeyFilter(Set<String> propertyKeyFilter) {

}

@Override
public SAPropertyPluginPriority priority() {
return SAPropertyPluginPriority.LOW;
}
}
Loading

0 comments on commit 667f279

Please sign in to comment.