Skip to content

Commit

Permalink
Release 2.0.6
Browse files Browse the repository at this point in the history
  • Loading branch information
chenru committed Dec 4, 2020
1 parent 1cfb61f commit 0b5ab0a
Show file tree
Hide file tree
Showing 10 changed files with 424 additions and 103 deletions.
2 changes: 1 addition & 1 deletion RNSensorsAnalyticsModule.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

Pod::Spec.new do |s|
s.name = "RNSensorsAnalyticsModule"
s.version = "2.0.5"
s.version = "2.0.6"
s.summary = "The official React Native SDK of Sensors Analytics."
s.description = <<-DESC
神策分析 RN 组件
Expand Down
22 changes: 14 additions & 8 deletions SensorsDataRNHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ var reactNavigationPath = dir + '/react-navigation',
reactNavigationPath4X = dir + '/@react-navigation/native/lib/module',
reactNavigationPath5X = dir + '/@react-navigation/core/src/BaseNavigationContainer.tsx';
// 自定义变量
// RN 控制点击事件 Touchable.js 源码文件

var reactNavigationReduxCreatePath =[dir +'/react-navigation-redux-helpers/src/reduxify-navigator.js',
dir + '/react-navigation-redux-helpers/src/create-redux-container.js'];
Expand Down Expand Up @@ -198,7 +197,17 @@ var sensorsDataHookReduxCreateCode =
var sensorsDataHookReduxMiddleCode = `
if(oldState !== newState){
var type = action.type;
if(!(type == 'Navigation/SET_PARAMS' || type == 'Navigation/COMPLETE_TRANSITION')){
if(type === 'Navigation/BACK' ||
type === 'Navigation/NAVIGATE' ||
type === 'Navigation/POP' ||
type === 'Navigation/POP_TO_TOP' ||
type === 'Navigation/PUSH' ||
type === 'Navigation/RESET' ||
type === 'Navigation/REPLACE' ||
type === 'Navigation/GO_BACK' ||
type === 'Navigation/JUMP_TO' ||
type === 'Navigation/OPEN_DRAWER' ||
type === 'Navigation/CLOSE_DRAWER'){
function getParams(route){
if(!route){
return null;
Expand Down Expand Up @@ -254,7 +263,7 @@ var sensorsDataHookReduxMiddleCode = `
var dataModule = ReactNative?.NativeModules?.RNSensorsDataModule;
dataModule?.trackViewScreen && dataModule.trackViewScreen(saProperties);
}
trackViewScreen(newState.nav);
trackViewScreen(navStateSelector(newState));
/* SENSORSDATA HOOK */
}
}
Expand Down Expand Up @@ -304,9 +313,9 @@ sensorsdataHookPressabilityClickRN = function () {
// 插入 hook 代码
var hookedContent = `${fileContent.substring(
0,
hookIndex + scriptStr.length
hookIndex
)}\n${sensorsdataClickHookPressabilityCode}\n${fileContent.substring(
hookIndex + scriptStr.length
hookIndex
)}`;
// 备份 Pressability.js 源文件
fs.renameSync(RNClickPressabilityFilePath, `${RNClickPressabilityFilePath}_sensorsdata_backup`);
Expand Down Expand Up @@ -738,9 +747,6 @@ sensorsdataHookClickableRN = function (reset = false) {
saElement.type.displayName === 'RCTSegmentedControl'));
if(elementProps.onStartShouldSetResponder || isSegmentedControl) {
var saProps = eachProgress(saElement);
if(saProps){
console.log(saProps);
}
var ReactNative = require('react-native');
var dataModule = ReactNative.NativeModules.RNSensorsDataModule;
dataModule && dataModule.saveViewProperties && dataModule.saveViewProperties(${tagName}, true , saProps);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -633,26 +633,6 @@ public void deleteAll() {
}
}

/**
* 导出 trackChannelEvent 方法给 RN 使用.
*
* @param eventName 事件名称
* @param properties 事件的具体属性 RN 中使用示例:(记录 RN_AddToFav 事件,事件属性
* "ProductID":123456,"UserLevel":"VIP")
* <Button title="Button" onPress={()=>
* RNSensorsAnalyticsModule.trackChannelEvent("RN_AddToFav",{"ProductID":123456,"UserLevel":"VIP"})}>
* </Button>
*/
@ReactMethod
public void trackChannelEvent(String eventName, ReadableMap properties) {
try {
SensorsDataAPI.sharedInstance().trackChannelEvent(eventName, RNUtils.convertToJSONObject(properties));
} catch (Exception e) {
e.printStackTrace();
Log.e(LOGTAG, e.toString() + "");
}
}

/**
* 导出 identify 方法给 RN 使用.
* <p>
Expand Down Expand Up @@ -866,6 +846,7 @@ public void getLoginIdPromise(Promise promise) {
* 默认值为 30*1000 毫秒
* 若 App 在后台超过设定事件,则认为当前 Session 结束,发送 $AppEnd 事件
*
* @platform Android
* @param sessionIntervalTime int
*/
@ReactMethod
Expand All @@ -878,6 +859,7 @@ public void setSessionIntervalTime(int sessionIntervalTime) {
* 默认值为 30*1000 毫秒
* 若 App 在后台超过设定事件,则认为当前 Session 结束,发送 $AppEnd 事件
*
* @platform Android
* @return 返回设置的 SessionIntervalTime ,默认是 30s
*/
@ReactMethod
Expand Down Expand Up @@ -975,6 +957,7 @@ public void setFlushNetworkPolicy(int networkType){
/**
* 设置是否允许请求网络,默认是 true
*
* @platform Android
* @param isRequest boolean
*/
@ReactMethod
Expand All @@ -990,6 +973,7 @@ public void enableNetworkRequest(boolean isRequest){
/**
* 是否允许请求网络,默认是 true
*
* @platform Android
* @return 是否允许请求网络
*/
@ReactMethod
Expand All @@ -1005,4 +989,21 @@ public void isNetworkRequestEnablePromise(Promise promise){
promise.reject("isNetworkRequestEnable failed", e);
}
}

/**
* 记录 $AppInstall 事件,用于在 App 首次启动时追踪渠道来源,并设置追踪渠道事件的属性。
* 这是 Sensors Analytics 进阶功能,请参考文档 https://sensorsdata.cn/manual/track_installation.html
*
* @param properties 渠道追踪事件的属性
*/
@ReactMethod
public void trackAppInstall(ReadableMap properties) {
try {
//解决版本限制,防止集成旧版本 SDK 没有 trackAppInstall() 方法.
SensorsDataAPI.sharedInstance().trackInstallation("$AppInstall", RNUtils.convertToJSONObject(properties));
} catch (Exception e) {
e.printStackTrace();
Log.e(LOGTAG, e.toString() + "");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

public class RNSensorsAnalyticsPackage implements ReactPackage {
public static final String VERSION = "2.0.5";
public static final String VERSION = "2.0.6";
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
Expand Down
Loading

0 comments on commit 0b5ab0a

Please sign in to comment.