Skip to content

Commit 66fea3a

Browse files
committed
更新
1 parent 30cc359 commit 66fea3a

14 files changed

+339
-173
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 1.13.21(2020-04-07)
2+
* 优化:优化预置事件 $MPLaunch、 $MPShow 中 $share_depth 的计算逻辑;
3+
* 新增:新增所有事件都有的预置属性 $latest_share_depth、 $latest_share_distinct_id、 $lastest_share_url_path,神策分析系统需升级到 1.14.745 1.16.1414 1.15.1413 1.13.5875 及以上版本;
4+
15
## 1.13.20(2020-03-19)
26
* 修复:修复点击处理函数参数为 null 时,点击预置事件报错问题;
37

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sa-sdk-miniprogram",
3-
"version": "1.13.20",
3+
"version": "1.13.21",
44
"description": "sensorsdata miniprogram sdk",
55
"main": "sensorsdata.min.js",
66
"scripts": {

product/sensorsdata.custom.es6.full.js

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ sa.para = {
2020
pageShare: true,
2121
mpClick: false,
2222
},
23-
is_persistent_save: false
23+
is_persistent_save: {
24+
share: false,
25+
utm: false
26+
}
2427
};
2528

2629
var mpHook = {
@@ -92,11 +95,23 @@ sa.setPara = function(para) {
9295
if (sa.para.batch_send === true) {
9396
sa.para.batch_send = _.extend({}, batch_send_default);
9497
sa.para.use_client_time = true;
95-
} else if (typeof sa.para.batch_send === 'object') {
98+
} else if (_.isObject(sa.para.batch_send)) {
9699
sa.para.use_client_time = true;
97100
sa.para.batch_send = _.extend({}, batch_send_default, sa.para.batch_send);
98101
}
99102

103+
var is_persistent_save_default = {
104+
share: false,
105+
utm: false
106+
};
107+
108+
if (sa.para.is_persistent_save === true) {
109+
sa.para.is_persistent_save = _.extend({}, is_persistent_save_default);
110+
sa.para.is_persistent_save.utm = true;
111+
} else if (_.isObject(sa.para.is_persistent_save)) {
112+
sa.para.is_persistent_save = _.extend({}, is_persistent_save_default, sa.para.is_persistent_save);
113+
}
114+
100115
if (!sa.para.server_url) {
101116
logger.info('请使用 setPara() 方法设置 server_url 数据接收地址,详情可查看https://www.sensorsdata.cn/manual/mp_sdk_new.html#112-%E5%BC%95%E5%85%A5%E5%B9%B6%E9%85%8D%E7%BD%AE%E5%8F%82%E6%95%B0');
102117
return;
@@ -114,11 +129,12 @@ var ArrayProto = Array.prototype,
114129
slice = ArrayProto.slice,
115130
toString = ObjProto.toString,
116131
hasOwnProperty = ObjProto.hasOwnProperty,
117-
LIB_VERSION = '1.13.20',
132+
LIB_VERSION = '1.13.21',
118133
LIB_NAME = 'MiniProgram';
119134

120135
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
121136
var latest_source_channel = ['$latest_utm_source', '$latest_utm_medium', '$latest_utm_campaign', '$latest_utm_content', '$latest_utm_term', 'latest_sa_utm'];
137+
var latest_share_info = ['$latest_share_distinct_id', '$latest_share_url_path', '$latest_share_depth'];
122138

123139
var mp_scene = {
124140
1000: '其他',
@@ -212,7 +228,7 @@ sa.status.referrer = '直接打开';
212228

213229
var mpshow_time = null;
214230

215-
var share_depth = 0;
231+
var query_share_depth = 0;
216232
var share_distinct_id = '';
217233

218234
var is_first_launch = false;
@@ -764,23 +780,11 @@ _.getMPScene = function(key) {
764780
}
765781
};
766782

767-
_.getShareDepth = function() {
768-
if (typeof share_depth === 'number' && share_depth !== 0) {
769-
var current_id = sa.store.getDistinctId();
770-
var current_first_id = sa.store.getFirstId();
771-
var latest_id = share_distinct_id;
772-
if (latest_id && (latest_id === current_id || latest_id === current_first_id)) {
773-
return share_depth;
774-
} else {
775-
return (share_depth + 1);
776-
}
777-
} else {
778-
return 1;
779-
}
780-
};
781-
782783
_.setShareInfo = function(para, prop) {
783784
var share = {};
785+
var obj = {};
786+
var current_id = sa.store.getDistinctId();
787+
var current_first_id = sa.store.getFirstId();
784788
if (para && _.isObject(para.query) && para.query.sampshare) {
785789
share = _.decodeURIComponent(para.query.sampshare);
786790
if (_.isJSONString(share)) {
@@ -797,27 +801,41 @@ _.setShareInfo = function(para, prop) {
797801
if (typeof id === 'string') {
798802
prop.$share_distinct_id = id;
799803
share_distinct_id = id;
804+
obj.$latest_share_distinct_id = id;
800805
} else {
801806
prop.$share_distinct_id = '取值异常';
802807
}
808+
809+
803810
if (typeof depth === 'number') {
804-
prop.$share_depth = depth;
805-
share_depth = depth;
811+
if (share_distinct_id && (share_distinct_id === current_id || share_distinct_id === current_first_id)) {
812+
prop.$share_depth = depth;
813+
query_share_depth = depth;
814+
obj.$latest_share_depth = depth;
815+
} else if (share_distinct_id && (share_distinct_id !== current_id || share_distinct_id !== current_first_id)) {
816+
prop.$share_depth = depth + 1;
817+
query_share_depth = depth + 1;
818+
obj.$latest_share_depth = depth + 1;
819+
} else {
820+
prop.$share_depth = '-1';
821+
}
806822
} else {
807823
prop.$share_depth = '-1';
808824
}
809825
if (typeof path === 'string') {
810826
prop.$share_url_path = path;
827+
obj.$latest_share_url_path = path;
811828
} else {
812829
prop.$share_url_path = '取值异常';
813830
}
831+
_.setLatestShare(obj);
814832
};
815833

816834
_.getShareInfo = function() {
817835
return JSON.stringify({
818836
i: sa.store.getDistinctId() || '取值异常',
819837
p: _.getCurrentPath(),
820-
d: _.getShareDepth()
838+
d: query_share_depth
821839
});
822840
};
823841

@@ -1271,13 +1289,13 @@ sa.clearAppRegister = function(arr) {
12711289
}
12721290
};
12731291

1274-
sa.setLatestChannel = function(channel) {
1292+
_.setLatestChannel = function(channel) {
12751293
if (!_.isEmptyObject(channel)) {
12761294
if (includeChannel(channel, latest_source_channel)) {
12771295
sa.clearAppRegister(latest_source_channel);
12781296
sa.clearAllProps(latest_source_channel);
12791297
}
1280-
sa.para.is_persistent_save ? sa.register(channel) : sa.registerApp(channel);
1298+
sa.para.is_persistent_save.utm ? sa.register(channel) : sa.registerApp(channel);
12811299
}
12821300

12831301
function includeChannel(channel, arr) {
@@ -1289,7 +1307,16 @@ sa.setLatestChannel = function(channel) {
12891307
}
12901308
return found;
12911309
}
1292-
}
1310+
};
1311+
1312+
_.setLatestShare = function(share) {
1313+
if (share.$latest_share_depth || share.$latest_share_distinct_id || share.$latest_share_url_path) {
1314+
sa.clearAppRegister(latest_share_info);
1315+
sa.clearAllProps(latest_share_info);
1316+
1317+
sa.para.is_persistent_save.share ? sa.register(share) : sa.registerApp(share);
1318+
}
1319+
};
12931320

12941321
sa.login = function(id) {
12951322
if (typeof id !== 'string' && typeof id !== 'number') {
@@ -1702,7 +1729,7 @@ sa.autoTrackCustom = {
17021729
prop.$is_first_time = false;
17031730
}
17041731

1705-
sa.setLatestChannel(utms.pre2);
1732+
_.setLatestChannel(utms.pre2);
17061733

17071734
prop.$scene = _.getMPScene(para.scene);
17081735
sa.registerApp({
@@ -1731,7 +1758,7 @@ sa.autoTrackCustom = {
17311758

17321759
var utms = _.setUtm(para, prop);
17331760

1734-
sa.setLatestChannel(utms.pre2);
1761+
_.setLatestChannel(utms.pre2);
17351762

17361763
prop.$scene = _.getMPScene(para.scene);
17371764
sa.registerApp({

product/sensorsdata.custom.full.js

Lines changed: 54 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ sa.para = {
2020
pageShare: true,
2121
mpClick: false,
2222
},
23-
is_persistent_save: false
23+
is_persistent_save: {
24+
share: false,
25+
utm: false
26+
}
2427
};
2528

2629
var mpHook = {
@@ -92,11 +95,23 @@ sa.setPara = function(para) {
9295
if (sa.para.batch_send === true) {
9396
sa.para.batch_send = _.extend({}, batch_send_default);
9497
sa.para.use_client_time = true;
95-
} else if (typeof sa.para.batch_send === 'object') {
98+
} else if (_.isObject(sa.para.batch_send)) {
9699
sa.para.use_client_time = true;
97100
sa.para.batch_send = _.extend({}, batch_send_default, sa.para.batch_send);
98101
}
99102

103+
var is_persistent_save_default = {
104+
share: false,
105+
utm: false
106+
};
107+
108+
if (sa.para.is_persistent_save === true) {
109+
sa.para.is_persistent_save = _.extend({}, is_persistent_save_default);
110+
sa.para.is_persistent_save.utm = true;
111+
} else if (_.isObject(sa.para.is_persistent_save)) {
112+
sa.para.is_persistent_save = _.extend({}, is_persistent_save_default, sa.para.is_persistent_save);
113+
}
114+
100115
if (!sa.para.server_url) {
101116
logger.info('请使用 setPara() 方法设置 server_url 数据接收地址,详情可查看https://www.sensorsdata.cn/manual/mp_sdk_new.html#112-%E5%BC%95%E5%85%A5%E5%B9%B6%E9%85%8D%E7%BD%AE%E5%8F%82%E6%95%B0');
102117
return;
@@ -114,11 +129,12 @@ var ArrayProto = Array.prototype,
114129
slice = ArrayProto.slice,
115130
toString = ObjProto.toString,
116131
hasOwnProperty = ObjProto.hasOwnProperty,
117-
LIB_VERSION = '1.13.20',
132+
LIB_VERSION = '1.13.21',
118133
LIB_NAME = 'MiniProgram';
119134

120135
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
121136
var latest_source_channel = ['$latest_utm_source', '$latest_utm_medium', '$latest_utm_campaign', '$latest_utm_content', '$latest_utm_term', 'latest_sa_utm'];
137+
var latest_share_info = ['$latest_share_distinct_id', '$latest_share_url_path', '$latest_share_depth'];
122138

123139
var mp_scene = {
124140
1000: '其他',
@@ -212,7 +228,7 @@ sa.status.referrer = '直接打开';
212228

213229
var mpshow_time = null;
214230

215-
var share_depth = 0;
231+
var query_share_depth = 0;
216232
var share_distinct_id = '';
217233

218234
var is_first_launch = false;
@@ -764,23 +780,11 @@ _.getMPScene = function(key) {
764780
}
765781
};
766782

767-
_.getShareDepth = function() {
768-
if (typeof share_depth === 'number' && share_depth !== 0) {
769-
var current_id = sa.store.getDistinctId();
770-
var current_first_id = sa.store.getFirstId();
771-
var latest_id = share_distinct_id;
772-
if (latest_id && (latest_id === current_id || latest_id === current_first_id)) {
773-
return share_depth;
774-
} else {
775-
return (share_depth + 1);
776-
}
777-
} else {
778-
return 1;
779-
}
780-
};
781-
782783
_.setShareInfo = function(para, prop) {
783784
var share = {};
785+
var obj = {};
786+
var current_id = sa.store.getDistinctId();
787+
var current_first_id = sa.store.getFirstId();
784788
if (para && _.isObject(para.query) && para.query.sampshare) {
785789
share = _.decodeURIComponent(para.query.sampshare);
786790
if (_.isJSONString(share)) {
@@ -797,27 +801,41 @@ _.setShareInfo = function(para, prop) {
797801
if (typeof id === 'string') {
798802
prop.$share_distinct_id = id;
799803
share_distinct_id = id;
804+
obj.$latest_share_distinct_id = id;
800805
} else {
801806
prop.$share_distinct_id = '取值异常';
802807
}
808+
809+
803810
if (typeof depth === 'number') {
804-
prop.$share_depth = depth;
805-
share_depth = depth;
811+
if (share_distinct_id && (share_distinct_id === current_id || share_distinct_id === current_first_id)) {
812+
prop.$share_depth = depth;
813+
query_share_depth = depth;
814+
obj.$latest_share_depth = depth;
815+
} else if (share_distinct_id && (share_distinct_id !== current_id || share_distinct_id !== current_first_id)) {
816+
prop.$share_depth = depth + 1;
817+
query_share_depth = depth + 1;
818+
obj.$latest_share_depth = depth + 1;
819+
} else {
820+
prop.$share_depth = '-1';
821+
}
806822
} else {
807823
prop.$share_depth = '-1';
808824
}
809825
if (typeof path === 'string') {
810826
prop.$share_url_path = path;
827+
obj.$latest_share_url_path = path;
811828
} else {
812829
prop.$share_url_path = '取值异常';
813830
}
831+
_.setLatestShare(obj);
814832
};
815833

816834
_.getShareInfo = function() {
817835
return JSON.stringify({
818836
i: sa.store.getDistinctId() || '取值异常',
819837
p: _.getCurrentPath(),
820-
d: _.getShareDepth()
838+
d: query_share_depth
821839
});
822840
};
823841

@@ -1271,13 +1289,13 @@ sa.clearAppRegister = function(arr) {
12711289
}
12721290
};
12731291

1274-
sa.setLatestChannel = function(channel) {
1292+
_.setLatestChannel = function(channel) {
12751293
if (!_.isEmptyObject(channel)) {
12761294
if (includeChannel(channel, latest_source_channel)) {
12771295
sa.clearAppRegister(latest_source_channel);
12781296
sa.clearAllProps(latest_source_channel);
12791297
}
1280-
sa.para.is_persistent_save ? sa.register(channel) : sa.registerApp(channel);
1298+
sa.para.is_persistent_save.utm ? sa.register(channel) : sa.registerApp(channel);
12811299
}
12821300

12831301
function includeChannel(channel, arr) {
@@ -1289,7 +1307,16 @@ sa.setLatestChannel = function(channel) {
12891307
}
12901308
return found;
12911309
}
1292-
}
1310+
};
1311+
1312+
_.setLatestShare = function(share) {
1313+
if (share.$latest_share_depth || share.$latest_share_distinct_id || share.$latest_share_url_path) {
1314+
sa.clearAppRegister(latest_share_info);
1315+
sa.clearAllProps(latest_share_info);
1316+
1317+
sa.para.is_persistent_save.share ? sa.register(share) : sa.registerApp(share);
1318+
}
1319+
};
12931320

12941321
sa.login = function(id) {
12951322
if (typeof id !== 'string' && typeof id !== 'number') {
@@ -1702,7 +1729,7 @@ sa.autoTrackCustom = {
17021729
prop.$is_first_time = false;
17031730
}
17041731

1705-
sa.setLatestChannel(utms.pre2);
1732+
_.setLatestChannel(utms.pre2);
17061733

17071734
prop.$scene = _.getMPScene(para.scene);
17081735
sa.registerApp({
@@ -1731,7 +1758,7 @@ sa.autoTrackCustom = {
17311758

17321759
var utms = _.setUtm(para, prop);
17331760

1734-
sa.setLatestChannel(utms.pre2);
1761+
_.setLatestChannel(utms.pre2);
17351762

17361763
prop.$scene = _.getMPScene(para.scene);
17371764
sa.registerApp({

0 commit comments

Comments
 (0)