我想添加一个EVENT TRACKING SCRIPT

时间:2017-04-14 09:57:30

标签: html google-analytics event-tracking

谷歌1页访问= BOUNCE。我的目标网页只有1页,因此对于Google,我的所有网页访问都会被标记为退回。

我不希望BOUNCE RATE为100℅所以为了避免这种情况,我需要创建一个EVENT TRACKING脚本。

通过将此EVENT TRACKING脚本添加到我的页面,我可以告诉Google我想要跟踪的是否为反弹。

我想在着陆页中跟踪的事件:

用户在page = NO BOUNCE

中花费45秒

用户向下滚动50页= NO BOUNCE

用户观看视频=无BOUNCE

1 个答案:

答案 0 :(得分:2)

  • 用户在页面上花费45秒

window.setTimeout(function() {
  ga('send', 'event', 'eventCategory', 'eventAction', 'eventLabel');
}, 45000);

  • 用户向下滚动页面

/* GA Scroll Depth */
var body = document.body,
    html = document.documentElement,
    windowHeight = $(window).height(),
    fullPageHeight = Math.max( body.scrollHeight, body.offsetHeight,
                               html.clientHeight, html.scrollHeight, html.offsetHeight),
    scrollableHeight = fullPageHeight - windowHeight,
    quarterScrolledPos = Math.round(scrollableHeight * .25),
    halfScrolledPos = Math.round(scrollableHeight * .5),
    threeQuarterScrolledPos = Math.round(scrollableHeight * .75),
    quarterScrollSentToGA = false,
    halfScrollSentToGA = false,
    threeQuarterScrollSentToGA = false,
    fullScrollSentToGA = false;
function checkScrollDepth() {
  var scrollPos = $(document).scrollTop();
  if (scrollPos >= quarterScrolledPos) {
    if (!quarterScrollSentToGA) {
      sendScrollDepthToGa('25%');
      quarterScrollSentToGA = true;
    }
  }
  if (scrollPos >= halfScrolledPos) {
    if (!halfScrollSentToGA) {
      sendScrollDepthToGa('50%');
      halfScrollSentToGA = true;
    }
  }
  if (scrollPos >= threeQuarterScrolledPos) {
    if (!threeQuarterScrollSentToGA) {
      sendScrollDepthToGa('75%');
      threeQuarterScrollSentToGA = true;
    }
  }
  if (scrollPos === scrollableHeight) {
    if (!fullScrollSentToGA) {
      sendScrollDepthToGa('100%');
      fullScrollSentToGA = true;
    }
  }
}
function sendScrollDepthToGa(scrollHeight) {
  ga('send', 'event', 'Scroll Depth', 'scroll' + scrollHeight, urlPath);
}
$(window).on('scroll', checkScrollDepth);
/* END GA Scroll Depth */

  • 除非将视频设置为自动播放,否则任何启动视频的点击都将被视为与该网页的互动,并会取消反弹。但是,如果您仍想发送事件以了解视频已播放,则可以使用javascript检测视频是否已播放,然后向GA发送事件,例如:

  ga('send', 'event', 'video', 'play', 'someOtherData');

您可能还想查看非互动事件:https://developers.google.com/analytics/devguides/collection/analyticsjs/events#non-interaction_events