Skip to content

Commit

Permalink
fix: mip-stats-baidu, remove word、baidu referrer params if not from r…
Browse files Browse the repository at this point in the history
…esult (#873)

* * merge commits

* mip-stats-baidu

* update codestyle

* update version patch

* update

* revert package.json version
  • Loading branch information
dongshihao authored Nov 2, 2017
1 parent 7d96928 commit 112b1de
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions mip-stats-baidu/mip-stats-baidu.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ define(function (require) {
if (viewer.isIframed) {
bdSearchCase();
}

if (config && Array.isArray(config.conf) && config.conf.length) {
var conf = config.conf;
for (var i = 0; i < conf.length; i++) {
Expand All @@ -40,7 +39,7 @@ define(function (require) {
}

bindEle();

var hm = document.createElement('script');
hm.src = 'https://hm.baidu.com/hm.js?' + token;
$(elem).append(hm);
Expand Down Expand Up @@ -197,25 +196,25 @@ define(function (require) {
* 解决来自百度搜索,内外域名不一致问题
*/
function bdSearchCase() {
var referrer = '';
var originUrl = '';
var hashObj = {};

var bdUrl = document.referrer;
var hashWord = MIP.hash.get('word') || '';
var hashEqid = MIP.hash.get('eqid') || '';
var from = MIP.hash.get('from') || '';
if ((hashWord || hashEqid) && bdUrl) {
var hashObj = {};
if (hashEqid && isMatch(from, 'result')) {

if (isMatch(from, 'result')) {
if ((hashWord || hashEqid) && document.referrer) {
hashObj.url = '';
hashObj.eqid = hashEqid;
}
else {
hashObj.word = hashWord;
originUrl = document.referrer;
}
referrer = makeReferrer(bdUrl, hashObj);
_hmt.push(['_setReferrerOverride', referrer]);
} else {
hashObj.url = '';
originUrl = location.origin + location.pathname + location.search;
}

_hmt.push(['_setReferrerOverride', makeReferrer(originUrl, hashObj)]);
}

/**
Expand Down Expand Up @@ -248,7 +247,7 @@ define(function (require) {
urlData += '&' + key + '=' + hashObj[key];
}
urlData = urlData.slice(1);
if (url.indexOf('#') < 0) {
if (url.indexOf('#') < 0 && urlData) {
referrer = url + conjMark + urlData;
}
else {
Expand Down

0 comments on commit 112b1de

Please sign in to comment.