在jquery中调用滚动事件中的谷歌分析
calling Google analytics in scroll event in jquery
我有以下代码在我的主页谷歌分析。
<script type="text/javascript">
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
ga('create', '@System.Configuration.ConfigurationManager.AppSettings["GoogleAnalyticsID"]', 'auto');
ga('send', 'pageview');
</script>
我需要在js中调用谷歌分析滚动事件如何调用谷歌分析功能滚动事件?你能帮我解决这个问题吗?div ?
一个在我公司工作的人开发了一个与Google Analytics Classic一起使用的库,我采用了Track Scroll插件并将其改编为fire to Universal Google Analytics,这里是代码:(如果您有任何疑问,请问我)
/**
* GAS - Google Analytics on Steroids
*
* Max-Scroll Tracking Plugin
*
* Copyright 2011, Cardinal Path and Direct Performance
* Licensed under the GPLv3 license.
*
* @author Eduardo Cereto <eduardocereto@gmail.com>
*/
var _maxScrollOpts;
/**
* Get current browser viewpane heigtht
*
* @return {number} height.
*/
function _get_window_height() {
return window.innerHeight || documentElement.clientHeight ||
document.body.clientHeight || 0;
}
/**
* Get current absolute window scroll position
*
* @return {number} YScroll.
*/
function _get_window_Yscroll() {
return window.pageYOffset || document.body.scrollTop ||
documentElement.scrollTop || 0;
}
/**
* Get current absolute document height
*
* @return {number} Current document height.
*/
function _get_doc_height() {
return Math.max(
document.body.scrollHeight || 0, documentElement.scrollHeight || 0,
document.body.offsetHeight || 0, documentElement.offsetHeight || 0,
document.body.clientHeight || 0, documentElement.clientHeight || 0
);
}
/**
* Get current vertical scroll percentage
*
* @return {number} Current vertical scroll percentage.
*/
function _get_scroll_percentage() {
return (
(_get_window_Yscroll() + _get_window_height()) / _get_doc_height()
) * 100;
}
var _t = null;
var _max_scroll = 0;
function _update_scroll_percentage(now) {
if (_t) {
clearTimeout(_t);
}
if (now === true) {
_max_scroll = Math.max(_get_scroll_percentage(), _max_scroll);
return;
}
_t = setTimeout(function () {
_max_scroll = Math.max(_get_scroll_percentage(), _max_scroll);
}, 400);
}
function _sendMaxScroll() {
_update_scroll_percentage(true);
_max_scroll = Math.floor(_max_scroll);
if (_max_scroll <= 0 || _max_scroll > 100) return;
var bucket = (_max_scroll > 10 ? 1 : 0) * (
Math.floor((_max_scroll - 1) / 10) * 10 + 1
);
bucket = String(bucket) + '-' +
String(Math.ceil(_max_scroll / 10) * 10);
ga('send',
'event',
_maxScrollOpts['category'],
url,
bucket,
Math.floor(_max_scroll),
true // non-interactive
);
}
/**
* Tracks the max Scroll on the page.
*
* @param {object} opts GAS Options to be used.
* @this {GasHelper} The Ga Helper object
*/
function _trackMaxScroll(opts) {
if (!this._maxScrollTracked) {
this._maxScrollTracked = true;
} else {
//Oops double tracking detected.
return;
}
_maxScrollOpts = opts || {};
_maxScrollOpts['category'] = _maxScrollOpts['category'] || 'Max Scroll';
this._addEventListener(window, 'scroll', _update_scroll_percentage);
this._addEventListener(window, 'beforeunload', _sendMaxScroll);
}
_trackMaxScroll();
相关文章:
- 谷歌地图劫持了iphone's滚动(触摸事件)-如何恢复
- 谷歌地图API-如何停止滚动(JavaScript)
- 像谷歌一样更改滚动网站
- 加载、滚动、放大和缩小图像,如谷歌地图
- Android默认浏览器:谷歌地图制作“;位置:相对;元素在页面顶部滚动
- 使用谷歌图表自动向下滚动表格
- 谷歌地图在滚动时拖动
- 谷歌地图API标记限制/滚动
- 谷歌MDL瀑布标题在正文右侧的滚动和滚动条上不缩小
- 滚动功能在谷歌地图上不起作用
- 禁用页面滚动,但允许谷歌地图滚动
- 如何使用谷歌地图调整滚动时的叠加层
- 当地图滚动到视图中时,为谷歌地图标记添加动画效果
- 谷歌地图API在移动设备上滑动与屏幕滚动冲突
- 新的谷歌日历登录页滚动
- 通过滚动条增加谷歌地图上的圆圈半径
- 如何在用户滚动时更新谷歌地图中心
- 谷歌地图缩放滚动条不会出现在新版本中
- 谷歌地图api之后,网页滚动被禁用
- 在wordpress网站的帖子之间插入谷歌广告,并进行无限滚动