Skip to content

Commit 52ab2c1

Browse files
author
shengyonggen
committed
解决冲突
1 parent cc999c1 commit 52ab2c1

File tree

3 files changed

+154
-50
lines changed

3 files changed

+154
-50
lines changed

sensorsdata.js

Lines changed: 148 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ var sa = {};
99

1010
sa.para = require('sensorsdata_conf.js');
1111

12-
13-
// 优化配置
14-
/*
15-
if (sa.para.debug_mode) {
16-
sa.para.debug_mode_url = sa.para.server_url.replace(/\/sa$/, '/debug').replace(/(\/sa)(\?[^\/]+)$/, '/debug$2');
17-
}router
18-
*/
19-
2012
sa._queue = [];
2113
// 是否已经获取到系统信息
2214
sa.getSystemInfoComplete = false;
@@ -27,9 +19,13 @@ var ArrayProto = Array.prototype,
2719
slice = ArrayProto.slice,
2820
toString = ObjProto.toString,
2921
hasOwnProperty = ObjProto.hasOwnProperty,
30-
LIB_VERSION = '0.7',
22+
LIB_VERSION = '0.9',
3123
LIB_NAME = 'MiniProgram';
3224

25+
var source_channel_standard = 'utm_source utm_medium utm_campaign utm_content utm_term';
26+
27+
var sa_referrer = '直接打开';
28+
3329
sa.lib_version = LIB_VERSION;
3430

3531
var logger = typeof logger === 'object' ? logger : {};
@@ -441,6 +437,42 @@ _.base64Encode = function(data) {
441437
return enc;
442438
};
443439

440+
_.getQueryParam = function (url, param) {
441+
url = _.decodeURIComponent(url);
442+
var regexS = "[\\?&]" + param + "=([^&#]*)",
443+
regex = new RegExp(regexS),
444+
results = regex.exec(url);
445+
if (results === null || (results && typeof (results[1]) !== 'string' && results[1].length)) {
446+
return '';
447+
} else {
448+
return _.decodeURIComponent(results[1]);
449+
}
450+
};
451+
452+
_.getUtm = function(url){
453+
var campaign_keywords = source_channel_standard.split(' ');
454+
var kw = '';
455+
var params = {};
456+
url = _.decodeURIComponent(url);
457+
url = url.split('?')[1];
458+
if(url.indexOf('?') === -1){
459+
url = '?' + url;
460+
if (_.isArray(sa.para.source_channel) && sa.para.source_channel.length > 0) {
461+
campaign_keywords = campaign_keywords.concat(sa.para.source_channel);
462+
campaign_keywords = _.unique(campaign_keywords);
463+
}
464+
_.each(campaign_keywords, function (kwkey) {
465+
kw = _.getQueryParam(url, kwkey);
466+
if (kw.length) {
467+
params[kwkey] = kw;
468+
}
469+
});
470+
return params;
471+
}else{
472+
return {};
473+
}
474+
};
475+
444476
_.info = {
445477
properties : {
446478
$lib : LIB_NAME,
@@ -515,6 +547,13 @@ sa.prepareData = function(p, callback) {
515547
if (!p.type || p.type.slice(0, 7) !== 'profile') {
516548
// 传入的属性 > 当前页面的属性 > session的属性 > cookie的属性 > 预定义属性
517549
data.properties = _.extend({}, _.info.properties, sa.store.getProps(), data.properties);
550+
551+
// 判断是否是首日访问,果子说要做
552+
if (typeof sa.store._state === 'object' && typeof sa.store._state.first_visit_day_time === 'number' && sa.store._state.first_visit_day_time > (new Date()).getTime()) {
553+
data.properties.$is_first_day = true;
554+
} else {
555+
data.properties.$is_first_day = false;
556+
}
518557
}
519558
// 如果$time是传入的就用,否则使用服务端时间
520559
if (data.properties.$time && _.isDate(data.properties.$time)) {
@@ -525,12 +564,7 @@ sa.prepareData = function(p, callback) {
525564
data.time = (new Date()) * 1;
526565
}
527566
}
528-
// 判断是否是首日访问,果子说要做
529-
if (typeof sa.store._state === 'object' && typeof sa.store._state.first_visit_day_time === 'number' && sa.store._state.first_visit_day_time > (new Date()).getTime() ){
530-
data.properties.$is_first_day = true;
531-
}else{
532-
data.properties.$is_first_day = false;
533-
}
567+
534568

535569
_.searchObjDate(data);
536570
_.searchObjString(data);
@@ -725,7 +759,7 @@ sa.send = function(t) {
725759
wx.request({
726760
"url" : url,
727761
"method" : "GET"
728-
})
762+
});
729763
};
730764
sendRequest();
731765
};
@@ -734,63 +768,141 @@ function e(t, n, o) {
734768
if (t[n]) {
735769
var e = t[n];
736770
t[n] = function(t) {
737-
o.call(this, t, n), e.call(this, t)
771+
o.call(this, t, n);
772+
e.call(this, t);
738773
}
739774
} else
740775
t[n] = function(t) {
741-
o.call(this, t, n)
776+
o.call(this, t, n);
742777
}
743778
}
744779

