Skip to content

Commit 5acf607

Browse files
author
shengyonggen
committed
Release 1.14.12
1 parent b4c995b commit 5acf607

14 files changed

+878
-31
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,14 @@
1+
## 1.14.12(2021-06-26)
2+
1. 新增
3+
- 支持在微信小程序中跟内嵌 `H5` 打通
4+
- 支持对特定控件不采集全埋点点击事件
5+
- 支持分享到朋友圈单页模式下页面的数据采集
6+
17
## 1.14.11(2021-06-10)
28
1. 新增
39
- 新增 `tabBar` 点击事件自动采集
410
- 新增 `getServerUrl` 接口
11+
- 默认开启批量发送
512
2. 修复
613
- 修复 `ES6` 语法报错问题
714

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

product/sensorsdata.custom.es6.full.js

Lines changed: 138 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ sa.para = {
3030
},
3131

3232
preset_properties: {},
33-
33+
preset_events: {
34+
moments_page: false,
35+
},
3436
batch_send: true
3537
};
3638

@@ -148,7 +150,7 @@ var ArrayProto = Array.prototype,
148150
slice = ArrayProto.slice,
149151
toString = ObjProto.toString,
150152
hasOwnProperty = ObjProto.hasOwnProperty,
151-
LIB_VERSION = '1.14.11',
153+
LIB_VERSION = '1.14.12',
152154
LIB_NAME = 'MiniProgram';
153155

154156
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -579,6 +581,80 @@ _.base64Encode = function(data) {
579581
return enc;
580582
};
581583

