-
Notifications
You must be signed in to change notification settings - Fork 434
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
weiqiangliu
committed
Jan 20, 2022
1 parent
932dcac
commit 667f279
Showing
28 changed files
with
1,730 additions
and
575 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...rc/main/java/com/sensorsdata/analytics/android/sdk/plugin/property/ISAPropertyPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |
115 changes: 115 additions & 0 deletions
115
...in/java/com/sensorsdata/analytics/android/sdk/plugin/property/SAPresetPropertyPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.