|
2223 | 2223 | return ''; |
2224 | 2224 | }; |
2225 | 2225 |
|
| 2226 | + _.isBaiduTraffic = function() { |
| 2227 | + var referer = document.referrer; |
| 2228 | + var endsWith = 'baidu.com'; |
| 2229 | + if (!referer) { |
| 2230 | + return false; |
| 2231 | + } |
| 2232 | + |
| 2233 | + try { |
| 2234 | + var hostname = _.URL(referer).hostname; |
| 2235 | + return hostname && hostname.substring(hostname.length - endsWith.length) === endsWith; |
| 2236 | + } catch (e) { |
| 2237 | + return false; |
| 2238 | + } |
| 2239 | + return false; |
| 2240 | + }; |
| 2241 | + |
| 2242 | + _.getReferrerEqid = function() { |
| 2243 | + var query = _.getQueryParamsFromUrl(document.referrer); |
| 2244 | + if (_.isEmptyObject(query) || !query.eqid) { |
| 2245 | + return _.UUID().replace(/-/g, ''); |
| 2246 | + } |
| 2247 | + return query.eqid; |
| 2248 | + }; |
| 2249 | + |
| 2250 | + _.getReferrerEqidType = function() { |
| 2251 | + var query = _.getQueryParamsFromUrl(document.referrer); |
| 2252 | + if (_.isEmptyObject(query) || !query.eqid) { |
| 2253 | + return 'baidu_sem_keyword_id'; |
| 2254 | + } |
| 2255 | + return 'baidu_seo_keyword_id'; |
| 2256 | + }; |
| 2257 | + |
| 2258 | + _.getBaiduKeyword = { |
| 2259 | + data: {}, |
| 2260 | + id: function() { |
| 2261 | + if (this.data.id) { |
| 2262 | + return this.data.id; |
| 2263 | + } else { |
| 2264 | + this.data.id = _.getReferrerEqid(); |
| 2265 | + return this.data.id; |
| 2266 | + } |
| 2267 | + }, |
| 2268 | + type: function() { |
| 2269 | + if (this.data.type) { |
| 2270 | + return this.data.type; |
| 2271 | + } else { |
| 2272 | + this.data.type = _.getReferrerEqidType(); |
| 2273 | + return this.data.type; |
| 2274 | + } |
| 2275 | + } |
| 2276 | + }; |
| 2277 | + |
| 2278 | + |
2226 | 2279 | _.isReferralTraffic = function(refererstring) { |
2227 | 2280 | refererstring = refererstring || document.referrer; |
2228 | 2281 | if (refererstring === '') { |
|
2415 | 2468 | return typeof referrer === 'string' ? referrer : ''; |
2416 | 2469 | }; |
2417 | 2470 |
|
2418 | | - _.getKeywordFromReferrer = function(referrerUrl) { |
| 2471 | + _.getKeywordFromReferrer = function(referrerUrl, activeValue) { |
2419 | 2472 | referrerUrl = referrerUrl || document.referrer; |
2420 | 2473 | var search_keyword = sd.para.source_type.keyword; |
2421 | 2474 | if (document && typeof referrerUrl === 'string') { |
2422 | 2475 | if (referrerUrl.indexOf('http') === 0) { |
2423 | 2476 | var searchEngine = _.getReferSearchEngine(referrerUrl); |
2424 | 2477 | var query = _.getQueryParamsFromUrl(referrerUrl); |
2425 | 2478 | if (_.isEmptyObject(query)) { |
2426 | | - return '未取到值'; |
| 2479 | + if (sd.para.preset_properties.search_keyword_baidu && _.isBaiduTraffic()) { |
| 2480 | + return; |
| 2481 | + } else { |
| 2482 | + return '未取到值'; |
| 2483 | + } |
2427 | 2484 | } |
2428 | 2485 | var temp = null; |
2429 | 2486 | for (var i in search_keyword) { |
|
2434 | 2491 | for (var i = 0; i < temp.length; i++) { |
2435 | 2492 | var _value = query[temp[i]]; |
2436 | 2493 | if (_value) { |
2437 | | - return _value; |
| 2494 | + if (activeValue) { |
| 2495 | + return { |
| 2496 | + active: _value |
| 2497 | + }; |
| 2498 | + } else { |
| 2499 | + return _value; |
| 2500 | + } |
2438 | 2501 | } |
2439 | 2502 | } |
2440 | 2503 | } else if (query[temp]) { |
2441 | | - return query[temp]; |
| 2504 | + if (activeValue) { |
| 2505 | + return { |
| 2506 | + active: query[temp] |
| 2507 | + }; |
| 2508 | + } else { |
| 2509 | + return query[temp]; |
| 2510 | + } |
2442 | 2511 | } |
2443 | 2512 | } |
2444 | 2513 | } |
2445 | 2514 | } |
2446 | | - return '未取到值'; |
| 2515 | + if (sd.para.preset_properties.search_keyword_baidu && _.isBaiduTraffic()) { |
| 2516 | + return; |
| 2517 | + } else { |
| 2518 | + return '未取到值' |
| 2519 | + } |
2447 | 2520 | } else { |
2448 | 2521 | if (referrerUrl === '') { |
2449 | 2522 | return '未取到值_直接打开'; |
|
2456 | 2529 | } |
2457 | 2530 | }; |
2458 | 2531 |
|
| 2532 | + |
2459 | 2533 | _.getWxAdIdFromUrl = function(url) { |
2460 | 2534 | var click_id = _.getQueryParam(url, 'gdt_vid'); |
2461 | 2535 | var hash_key = _.getQueryParam(url, 'hash_key'); |
|
3105 | 3179 |
|
3106 | 3180 | sd.para_default = { |
3107 | 3181 | preset_properties: { |
| 3182 | + search_keyword_baidu: false, |
3108 | 3183 | latest_utm: true, |
3109 | 3184 | latest_traffic_source_type: true, |
3110 | 3185 | latest_search_keyword: true, |
|
3613 | 3688 | } |
3614 | 3689 |
|
3615 | 3690 | if (sd.is_first_visitor && !para.not_set_profile) { |
| 3691 | + var eqidObj = {}; |
| 3692 | + |
| 3693 | + if (sd.para.preset_properties.search_keyword_baidu && _.isReferralTraffic(document.referrer) && _.isBaiduTraffic()) { |
| 3694 | + eqidObj['$search_keyword_id'] = _.getBaiduKeyword.id(); |
| 3695 | + eqidObj['$search_keyword_id_type'] = _.getBaiduKeyword.type(); |
| 3696 | + eqidObj['$search_keyword_id_hash'] = _.hashCode(eqidObj['$search_keyword_id']); |
| 3697 | + } |
| 3698 | + |
3616 | 3699 | sd.setOnceProfile( |
3617 | 3700 | _.extend({ |
3618 | 3701 | $first_visit_time: new Date(), |
|
3622 | 3705 | $first_traffic_source_type: _.getSourceFromReferrer(), |
3623 | 3706 | $first_search_keyword: _.getKeywordFromReferrer() |
3624 | 3707 | }, |
3625 | | - getUtm() |
| 3708 | + getUtm(), eqidObj |
3626 | 3709 | ) |
3627 | 3710 | ); |
3628 | 3711 | sd.is_first_visitor = false; |
|
3669 | 3752 | } |
3670 | 3753 | }); |
3671 | 3754 | if (sd.is_first_visitor && !para.not_set_profile) { |
| 3755 | + var eqidObj = {}; |
| 3756 | + |
| 3757 | + if (sd.para.preset_properties.search_keyword_baidu && _.isReferralTraffic(document.referrer) && _.isBaiduTraffic()) { |
| 3758 | + eqidObj['$search_keyword_id'] = _.getBaiduKeyword.id(); |
| 3759 | + eqidObj['$search_keyword_id_type'] = _.getBaiduKeyword.type(); |
| 3760 | + eqidObj['$search_keyword_id_hash'] = _.hashCode(eqidObj['$search_keyword_id']); |
| 3761 | + } |
| 3762 | + |
3672 | 3763 | sd.setOnceProfile( |
3673 | 3764 | _.extend({ |
3674 | 3765 | $first_visit_time: new Date(), |
|
3678 | 3769 | $first_traffic_source_type: _.getSourceFromReferrer(), |
3679 | 3770 | $first_search_keyword: _.getKeywordFromReferrer() |
3680 | 3771 | }, |
3681 | | - $utms |
| 3772 | + $utms, eqidObj |
3682 | 3773 | ) |
3683 | 3774 | ); |
3684 | 3775 | sd.is_first_visitor = false; |
3685 | 3776 | } |
| 3777 | + |
3686 | 3778 | if (para.not_set_profile) { |
3687 | 3779 | delete para.not_set_profile; |
3688 | 3780 | } |
|
5034 | 5126 | data.properties.$latest_referrer = '取值异常'; |
5035 | 5127 | } |
5036 | 5128 | if (sd.para.preset_properties.latest_search_keyword && !_.isString(data.properties.$latest_search_keyword)) { |
5037 | | - data.properties.$latest_search_keyword = '取值异常'; |
| 5129 | + if (!sd.para.preset_properties.search_keyword_baidu || !_.isString(data.properties.$search_keyword_id) || !_.isNumber(data.properties.$search_keyword_id_hash) || !_.isString(data.properties.$search_keyword_id_type)) { |
| 5130 | + data.properties.$latest_search_keyword = '取值异常'; |
| 5131 | + } |
5038 | 5132 | } |
5039 | 5133 | if (sd.para.preset_properties.latest_traffic_source_type && !_.isString(data.properties.$latest_traffic_source_type)) { |
5040 | 5134 | data.properties.$latest_traffic_source_type = '取值异常'; |
|
5382 | 5476 | checkIsFirstLatest: function() { |
5383 | 5477 | var url_domain = _.info.pageProp.url_domain; |
5384 | 5478 |
|
5385 | | - var latest_utms = ['$utm_source', '$utm_medium', '$utm_campaign', '$utm_content', '$utm_term']; |
5386 | | - var props = store.getProps(); |
5387 | | - for (var i = 0; i < latest_utms.length; i++) { |
5388 | | - if (latest_utms[i] in props) { |
5389 | | - delete props[latest_utms[i]]; |
5390 | | - } |
5391 | | - } |
5392 | | - store.setProps(props, true); |
5393 | | - |
5394 | 5479 |
|
5395 | 5480 | var latestObj = {}; |
5396 | 5481 |
|
5397 | 5482 | if (url_domain === '') { |
5398 | 5483 | url_domain = 'url解析失败'; |
5399 | 5484 | } |
5400 | 5485 |
|
| 5486 | + var baiduKey = _.getKeywordFromReferrer(document.referrer, true); |
| 5487 | + if (sd.para.preset_properties.search_keyword_baidu) { |
| 5488 | + if (_.isReferralTraffic(document.referrer)) { |
| 5489 | + if (_.isBaiduTraffic() && !(_.isObject(baiduKey) && baiduKey.active)) { |
| 5490 | + latestObj['$search_keyword_id'] = _.getBaiduKeyword.id(); |
| 5491 | + latestObj['$search_keyword_id_type'] = _.getBaiduKeyword.type(); |
| 5492 | + latestObj['$search_keyword_id_hash'] = _.hashCode(latestObj['$search_keyword_id']); |
| 5493 | + } else { |
| 5494 | + sd.store._state.props.$search_keyword_id && delete sd.store._state.props.$search_keyword_id; |
| 5495 | + sd.store._state.props.$search_keyword_id_type && delete sd.store._state.props.$search_keyword_id_type; |
| 5496 | + sd.store._state.props.$search_keyword_id_hash && delete sd.store._state.props.$search_keyword_id_hash; |
| 5497 | + } |
| 5498 | + } |
| 5499 | + } else { |
| 5500 | + sd.store._state.props.$search_keyword_id && delete sd.store._state.props.$search_keyword_id; |
| 5501 | + sd.store._state.props.$search_keyword_id_type && delete sd.store._state.props.$search_keyword_id_type; |
| 5502 | + sd.store._state.props.$search_keyword_id_hash && delete sd.store._state.props.$search_keyword_id_hash; |
| 5503 | + } |
| 5504 | + |
| 5505 | + sd.store.save(); |
| 5506 | + |
| 5507 | + |
5401 | 5508 | _.each(sd.para.preset_properties, function(value, key) { |
5402 | 5509 | if (key.indexOf('latest_') === -1) { |
5403 | 5510 | return false; |
|
5424 | 5531 | latestObj['$latest_referrer'] = _.isDecodeURI(sd.para.url_is_decode, _.info.pageProp.referrer); |
5425 | 5532 | break; |
5426 | 5533 | case 'search_keyword': |
5427 | | - latestObj['$latest_search_keyword'] = _.getKeywordFromReferrer(); |
| 5534 | + if (_.getKeywordFromReferrer()) { |
| 5535 | + latestObj['$latest_search_keyword'] = _.getKeywordFromReferrer(); |
| 5536 | + } else if (_.isObject(sd.store._state.props) && sd.store._state.props.$latest_search_keyword) { |
| 5537 | + delete sd.store._state.props.$latest_search_keyword; |
| 5538 | + } |
5428 | 5539 | break; |
5429 | 5540 | case 'landing_page': |
5430 | 5541 | latestObj['$latest_landing_page'] = _.isDecodeURI(sd.para.url_is_decode, location.href); |
|
0 commit comments