Skip to content

Commit 85a8bc8

Browse files
author
shengyonggen
committed
Release 1.14.29
1 parent 353e351 commit 85a8bc8

14 files changed

+469
-123
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.14.29(2021-11-29)
2+
1. 新增
3+
- 新增所有事件采集 `$url``$title``$mp_client_basic_library_version``$mp_client_app_version``$app_version` 属性
4+
5+
16
## 1.14.28(2021-11-24)
27
1. 优化
38
- 优化 `$referrer` 取值为 `url` 完整路径带 `query` 参数

package.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sa-sdk-miniprogram",
3-
"version": "1.14.28",
3+
"version": "1.14.29",
44
"description": "sensorsdata miniprogram sdk",
55
"main": "sensorsdata.min.js",
66
"scripts": {
@@ -20,12 +20,5 @@
2020
"bugs": {
2121
"url": "https://github.com/sensorsdata/sa-sdk-miniprogram/issues"
2222
},
23-
"homepage": "https://github.com/sensorsdata/sa-sdk-miniprogram#readme",
24-
"devDependencies": {
25-
"eslint": "^8.0.1",
26-
"husky": "^7.0.4"
27-
},
28-
"dependencies": {
29-
"prettier": "^2.4.1"
30-
}
23+
"homepage": "https://github.com/sensorsdata/sa-sdk-miniprogram#readme"
3124
}

product/sensorsdata.custom.es6.full.js

Lines changed: 76 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,7 @@ kit.buildData = function(p) {
6767
}
6868

