diff --git a/src/mip-story/mip-story-log.js b/src/mip-story/mip-story-log.js new file mode 100644 index 000000000..2596b1e8f --- /dev/null +++ b/src/mip-story/mip-story-log.js @@ -0,0 +1,100 @@ +/** + * @file mip-story-log.js + * @desc 小故事日志 + * @author + */ + +define(function (require) { + var util = require('util'); + var viewer = require('viewer'); + + // 前缀 + var prefix = 'MIP-SOTRY-LOG-TC'; + var baseData = {}; + + // 事件描述 包括事件名、描述,index纯粹为了可读性 + var evtDesc = [ + { + index: 0, + evtName: 'CLOSE_STORY', + desc: '关闭' + }, + { + index: 1, + evtName: 'CLOSE_AUDIO', + desc: '关闭音频' + }, + { + index: 2, + evtName: 'REPLAY_STORY', + desc: '重播' + }, + { + index: 3, + evtName: 'LINKTO_RECOMMEND', + desc: '点击推荐链接' + }, + { + index: 4, + evtName: 'LINKTO_RECOMMEND_FROM', + desc: '点击推荐来源' + }, + { + index: 5, + evtName: 'SHARE_STORY', + desc: '点击分享' + }, + { + index: 6, + evtName: 'RECOMMEND_SHOW', + desc: '推荐链接展现量' + }, + { + index: 7, + evtName: 'VIEWED_PAGE_END', + desc: '浏览至尾页' + }, + { + index: 8, + evtName: 'VIEWED_PAGE', + desc: '浏览页面' + }, + { + index: 9, + evtName: 'VIEWED_PV', + desc: 'pv' + } + ]; + + /** + * 日志发送 + * + * @param {number} evtIndex 统计项目编号 + * @param {Object} data 需要发送的数据 + * @example TcLog(0, {}) 点击关闭时发送日志 + */ + function TcLog (evtIndex, data) { + if(evtIndex !== 0 && !evtIndex) return; + + var curEvt = evtDesc[evtIndex]; + + var data = data || {}; + var tcData = util.fn.extend(data, baseData, { + desc: curEvt.desc + }); + var evt = prefix + curEvt.evtName; + + viewer.sendMessage(evt, tcData); + } + + /** + * 获取基本数据 + * + */ + TcLog.prototype.initBaseData = function (data) { + baseData = data || {}; + } + + return TcLog; +}); + diff --git a/src/mip-story/mip-story-service.js b/src/mip-story/mip-story-service.js index 89ca36ab8..df6037a76 100644 --- a/src/mip-story/mip-story-service.js +++ b/src/mip-story/mip-story-service.js @@ -10,6 +10,7 @@ define(function (require) { var storyViews = []; var emitter; var viewport = require('viewport'); + var tcLog = require('./mip-story-log'); var CURRENT = 'current'; var ACTIVE = 'active'; var STYLE = 'style'; @@ -267,28 +268,58 @@ define(function (require) { var target = e.target; var eleParent = findParent(target, 'a'); e.preventDefault(); + + var recTitle = eleParent.querySelector('p').innerHTML; + var recUrl = eleParent.getAttribute('href'); + var recImg = eleParent.querySelector('img').getAttribute('src'); + var fromUrl = eleParent.querySelector('.item-from').getAttribute('data-src'); + var formTile = eleParent.querySelector('.item-from').innerHTML; + + // tclog 推荐链接基本数据 包括推荐链接、标题、图片,推荐来源链接、来源标题 + // 这里 undefined 是字符串没错…… + var recData = {}; + recData.title = recTitle === 'undefined' ? "NOT_SET_REC_TITLE" : recTitle; + recData.url = recUrl === 'undefined' ? "NOT_SET_REC_URL" : encodeURIComponent(recUrl); + recData.img = recImg === 'undefined' ? "NOT_SET_REC_IMG" : encodeURIComponent(recImg); + recData.fromUrl = fromUrl === 'undefined' ? "NOT_SET_FROM_URL" : encodeURIComponent(fromUrl); + recData.fromTilte = formTile === 'undefined' ? "NOT_SET_FROM_TITLE" : formTile; + // 推荐链接 - if (target.nodeName.toLocaleLowerCase() !== 'span') { - var href = eleParent.getAttribute('href'); - window.top.location.href = href; + if (target.nodeName.toLocaleLowerCase() !== 'span' && recData.url !== 'NOT_SET_REC_URL') { + // tclog 推荐链接 + tcLog(3, recData); + window.top.location.href = decodeURIComponent(recData.url); return; + } else { + console.warn('没有设置推荐链接!!') } + // 来源链接 - var src = target.getAttribute('data-src'); - if (!src) { + if (recData.url !== 'NOT_SET_FROM_URL') { + // tclog 推荐来源 + tcLog(4, recData); + + window.top.location.href = decodeURIComponent(recData.fromUrl); return; + } else { + console.warn('没有设置来源链接!!') } - window.top.location.href = src; } // 返回上一页 if (this.hasClass(e, back)) { - history.back(); + // tclog 关闭小故事 + tcLog(0, {}); + + // history.back(); return; } // 静音控制 if (e.target === audio) { + // tclog 关闭音频播放 + tcLog(1, {}); + var enabled = audio.hasAttribute('muted'); enabled ? this.emitter.trigger(UNMUTE, e) : this.emitter.trigger(MUTE, e); @@ -296,6 +327,9 @@ define(function (require) { } // 重头开始播放 if (dm.contains(replay, e.target)) { + // tclog 重新播放 + tcLog(2, {}); + this.emitter.trigger(REPLAY); this.progress.updateProgress(0, 1); return; @@ -304,6 +338,9 @@ define(function (require) { else if (dm.contains(backend, e.target)) { // 弹出分享 if (dm.contains(shareBtn, e.target)) { + // tclog 点击分享 + tcLog(5, {}); + this.share.showShareLayer(); } // 关闭结尾页-只有点击交互的时候触发 diff --git a/src/mip-story/mip-story-slider.js b/src/mip-story/mip-story-slider.js index 5db2d5265..62341536c 100644 --- a/src/mip-story/mip-story-slider.js +++ b/src/mip-story/mip-story-slider.js @@ -16,6 +16,7 @@ define(function (require) { var CURRENT = constConfig.PAGE_STATE.current; var ACTIVE = constConfig.PAGE_STATE.active; var storyState = require('./mip-story-state'); + var tcLog = require('./mip-story-log'); var STYLE = 'style'; var screenWidth = viewport.getWidth(); var screenHeight = viewport.getHeight(); @@ -36,13 +37,13 @@ define(function (require) { var recommend; // 翻页埋点 - var pageViewed = [0]; + var pageViewed = []; var isPageOneViewed = false; var pageViewedData = { 'category': '_trackEvent', 'action': '翻页进度', 'optLabel': '滑动', - 'optValue': '翻了1页' + 'optValue': '看了第1页' }; // 分享页展示次数 这里以后可能会改成推荐小故事的展示量 @@ -167,6 +168,20 @@ define(function (require) { this.touchstartX = this.touchendX = 0; this.moveFlag = false; + + // 进入页面 自动发送当前页信息 + if(isPageOneViewed) return; + pageViewed = [this.currentIndex]; + var pageViewedInfo = '看了第' + (parseInt(this.currentIndex, 10) + 1) + '页'; + pageViewedData.optValue = pageViewedInfo; + this.trackEvent(pageViewedData); + + // tclog 看了第几页 + tcLog(8, {viewingPage: this.currentIndex + 1}); + // tclog pv + tcLog(9, {}); + + isPageOneViewed = true; } function enableScroll(ele) { @@ -574,7 +589,7 @@ define(function (require) { var currentPage = storyContain[i]; if (i === this.currentIndex) { // 埋点 - if (window._hmt && pageViewed.indexOf(i) === -1) { + if (pageViewed.indexOf(i) === -1) { var pageRole = currentPage.getAttribute('page-role'); this.triggerStats(i, pageRole); } @@ -640,21 +655,29 @@ define(function (require) { // 分享页单独统计 if (role === PAGE_ROLE.sharePage && !isSharePageViewed) { isSharePageViewed = true; - return this.trackEvent(sharePagedData); - } - // 这里主要是 保证第一页发送的时机 - if (!isPageOneViewed) { - isPageOneViewed = true; - this.trackEvent(pageViewedData); + // tclog 看了尾页 + tcLog(7, {}); + + // tclog 推荐展现量,现按:到了分享页,认为所有的推荐链接都展现了 + var count = storyContain[storyContain.length - 1].querySelectorAll('.recommend-item').length - 1; + tcLog(6, {count: count}); + + return this.trackEvent(sharePagedData); } // 分享页不计入翻页 if (role === PAGE_ROLE.sharePage) { return; } + pageViewed.push(pageIndex); - var pageViewedInfo = '翻了' + (+pageViewed[pageIndex] + 1) + '页'; + var viewingPage = +pageViewed[pageViewed.length - 1] + 1; + + // tclog 看了第几页 + tcLog(8, {viewingPage: viewingPage}); + + var pageViewedInfo = '看了第' + viewingPage + '页'; pageViewedData.optValue = pageViewedInfo; this.trackEvent(pageViewedData); } @@ -675,9 +698,10 @@ define(function (require) { * @param {Object} obj 统计事件对象 */ MIPStorySlider.prototype.trackEvent = function (obj) { + // console.log(obj.optValue) var label = obj.optLabel || ''; var value = obj.optValue || ''; - window._hmt.push([obj.category, obj.action, label, value]); + window._hmt && window._hmt.push([obj.category, obj.action, label, value]); } MIPStorySlider.prototype.clearStyle = function () { diff --git a/src/mip-story/mip-story.js b/src/mip-story/mip-story.js index 5423df8be..3d7d0511f 100644 --- a/src/mip-story/mip-story.js +++ b/src/mip-story/mip-story.js @@ -9,6 +9,7 @@ define(function (require) { var customElement = require('customElement').create(); require('./mip-story-view'); require('./mip-story-layer'); + var TcLog = require('./mip-story-log'); var constConfig = require('./mip-story-config'); var MIP_I_STORY_STANDALONE = constConfig.MIP_I_STORY_STANDALONE; var Audio = require('./audio'); @@ -78,6 +79,15 @@ define(function (require) { this.storyViews = this.element.querySelectorAll('mip-story-view'); }; + MIPStory.prototype.initBaseTcData = function () { + var data = {}; + data.pageLen = this.storyViews.length; + data.originUrl = util.getOriginalUrl(window.location.href).split('?')[0].split('#')[0]; + data.reffer = encodeURIComponent(window.document.referrer); + var tcLog = new TcLog() + tcLog.initBaseData(data); + } + MIPStory.prototype.initStoryContain = function () { this.bookEndContainer = document.querySelector('.mip-backend'); for (var index = 0; index < this.storyViews.length; index++) { @@ -193,6 +203,8 @@ define(function (require) { this.initBookend(mipStoryConfigData); // 保存 story-views到storyViews中便于后期操作 this.initStoryViews(); + // 初始化打点基本数据 + this.initBaseTcData(); // 保存包括封底页面在内的所有结果页 this.initStoryContain(); // 初始化引导页