584+
_.urlSafeBase64 = (function() {
585+
var ENC = {
586+
'+': '-',
587+
'/': '_',
588+
'=': '.'
589+
};
590+
var DEC = {
591+
'-': '+',
592+
_: '/',
593+
'.': '='
594+
};
595+
596+
var encode = function(base64) {
597+
return base64.replace(/[+/=]/g, function(m) {
598+
return ENC[m];
599+
});
600+
};
601+
602+
var decode = function(safe) {
603+
return safe.replace(/[-_.]/g, function(m) {
604+
return DEC[m];
605+
});
606+
};
607+
608+
var trim = function(string) {
609+
return string.replace(/[.=]{1,2}$/, '');
610+
};
611+
612+
var isBase64 = function(string) {
613+
return /^[A-Za-z0-9+/]*[=]{0,2}$/.test(string);
614+
};
615+
616+
var isUrlSafeBase64 = function(string) {
617+
return /^[A-Za-z0-9_-]*[.]{0,2}$/.test(string);
618+
};
619+
620+
return {
621+
encode: encode,
622+
decode: decode,
623+
trim: trim,
624+
isBase64: isBase64,
625+
isUrlSafeBase64: isUrlSafeBase64
626+
};
627+
})();
628+
629+
_.btoa = function(string) {
630+
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
631+
string = String(string)
632+
var bitmap,
633+
a,
634+
b,
635+
c,
636+
result = '',
637+
i = 0,
638+
rest = string.length % 3;
639+
640+
for (; i < string.length;) {
641+
if ((a = string.charCodeAt(i++)) > 255 || (b = string.charCodeAt(i++)) > 255 || (c = string.charCodeAt(i++)) > 255) {
642+
logger.info("Failed to execute 'btoa' : The string to be encoded contains characters outside of the Latin1 range.");
643+
};
644+
bitmap = (a << 16) | (b << 8) | c;
645+
result += b64.charAt((bitmap >> 18) & 63) + b64.charAt((bitmap >> 12) & 63) + b64.charAt((bitmap >> 6) & 63) + b64.charAt(bitmap & 63);
646+
}
647+
648+
return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;
649+
}
650+
651+
652+
_.urlBase64Encode = function(data) {
653+
return _.btoa(encodeURIComponent(data).replace(/%([0-9A-F]{2})/g, function(match, p1) {
654+
return String.fromCharCode('0x' + p1);
655+
}));
656+
};
657+
582658
_.rot13obfs = function(str, key) {
583659
str = String(str);
584660
key = typeof key === 'number' ? key : 13;
@@ -1179,9 +1255,9 @@ sa.usePlugin = function(plugin, para) {
11791255

11801256

11811257
sa.prepareData = function(p, callback) {
1182-
if (current_scene && current_scene === 1154) {
1258+
if (current_scene && current_scene === 1154 && !sa.para.preset_events.moments_page) {
11831259
return false;
1184-
}
1260+
};
11851261

11861262
var data = {
11871263
distinct_id: this.store.getDistinctId(),
@@ -1894,6 +1970,64 @@ sa.initWithOpenid = function(options, callback) {
18941970
});
18951971
};
18961972

1973+
1974+
1975+
sa.setWebViewUrl = function(url, after_hash) {
1976+
if (!_.isString(url) || url === '') {
1977+
logger.info('error:请传入正确的 URL 格式');
1978+
return false;
1979+
}
1980+
1981+
url = decodeURIComponent(url);
1982+
var reg = /([^?#]+)(\?[^#]*)?(#.*)?/,
1983+
arr = reg.exec(url);
1984+
1985+
var host = arr[1] || '',
1986+
search = arr[2] || '',
1987+
hash = arr[3] || '',
1988+
nurl = '';
1989+
var distinct_id = sa.store.getDistinctId() || "",
1990+
first_id = sa.store.getFirstId() || "",
1991+
name = '_sasdk',
1992+
idIndex;
1993+
1994+
if (_.urlSafeBase64 && _.urlSafeBase64.encode) {
1995+
distinct_id = distinct_id ? _.urlSafeBase64.trim(_.urlSafeBase64.encode(_.urlBase64Encode(distinct_id))) : '';
1996+
} else if (this._.rot13obfs) {
1997+
distinct_id = distinct_id ? _.rot13obfs(distinct_id) : '';
1998+
}
1999+
distinct_id = encodeURIComponent(distinct_id);
2000+
var value = first_id ? 'f' + distinct_id : 'd' + distinct_id;
2001+
2002+
if (after_hash) {
2003+
idIndex = hash.indexOf('_sasdk');
2004+
var queryIndex = hash.indexOf('?');
2005+
if (queryIndex > -1) {
2006+
if (idIndex > -1) {
2007+
nurl = host + search + '#' + hash.substring(1, idIndex) + '_sasdk=' + value;
2008+
} else {
2009+
nurl = host + search + '#' + hash.substring(1) + '&_sasdk=' + value;
2010+
}
2011+
} else {
2012+
nurl = host + search + '#' + hash.substring(1) + '?_sasdk=' + value;
2013+
}
2014+
} else {
2015+
idIndex = search.indexOf('_sasdk');
2016+
var hasQuery = /^\?(\w)+/.test(search);
2017+
if (hasQuery) {
2018+
if (idIndex > -1) {
2019+
nurl = host + '?' + search.substring(1, idIndex) + '_sasdk=' + value + hash;
2020+
} else {
2021+
nurl = host + '?' + search.substring(1) + '&_sasdk=' + value + hash;
2022+
}
2023+
} else {
2024+
nurl = host + '?' + search.substring(1) + '_sasdk=' + value + hash;
2025+
}
2026+
}
2027+
2028+
return nurl;
2029+
}
2030+
18972031
_.each(['setProfile', 'setOnceProfile', 'track', 'quick', 'incrementProfile', 'appendProfile', 'login', 'logout', 'registerApp', 'register', 'clearAllRegister', 'clearAllProps', 'clearAppRegister'], function(method) {
18982032
var temp = sa[method];
18992033
sa[method] = function() {

product/sensorsdata.custom.full.js

Lines changed: 138 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ sa.para = {
3030
},
3131

3232
preset_properties: {},
33-
33+
preset_events: {
34+
moments_page: false,
35+
},
3436
batch_send: true
3537
};
3638

@@ -148,7 +150,7 @@ var ArrayProto = Array.prototype,
148150
slice = ArrayProto.slice,
149151
toString = ObjProto.toString,
150152
hasOwnProperty = ObjProto.hasOwnProperty,
151-
LIB_VERSION = '1.14.11',
153+
LIB_VERSION = '1.14.12',
152154
LIB_NAME = 'MiniProgram';
153155

154156
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -579,6 +581,80 @@ _.base64Encode = function(data) {
579581
return enc;
580582
};
581583

584+
_.urlSafeBase64 = (function() {
585+
var ENC = {
586+
'+': '-',
587+
'/': '_',
588+
'=': '.'
589+
};
590+
var DEC = {
591+
'-': '+',
592+
_: '/',
593+
'.': '='
594+
};
595+
596+
var encode = function(base64) {
597+
return base64.replace(/[+/=]/g, function(m) {
598+
return ENC[m];
599+
});
600+
};
601+
602+
var decode = function(safe) {
603+
return safe.replace(/[-_.]/g, function(m) {
604+
return DEC[m];
605+
});
606+
};
607+
608+
var trim = function(string) {
609+
return string.replace(/[.=]{1,2}$/, '');
610+
};
611+
612+
var isBase64 = function(string) {
613+
return /^[A-Za-z0-9+/]*[=]{0,2}$/.test(string);
614+
};
615+
616+
var isUrlSafeBase64 = function(string) {
617+
return /^[A-Za-z0-9_-]*[.]{0,2}$/.test(string);
618+
};
619+
620+
return {
621+
encode: encode,
622+
decode: decode,
623+
trim: trim,
624+
isBase64: isBase64,
625+
isUrlSafeBase64: isUrlSafeBase64
626+
};
627+
})();
628+
629+
_.btoa = function(string) {
630+
var b64 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';
631+
string = String(string)
632+
var bitmap,
633+
a,
634+
b,
635+
c,
636+
result = '',
637+
i = 0,
638+
rest = string.length % 3;
639+
640+
for (; i < string.length;) {
641+
if ((a = string.charCodeAt(i++)) > 255 || (b = string.charCodeAt(i++)) > 255 || (c = string.charCodeAt(i++)) > 255) {
642+
logger.info("Failed to execute 'btoa' : The string to be encoded contains characters outside of the Latin1 range.");
643+
};
644+
bitmap = (a << 16) | (b << 8) | c;
645+
result += b64.charAt((bitmap >> 18) & 63) + b64.charAt((bitmap >> 12) & 63) + b64.charAt((bitmap >> 6) & 63) + b64.charAt(bitmap & 63);
646+
}
647+
648+
return rest ? result.slice(0, rest - 3) + '==='.substring(rest) : result;
649+
}
650+
651+
652+
_.urlBase64Encode = function(data) {
653+
return _.btoa(encodeURIComponent(data).replace(/%([0-9A-F]{2})/g, function(match, p1) {
654+
return String.fromCharCode('0x' + p1);
655+
}));
656+
};
657+
582658
_.rot13obfs = function(str, key) {
583659
str = String(str);
584660
key = typeof key === 'number' ? key : 13;
@@ -1179,9 +1255,9 @@ sa.usePlugin = function(plugin, para) {
11791255

11801256

11811257
sa.prepareData = function(p, callback) {
1182-
if (current_scene && current_scene === 1154) {
1258+
if (current_scene && current_scene === 1154 && !sa.para.preset_events.moments_page) {
11831259
return false;
1184-
}
1260+
};
11851261

11861262
var data = {
11871263
distinct_id: this.store.getDistinctId(),
@@ -1894,6 +1970,64 @@ sa.initWithOpenid = function(options, callback) {
18941970
});
18951971
};
18961972

1973+
1974+
1975+
sa.setWebViewUrl = function(url, after_hash) {
1976+
if (!_.isString(url) || url === '') {
1977+
logger.info('error:请传入正确的 URL 格式');
1978+
return false;
1979+
}
1980+
1981+
url = decodeURIComponent(url);
1982+
var reg = /([^?#]+)(\?[^#]*)?(#.*)?/,
1983+
arr = reg.exec(url);
1984+
1985+
var host = arr[1] || '',
1986+
search = arr[2] || '',
1987+
hash = arr[3] || '',
1988+
nurl = '';
1989+
var distinct_id = sa.store.getDistinctId() || "",
1990+
first_id = sa.store.getFirstId() || "",
1991+
name = '_sasdk',
1992+
idIndex;
1993+
1994+
if (_.urlSafeBase64 && _.urlSafeBase64.encode) {
1995+
distinct_id = distinct_id ? _.urlSafeBase64.trim(_.urlSafeBase64.encode(_.urlBase64Encode(distinct_id))) : '';
1996+
} else if (this._.rot13obfs) {
1997+
distinct_id = distinct_id ? _.rot13obfs(distinct_id) : '';
1998+
}
1999+
distinct_id = encodeURIComponent(distinct_id);
2000+
var value = first_id ? 'f' + distinct_id : 'd' + distinct_id;
2001+
2002+
if (after_hash) {
2003+
idIndex = hash.indexOf('_sasdk');
2004+
var queryIndex = hash.indexOf('?');
2005+
if (queryIndex > -1) {
2006+
if (idIndex > -1) {
2007+
nurl = host + search + '#' + hash.substring(1, idIndex) + '_sasdk=' + value;
2008+
} else {
2009+
nurl = host + search + '#' + hash.substring(1) + '&_sasdk=' + value;
2010+
}
2011+
} else {
2012+
nurl = host + search + '#' + hash.substring(1) + '?_sasdk=' + value;
2013+
}
2014+
} else {
2015+
idIndex = search.indexOf('_sasdk');
2016+
var hasQuery = /^\?(\w)+/.test(search);
2017+
if (hasQuery) {
2018+
if (idIndex > -1) {
2019+
nurl = host + '?' + search.substring(1, idIndex) + '_sasdk=' + value + hash;
2020+
} else {
2021+
nurl = host + '?' + search.substring(1) + '&_sasdk=' + value + hash;
2022+
}
2023+
} else {
2024+
nurl = host + '?' + search.substring(1) + '_sasdk=' + value + hash;
2025+
}
2026+
}
2027+
2028+
return nurl;
2029+
}
2030+
18972031
_.each(['setProfile', 'setOnceProfile', 'track', 'quick', 'incrementProfile', 'appendProfile', 'login', 'logout', 'registerApp', 'register', 'clearAllRegister', 'clearAllProps', 'clearAppRegister'], function(method) {
18982032
var temp = sa[method];
18992033
sa[method] = function() {

0 commit comments

Comments
 (0)