Authored by 沈志敏

增加 曝光事件

Showing 1 changed file with 73 additions and 54 deletions
@@ -79,7 +79,7 @@ var nullFun = function() {}; @@ -79,7 +79,7 @@ var nullFun = function() {};
79 //入口方法 79 //入口方法
80 var _yas = function(initTime, version, tid, uid, geo, selector) { 80 var _yas = function(initTime, version, tid, uid, geo, selector) {
81 window.qs = util.queryString(); 81 window.qs = util.queryString();
82 - 82 +
83 custInfo.ak = tid; 83 custInfo.ak = tid;
84 appInfo.sv = version; 84 appInfo.sv = version;
85 custInfo.ud = uid ? uid : ''; 85 custInfo.ud = uid ? uid : '';
@@ -475,43 +475,88 @@ _yas.sendAppLogs = function(json, asyncindx) { @@ -475,43 +475,88 @@ _yas.sendAppLogs = function(json, asyncindx) {
475 } 475 }
476 } 476 }
477 477
  478 +function appPageOpen(data, actionUrl) {
  479 + window.indx = data.indx;
  480 + window.baseLogs = {
  481 + device: {
  482 + ak: data.ak,
  483 + udid: data.udid,
  484 + },
  485 + status: [{
  486 + av: data.av,
  487 + udid: data.udid,
  488 + sid: data.sid,
  489 + }],
  490 + events: [{
  491 + uid: data.uid,
  492 + sid: data.sid
  493 + }]
  494 + }
  495 +
  496 + // 上报页面打开事件
  497 + _yas.sendAppLogs({
  498 + appop: 'YB_H5_PAGE_OPEN_L',
  499 + param: JSON.stringify({
  500 + C_ID: window.qs.yh_channel || util.getChannel() || 1,
  501 + PAGE_URL: location.href,
  502 + PAGE_NAME: window.qs.title || document.title,
  503 + ACTION_URL: actionUrl
  504 + })
  505 + }, false);
  506 +}
  507 +
478 // 监听app加载的deviceready事件 508 // 监听app加载的deviceready事件
479 ev.addEventHandler(document, 'deviceready', function(e) { 509 ev.addEventHandler(document, 'deviceready', function(e) {
480 window._yasloaded = false; 510 window._yasloaded = false;
481 window.fromApp = true; 511 window.fromApp = true;
482 512
483 - window.yohoInterface.triggerEvent(function(data) {  
484 - window.indx = data.indx;  
485 - window.baseLogs = {  
486 - device: {  
487 - ak: data.ak,  
488 - udid: data.udid,  
489 - },  
490 - status: [{  
491 - av: data.av,  
492 - udid: data.udid,  
493 - sid: data.sid,  
494 - }],  
495 - events: [{  
496 - uid: data.uid,  
497 - sid: data.sid  
498 - }]  
499 - } 513 + var actionUrl = [];
  514 + var aDom = document.getElementsByTagName("a"); //获取页面所有a标签
  515 +
  516 + for(var i = 0; i < aDom.length; i++) {
  517 + var href = aDom[i].getAttribute('href');
  518 + href && actionUrl.push(href);
  519 +
  520 + ev.addEventHandler(aDom[i], 'click', function(e) {
  521 + // 上报曝光事件
  522 + _yas.sendAppLogs({
  523 + appop: 'YB_H5_PAGE_FLR_C',
  524 + param: JSON.stringify({
  525 + C_ID: window.qs.yh_channel || util.getChannel() || 1,
  526 + PAGE_URL: location.href,
  527 + PAGE_NAME: window.qs.title || document.title,
  528 + F_URL: e.currentTarget.getAttribute('href')
  529 + })
  530 + }, true);
  531 +
  532 + if ('feature.yoho.cn' === document.domain) { // feature.yoho.cn场合
  533 + var operid = e.currentTarget.getAttribute('operid');
  534 + if (operid) {
  535 + var param = e.currentTarget.getAttribute('param');
  536 + var needcid = e.currentTarget.getAttribute('needcid');
  537 +
  538 + if (needcid) {
  539 + param = JSON.parse(param);
  540 + param.C_ID = window.qs.yh_channel;
  541 + param = JSON.stringify(param);
  542 + }
  543 +
  544 + _yas.sendAppLogs({
  545 + appop: operid,
  546 + param: param
  547 + }, true);
  548 + }
  549 + }
  550 + });
  551 + }
500 552
501 - // 上报页面打开事件  
502 - _yas.sendAppLogs({  
503 - appop: 'YB_H5_PAGE_OPEN_L',  
504 - param: JSON.stringify({  
505 - C_ID: window.qs.yh_channel || util.getChannel() || 1,  
506 - PAGE_URL: location.href,  
507 - PAGE_NAME: window.qs.title || document.title  
508 - })  
509 - }, false); 553 + window.yohoInterface.triggerEvent(function(data){
  554 + appPageOpen(data, actionUrl);
510 }, nullFun, { 555 }, nullFun, {
511 method: 'get.analyticAppData' 556 method: 'get.analyticAppData'
512 }); 557 });
513 558
514 - // 同步indx 559 + // 同步indx(需延迟处理)
515 var timer = setInterval(function() { 560 var timer = setInterval(function() {
516 if (window._yasloaded) { 561 if (window._yasloaded) {
517 clearInterval(timer); 562 clearInterval(timer);
@@ -523,33 +568,7 @@ ev.addEventHandler(document, 'deviceready', function(e) { @@ -523,33 +568,7 @@ ev.addEventHandler(document, 'deviceready', function(e) {
523 }); 568 });
524 } 569 }
525 }, 500); 570 }, 500);
526 -  
527 - if ('feature.yoho.cn' === document.domain) {  
528 - // feature.yoho.cn场合  
529 - var aDom = document.getElementsByTagName("a");  
530 -  
531 - for(var i = 0; i < aDom.length; i++){  
532 - ev.addEventHandler(aDom[i], 'click', function(e) {  
533 - var operid = e.target.getAttribute('operid');  
534 571
535 - if (operid) {  
536 - var param = e.target.getAttribute('param');  
537 - var needcid = e.target.getAttribute('needcid');  
538 -  
539 - if (needcid) {  
540 - param = JSON.parse(param);  
541 - param.C_ID = window.qs.yh_channel;  
542 - param = JSON.stringify(param);  
543 - }  
544 -  
545 - _yas.sendAppLogs({  
546 - appop: operid,  
547 - param: param  
548 - }, true);  
549 - }  
550 - });  
551 - }  
552 - }  
553 }); 572 });
554 573
555 module.exports = _yas; 574 module.exports = _yas;