6969
var refPage = _.getRefPage();
70-
if (!data.properties.hasOwnProperty('$referrer')) {
71-
data.properties.$referrer = refPage.route;
72-
}
73-
74-
if (!data.properties.hasOwnProperty('$referrer_title')) {
75-
data.properties.$referrer_title = refPage.title;
76-
}
70+
setPublicPProperties(data);
7771
}
7872
if (data.properties.$time && _.isDate(data.properties.$time)) {
7973
data.time = data.properties.$time * 1;
@@ -108,6 +102,24 @@ function encodeTrackData(data) {
108102
return encodeURIComponent(dataStr);
109103
}
110104

105+
function setPublicPProperties(data) {
106+
if (data && data.properties) {
107+
var refPage = sa._.getRefPage();
108+
var pageInfo = sa._.getCurrentPageInfo();
109+
var propertiesMap = {
110+
$referrer: refPage.route,
111+
$referrer_title: refPage.title,
112+
$title: pageInfo.title,
113+
$url: pageInfo.url
114+
};
115+
for (var key in propertiesMap) {
116+
if (!data.properties.hasOwnProperty(key)) {
117+
data.properties[key] = propertiesMap[key];
118+
}
119+
}
120+
}
121+
}
122+
111123

112124
var mergeStorageData = {};
113125

@@ -469,7 +481,7 @@ var ArrayProto = Array.prototype,
469481
slice = ArrayProto.slice,
470482
toString$1 = ObjProto.toString,
471483
hasOwnProperty = ObjProto.hasOwnProperty,
472-
LIB_VERSION = '1.14.28',
484+
LIB_VERSION = '1.14.29',
473485
LIB_NAME = 'MiniProgram';
474486

475487
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
@@ -1465,6 +1477,20 @@ _.getRefPage = function() {
14651477
return _refInfo;
14661478
};
14671479

1480+
_.getCurrentPageInfo = function() {
1481+
var pages = _.getCurrentPage();
1482+
var pageInfo = {
1483+
title: '',
1484+
url: ''
1485+
};
1486+
if (pages && pages.route) {
1487+
var query = pages.sensors_mp_url_query ? '?' + pages.sensors_mp_url_query : '';
1488+
pageInfo.title = _.getPageTitle(pages.route);
1489+
pageInfo.url = pages.route + query;
1490+
}
1491+
return pageInfo;
1492+
};
1493+
14681494
_.setPageRefData = function(prop, path, query) {
14691495
var refPage = _.getRefPage();
14701496

@@ -1485,7 +1511,7 @@ _.setPageRefData = function(prop, path, query) {
14851511

14861512
_.getPageTitle = function(route) {
14871513
if (route === '未取到' || !route) {
1488-
return false;
1514+
return '';
14891515
}
14901516
var title = '';
14911517
try {
@@ -1539,13 +1565,23 @@ _.wxrequest = function(obj) {
15391565
}
15401566
};
15411567

1542-
_.getAppId = function() {
1543-
var info;
1568+
_.getAppInfoSync = function() {
15441569
if (wx.getAccountInfoSync) {
1545-
info = wx.getAccountInfoSync();
1570+
var info = wx.getAccountInfoSync(),
1571+
accountInfo = info && info.miniProgram ? info.miniProgram : {};
1572+
return {
1573+
appId: accountInfo.appId,
1574+
appEnv: accountInfo.envVersion,
1575+
appVersion: accountInfo.version
1576+
};
15461577
}
1547-
if (_.isObject(info) && _.isObject(info.miniProgram)) {
1548-
return info.miniProgram.appId;
1578+
return {};
1579+
};
1580+
1581+
_.getAppId = function() {
1582+
var info = _.getAppInfoSync();
1583+
if (info && info.appId) {
1584+
return info.appId;
15491585
}
15501586
};
15511587

@@ -1637,15 +1673,20 @@ _.info = {
16371673
e.$os = formatSystem(t['platform']);
16381674
e.$os_version = t['system'].indexOf(' ') > -1 ? t['system'].split(' ')[1] : t['system'];
16391675
wxSDKVersion = t['SDKVersion'];
1676+
e.$mp_client_app_version = t['version'];
1677+
e.$mp_client_basic_library_version = wxSDKVersion;
16401678
},
16411679
complete: function() {
16421680
var timeZoneOffset = new Date().getTimezoneOffset();
1643-
var appId = _.getAppId();
1681+
var accountInfo = _.getAppInfoSync();
16441682
if (_.isNumber(timeZoneOffset)) {
16451683
e.$timezone_offset = timeZoneOffset;
16461684
}
1647-
if (appId) {
1648-
e.$app_id = appId;
1685+
if (accountInfo.appId) {
1686+
e.$app_id = accountInfo.appId;
1687+
}
1688+
if (accountInfo.appVersion) {
1689+
e.$app_version = accountInfo.appVersion;
16491690
}
16501691
sa.initialState.systemIsComplete = true;
16511692
sa.initialState.checkIsComplete();
@@ -2391,6 +2432,14 @@ sa.autoTrackCustom = {
23912432
}
23922433
if (para && para.path) {
23932434
prop.$url_path = _.getPath(para.path);
2435+
prop.$title = _.getPageTitle(para.path);
2436+
2437+
if (para.query && _.isObject(para.query)) {
2438+
var _query = _.setQuery(para.query);
2439+
_query = _query ? '?' + _query : '';
2440+
prop.$url = prop.$url_path + _query;
2441+
}
2442+
23942443
if (sa.para.preset_properties.url_path === true) {
23952444
sa.registerApp({
23962445
$url_path: prop.$url_path
@@ -2445,6 +2494,7 @@ sa.autoTrackCustom = {
24452494

24462495
if (para && para.path) {
24472496
prop.$url_path = _.getPath(para.path);
2497+
prop.$title = _.getPageTitle(para.path);
24482498
if (sa.para.preset_properties.url_path === true) {
24492499
sa.registerApp({
24502500
$url_path: prop.$url_path
@@ -2466,7 +2516,9 @@ sa.autoTrackCustom = {
24662516
});
24672517
prop.$url_query = _.setQuery(para.query);
24682518
_.setPageRefData(prop, para.path, prop.$url_query);
2469-
2519+
if (para && para.path) {
2520+
prop.$url = para.path + (prop.$url_query ? '?' + prop.$url_query : '');
2521+
}
24702522
if (not_use_auto_track) {
24712523
prop = _.extend(prop, not_use_auto_track);
24722524
sa.track('$MPShow', prop);
@@ -2651,6 +2703,7 @@ sa.appLaunch = function(option, prop) {
26512703
}
26522704
if (option && option.path) {
26532705
obj.$url_path = _.getPath(option.path);
2706+
obj.$title = _.getPageTitle(option.path);
26542707
if (sa.para.preset_properties.url_path === true) {
26552708
sa.registerApp({
26562709
$url_path: obj.$url_path
@@ -2676,6 +2729,7 @@ sa.appLaunch = function(option, prop) {
26762729
});
26772730

26782731
obj.$url_query = _.setQuery(option.query);
2732+
obj.$url = option.path + (obj.$url_query ? '?' + obj.$url_query : '');
26792733
_.setPageRefData(prop);
26802734
if (_.isObject(prop)) {
26812735
obj = _.extend(obj, prop);
@@ -2701,6 +2755,7 @@ sa.appShow = function(option, prop) {
27012755

27022756
if (option && option.path) {
27032757
obj.$url_path = _.getPath(option.path);
2758+
obj.$title = _.getPageTitle(option.path);
27042759
if (sa.para.preset_properties.url_path === true) {
27052760
sa.registerApp({
27062761
$url_path: obj.$url_path
@@ -2718,6 +2773,9 @@ sa.appShow = function(option, prop) {
27182773
$latest_scene: obj.$scene
27192774
});
27202775
obj.$url_query = _.setQuery(option.query);
2776+
if (option && option.path) {
2777+
obj.$url = option.path + (obj.$url_query ? '?' + obj.$url_query : '');
2778+
}
27212779
_.setPageRefData(obj, option.path, obj.$url_query);
27222780
if (_.isObject(prop)) {
27232781
obj = _.extend(obj, prop);

0 commit comments

Comments
 (0)