Skip to content

Commit 5900464

Browse files
committed
更新
1 parent b3244c4 commit 5900464

15 files changed

+438
-36
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.17(2020-03-05)
2+
* 新增:新增预置点击事件 $MPClick 采集功能;
3+
* 新增:新增 logout() 接口;
4+
15
## 1.13.17(2020-02-17)
26
* 优化:优化 identify() 接口逻辑;
37
* 优化:批量发送方式下,默认请求取消时长修改为 10s;

README.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,14 @@
2020

2121
请参见 [CHANGELOG.md](CHANGELOG.md)
2222

23-
## 开源社区
24-
神策正在组建开源社区,所以相应的源码也会放在 GitHub 上。
25-
针对微信小程序 SDK 源码的问题请不要在 GitHub 上提问,请加微信号 free__dom (两个下划线)私聊。
26-
如果是咨询神策收费,以及 SDK 使用问题,请扫码加入神策官方 SDK QQ 讨论群;群号:785122381<br><br>
27-
![ QQ 讨论群](https://raw.githubusercontent.com/sensorsdata/sa-sdk-android/master/docs/qrCode.jpeg)
23+
## 讨论
24+
25+
| 扫码加入神策数据开源社区 QQ 群<br>群号:785122381 | 扫码加入神策数据开源社区微信群 |
26+
| ------ | ------ |
27+
|![ QQ 讨论群](https://raw.githubusercontent.com/richardhxy/OpensourceQRCode/master/docs/qrCode_for_qq.jpg) | ![ 微信讨论群 ](https://raw.githubusercontent.com/richardhxy/OpensourceQRCode/master/docs/qrcode_for_wechat.JPG) |
28+
29+
## 公众号
30+
31+
| 扫码关注<br>神策数据开源社区 | 扫码关注<br>神策数据开源社区服务号 |
32+
| ------ | ------ |
33+
|![ 微信订阅号 ](https://raw.githubusercontent.com/richardhxy/OpensourceQRCode/master/docs/qrcode_for_wechat_subscription_account.jpg) | ![ 微信服务号 ](https://raw.githubusercontent.com/richardhxy/OpensourceQRCode/master/docs/qrcode_for_wechat_service_account.jpg) |

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.17",
3+
"version": "1.13.18",
44
"description": "sensorsdata miniprogram sdk",
55
"main": "sensorsdata.min.js",
66
"scripts": {

product/sensorsdata.custom.es6.full.js

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ sa.para = {
2222
is_persistent_save: false
2323
};
2424

25+
var mpHook = {
26+
"data": 1,
27+
"onLoad": 1,
28+
"onShow": 1,
29+
"onReady": 1,
30+
"onPullDownRefresh": 1,
31+
"onReachBottom": 1,
32+
"onShareAppMessage": 1,
33+
"onPageScroll": 1,
34+
"onResize": 1,
35+
"onTabItemTap": 1,
36+
"onHide": 1,
37+
"onUnload": 1
38+
};
2539

2640
var logger = typeof logger === 'object' ? logger : {};
2741

@@ -99,7 +113,7 @@ var ArrayProto = Array.prototype,
99113
slice = ArrayProto.slice,
100114
toString = ObjProto.toString,
101115
hasOwnProperty = ObjProto.hasOwnProperty,
102-
LIB_VERSION = '1.13.17',
116+
LIB_VERSION = '1.13.18',
103117
LIB_NAME = 'MiniProgram';
104118

105119
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -627,6 +641,25 @@ _.getPath = function(path) {
627641
return path;
628642
};
629643

644+
_.getMethods = function(option) {
645+
var methods = [];
646+
for (var m in option) {
647+
if (typeof(option[m]) === 'function' && !mpHook[m]) {
648+
methods.push(m);
649+
}
650+
}
651+
return methods;
652+
}
653+
654+
_.isClick = function(type) {
655+
var mpTaps = {
656+
"tap": 1,
657+
"longpress": 1,
658+
"longtap": 1,
659+
};
660+
return !!mpTaps[type];
661+
}
662+
630663
sa.initialState = {
631664
queue: [],
632665
isComplete: false,
@@ -1275,6 +1308,20 @@ sa.login = function(id) {
12751308
}
12761309
};
12771310

1311+
sa.logout = function(isChangeId) {
1312+
var firstId = sa.store.getFirstId();
1313+
if (firstId) {
1314+
sa.store.set('first_id', '');
1315+
if (isChangeId === true) {
1316+
sa.store.set('distinct_id', sa.store.getUUID());
1317+
} else {
1318+
sa.store.set('distinct_id', firstId);
1319+
}
1320+
} else {
1321+
logger.info('没有first_id,logout失败');
1322+
}
1323+
};
1324+
12781325
sa.openid = {
12791326
getRequest: function(callback) {
12801327
wx.login({
@@ -1541,9 +1588,7 @@ sa.sendStrategy = {
15411588
}
15421589
loopWrite();
15431590
loopSend();
1544-
15451591
}
1546-
15471592
};
15481593

15491594
sa.setOpenid = function(openid, isCover) {
@@ -1571,7 +1616,7 @@ sa.initWithOpenid = function(options, callback) {
15711616
});
15721617
};
15731618

1574-
_.each(['setProfile', 'setOnceProfile', 'track', 'quick', 'incrementProfile', 'appendProfile'], function(method) {
1619+
_.each(['setProfile', 'setOnceProfile', 'track', 'quick', 'incrementProfile', 'appendProfile', 'login', 'logout'], function(method) {
15751620
var temp = sa[method];
15761621
sa[method] = function() {
15771622
if (sa.initialState.isComplete) {

product/sensorsdata.custom.full.js

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ sa.para = {
2222
is_persistent_save: false
2323
};
2424

25+
var mpHook = {
26+
"data": 1,
27+
"onLoad": 1,
28+
"onShow": 1,
29+
"onReady": 1,
30+
"onPullDownRefresh": 1,
31+
"onReachBottom": 1,
32+
"onShareAppMessage": 1,
33+
"onPageScroll": 1,
34+
"onResize": 1,
35+
"onTabItemTap": 1,
36+
"onHide": 1,
37+
"onUnload": 1
38+
};
2539

2640
var logger = typeof logger === 'object' ? logger : {};
2741

@@ -99,7 +113,7 @@ var ArrayProto = Array.prototype,
99113
slice = ArrayProto.slice,
100114
toString = ObjProto.toString,
101115
hasOwnProperty = ObjProto.hasOwnProperty,
102-
LIB_VERSION = '1.13.17',
116+
LIB_VERSION = '1.13.18',
103117
LIB_NAME = 'MiniProgram';
104118

105119
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -627,6 +641,25 @@ _.getPath = function(path) {
627641
return path;
628642
};
629643

644+
_.getMethods = function(option) {
645+
var methods = [];
646+
for (var m in option) {
647+
if (typeof(option[m]) === 'function' && !mpHook[m]) {
648+
methods.push(m);
649+
}
650+
}
651+
return methods;
652+
}
653+
654+
_.isClick = function(type) {
655+
var mpTaps = {
656+
"tap": 1,
657+
"longpress": 1,
658+
"longtap": 1,
659+
};
660+
return !!mpTaps[type];
661+
}
662+
630663
sa.initialState = {
631664
queue: [],
632665
isComplete: false,
@@ -1275,6 +1308,20 @@ sa.login = function(id) {
12751308
}
12761309
};
12771310

1311+
sa.logout = function(isChangeId) {
1312+
var firstId = sa.store.getFirstId();
1313+
if (firstId) {
1314+
sa.store.set('first_id', '');
1315+
if (isChangeId === true) {
1316+
sa.store.set('distinct_id', sa.store.getUUID());
1317+
} else {
1318+
sa.store.set('distinct_id', firstId);
1319+
}
1320+
} else {
1321+
logger.info('没有first_id,logout失败');
1322+
}
1323+
};
1324+
12781325
sa.openid = {
12791326
getRequest: function(callback) {
12801327
wx.login({
@@ -1541,9 +1588,7 @@ sa.sendStrategy = {
15411588
}
15421589
loopWrite();
15431590
loopSend();
1544-
15451591
}
1546-
15471592
};
15481593

15491594
sa.setOpenid = function(openid, isCover) {
@@ -1571,7 +1616,7 @@ sa.initWithOpenid = function(options, callback) {
15711616
});
15721617
};
15731618

1574-
_.each(['setProfile', 'setOnceProfile', 'track', 'quick', 'incrementProfile', 'appendProfile'], function(method) {
1619+
_.each(['setProfile', 'setOnceProfile', 'track', 'quick', 'incrementProfile', 'appendProfile', 'login', 'logout'], function(method) {
15751620
var temp = sa[method];
15761621
sa[method] = function() {
15771622
if (sa.initialState.isComplete) {

product/sensorsdata.es6.full.js

Lines changed: 86 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ sa.para = {
2222
is_persistent_save: false
2323
};
2424

25+
var mpHook = {
26+
"data": 1,
27+
"onLoad": 1,
28+
"onShow": 1,
29+
"onReady": 1,
30+
"onPullDownRefresh": 1,
31+
"onReachBottom": 1,
32+
"onShareAppMessage": 1,
33+
"onPageScroll": 1,
34+
"onResize": 1,
35+
"onTabItemTap": 1,
36+
"onHide": 1,
37+
"onUnload": 1
38+
};
2539

2640
var logger = typeof logger === 'object' ? logger : {};
2741

@@ -99,7 +113,7 @@ var ArrayProto = Array.prototype,
99113
slice = ArrayProto.slice,
100114
toString = ObjProto.toString,
101115
hasOwnProperty = ObjProto.hasOwnProperty,
102-
LIB_VERSION = '1.13.17',
116+
LIB_VERSION = '1.13.18',
103117
LIB_NAME = 'MiniProgram';
104118

105119
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -627,6 +641,25 @@ _.getPath = function(path) {
627641
return path;
628642
};
629643

644+
_.getMethods = function(option) {
645+
var methods = [];
646+
for (var m in option) {
647+
if (typeof(option[m]) === 'function' && !mpHook[m]) {
648+
methods.push(m);
649+
}
650+
}
651+
return methods;
652+
}
653+
654+
_.isClick = function(type) {
655+
var mpTaps = {
656+
"tap": 1,
657+
"longpress": 1,
658+
"longtap": 1,
659+
};
660+
return !!mpTaps[type];
661+
}
662+
630663
sa.initialState = {
631664
queue: [],
632665
isComplete: false,
@@ -1275,6 +1308,20 @@ sa.login = function(id) {
12751308
}
12761309
};
12771310

1311+
sa.logout = function(isChangeId) {
1312+
var firstId = sa.store.getFirstId();
1313+
if (firstId) {
1314+
sa.store.set('first_id', '');
1315+
if (isChangeId === true) {
1316+
sa.store.set('distinct_id', sa.store.getUUID());
1317+
} else {
1318+
sa.store.set('distinct_id', firstId);
1319+
}
1320+
} else {
1321+
logger.info('没有first_id,logout失败');
1322+
}
1323+
};
1324+
12781325
sa.openid = {
12791326
getRequest: function(callback) {
12801327
wx.login({
@@ -1541,9 +1588,7 @@ sa.sendStrategy = {
15411588
}
15421589
loopWrite();
15431590
loopSend();
1544-
15451591
}
1546-
15471592
};
15481593

15491594
sa.setOpenid = function(openid, isCover) {
@@ -1571,7 +1616,7 @@ sa.initWithOpenid = function(options, callback) {
15711616
});
15721617
};
15731618

1574-
_.each(['setProfile', 'setOnceProfile', 'track', 'quick', 'incrementProfile', 'appendProfile'], function(method) {
1619+
_.each(['setProfile', 'setOnceProfile', 'track', 'quick', 'incrementProfile', 'appendProfile', 'login', 'logout'], function(method) {
15751620
var temp = sa[method];
15761621
sa[method] = function() {
15771622
if (sa.initialState.isComplete) {
@@ -1640,6 +1685,30 @@ function mp_proxy(option, method, identifier) {
16401685
}
16411686
}
16421687

1688+
function click_proxy(option, method) {
1689+
var oldFunc = option[method];
1690+
1691+
option[method] = function() {
1692+
var prop = {},
1693+
type = '';
1694+
1695+
if (typeof arguments[0] === 'object') {
1696+
var target = arguments[0].currentTarget || {};
1697+
var dataset = target.dataset || {};
1698+
type = arguments[0]['type'];
1699+
prop['$url_path'] = _.getCurrentPath();
1700+
prop['$element_id'] = target.id;
1701+
prop['$element_type'] = dataset['type'];
1702+
prop['$element_content'] = dataset['content'];
1703+
prop['$element_name'] = dataset['name'];
1704+
}
1705+
if (type && _.isClick(type)) {
1706+
sa.track('$MPClick', prop);
1707+
}
1708+
return oldFunc && oldFunc.apply(this, arguments);
1709+
}
1710+
};
1711+
16431712

16441713
sa.autoTrackCustom = {
16451714
trackCustom: function(api, prop, event) {
@@ -1845,6 +1914,13 @@ App = function(option) {
18451914

18461915
var oldPage = Page;
18471916
Page = function(option) {
1917+
1918+
var methods = _.getMethods(option);
1919+
1920+
for (let i = 0, len = methods.length; i < len; i++) {
1921+
click_proxy(option, methods[i]);
1922+
}
1923+
18481924
mp_proxy(option, "onLoad", 'pageLoad');
18491925
mp_proxy(option, "onShow", 'pageShow');
18501926
if (typeof option.onShareAppMessage === 'function') {
@@ -1857,6 +1933,12 @@ var oldComponent = Component;
18571933
Component = function(option) {
18581934
try {
18591935
option.methods = option.methods || {};
1936+
var methods = _.getMethods(option.methods);
1937+
1938+
for (let i = 0, len = methods.length; i < len; i++) {
1939+
click_proxy(option.methods, methods[i]);
1940+
}
1941+
18601942
mp_proxy(option.methods, 'onLoad', 'pageLoad');
18611943
mp_proxy(option.methods, 'onShow', 'pageShow');
18621944
if (typeof option.methods.onShareAppMessage === 'function') {

0 commit comments

Comments
 (0)