Google 页面停留时间的分析事件
Google Analytics event with time on page
我目前正在使用以下代码将点击事件发送到 Google Analytics:
$(document).ready(function() {
$('#button').on('click', function() {
ga('send', 'event', 'button', 'click', 'nav-buttons');
});
});
效果很好。
但是,我希望该值是用户在页面上停留的时间的分钟数。
这意味着,它将跟踪用户单击按钮所用的分钟数。
$(document).ready(function() {
//current time at document ready
var past = new Date().getTime();
$('#button').on('click', function() {
//how much minutes passed when button clicked
timeElapsedInMin = Math.floor((new Date().getTime() - past) / 60000);
ga('send', 'event', 'button', 'click', 'nav-buttons', timeElapsedInMin);
});
});
我目前正在使用以下代码将点击事件发送到 Google Analytics:
$(document).ready(function() {
$('#button').on('click', function() {
ga('send', 'event', 'button', 'click', 'nav-buttons');
});
});
效果很好。
但是,我希望该值是用户在页面上停留的时间的分钟数。
这意味着,它将跟踪用户单击按钮所用的分钟数。
$(document).ready(function() {
//current time at document ready
var past = new Date().getTime();
$('#button').on('click', function() {
//how much minutes passed when button clicked
timeElapsedInMin = Math.floor((new Date().getTime() - past) / 60000);
ga('send', 'event', 'button', 'click', 'nav-buttons', timeElapsedInMin);
});
});