745-
function appLaunch() {
780+
function appLaunch(para) {
746781
this[sa.para.name] = sa;
747782
sa.init();
783+
var prop = {};
748784

785+
if(para && para.path){
786+
prop.$url_path = para.path;
787+
}
788+
// 暂时只解析传统网页渠道的query
789+
if(para && _.isObject(para.query) && para.query.q){
790+
_.extend(prop,_.getUtm(para.query.q));
791+
}
792+
// console.log('app_launch', JSON.stringify(arguments));
793+
sa.track('$MPLaunch',prop);
749794
};
750795

751-
function appShow() {
796+
function appShow(para) {
797+
// console.log('app_show', JSON.stringify(arguments));
798+
var prop = {};
752799

800+
if (para && para.path) {
801+
prop.$url_path = para.path;
802+
}
803+
// 暂时只解析传统网页渠道的query
804+
if (para && _.isObject(para.query) && para.query.q) {
805+
_.extend(prop, _.getUtm(para.query.q));
806+
}
807+
sa.track('$MPShow', prop);
753808
};
754809

755-
function appHide(n, e) {
756-
810+
function appHide() {
811+
sa.track('$MPHide');
812+
// console.log('app_hide', JSON.stringify(arguments));
813+
// sa.track('app_hide', { detail: JSON.stringify(arguments) });
757814
};
758815

816+
function appError(){
817+
// console.log('app_error', JSON.stringify(arguments));
818+
// sa.track('app_error', { detail: JSON.stringify(arguments) });
819+
}
820+
function appUnLaunch() {
821+
// console.log('app_unlaunch', JSON.stringify(arguments));
822+
// sa.track('app_unlaunch', { detail: JSON.stringify(arguments) });
823+
}
824+
759825
var p = App;
760826

761827
App = function(t) {
762828
e(t, "onLaunch", appLaunch);
763829
e(t, "onShow", appShow);
830+
// e(t, "onUnLaunch", appUnLaunch);
764831
e(t, "onHide", appHide);
832+
// e(t, "onError",appError);
765833
p(t);
766834
};
767835

768836
function pageOnunload(n, e) {
769-
837+
838+
// console.log('s-page_unload', JSON.stringify(arguments));
839+
// sa.track('page_unload', { detail: JSON.stringify(arguments) });
770840
}
771841

772-
function pageOnload(t, n) {
842+
function pageOnload(para) {
843+
//console.log('s-page_onload', JSON.stringify(arguments));
844+
var router = typeof this["__route__"] === 'string' ? this["__route__"] : '系统没有取到值';
845+
846+
var prop = {};
847+
prop.$referrer = sa_referrer;
848+
prop.$url_path = router;
849+
// 暂时只解析传统网页渠道的query
850+
if (para && _.isObject(para[0]) && para[0].q) {
851+
_.extend(prop, _.getUtm(para[0].q));
852+
}
853+
854+
if (sa.para.onshow) {
855+
sa.para.onshow(sa, router, this);
856+
} else {
857+
sa.track('$MPViewScreen', prop);
858+
}
859+
860+
sa_referrer = router;
773861

774862
};
775863

776-
function pageOnshow(t, n) {
777-
var router = typeof this["__route__"] === 'string' ? this["__route__"] : '系统没有取到值';
778-
if (sa.para.onshow){
779-
sa.para.onshow(sa, router, this)
780-
}else{
781-
sa.track('$MPViewScreen', {
782-
$url: router
783-
});
784-
}
864+
function pageOnshow() {
865+
//console.log('s-page_show', JSON.stringify(arguments));
785866
};
786867

868+
function pageOnHide() {
869+
// console.log('s-page_hide', JSON.stringify(arguments));
870+
// sa.track('page_hide', { detail: JSON.stringify(arguments) });
871+
}
872+
873+
function pageOnReady() {
874+
// console.log('s-page_ready', JSON.stringify(arguments));
875+
// sa.track('page_ready', { detail: JSON.stringify(arguments) });
876+
}
877+
878+
function pageOnPullDownRefresh() {
879+
// console.log('page_PullDownRefresh', JSON.stringify(arguments));
880+
// sa.track('page_PullDownRefresh', { detail: JSON.stringify(arguments) });
881+
}
882+
883+
function pageOnReachBottom() {
884+
// console.log('page_ReachBottom', JSON.stringify(arguments));
885+
// sa.track('page_ReachBottom', { detail: JSON.stringify(arguments) };
886+
}
887+
function pageOnShareAppMessage(n, e) {
888+
// console.log('page_ShareAppMessage', JSON.stringify(arguments));
889+
// sa.track('page_ShareAppMessage', { detail: JSON.stringify(arguments) });
890+
}
891+
787892
var v = Page;
788893

789894
Page = function(t) {
895+
790896
e(t, "onLoad", pageOnload);
791-
e(t, "onUnload", pageOnunload);
792-
e(t, "onShow", pageOnshow);
793-
e(t, "onHide", pageOnunload);
897+
// e(t, "onUnload", pageOnunload);
898+
// e(t, "onShow", pageOnshow);
899+
// e(t, "onHide", pageOnHide);
900+
901+
// e(t, "onReady", pageOnReady);
902+
// e(t, "onPullDownRefresh", pageOnPullDownRefresh);
903+
// e(t, "onReachBottom", pageOnReachBottom);
904+
// e(t, "onShareAppMessage", pageOnShareAppMessage);
905+
794906

795907
v(t);
796908

0 commit comments

Comments
 (0)