javascript - calling Google analytics in scroll event in jquery -


i have following code in master page google analytics.

<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(); = 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> 

i need call google analytics in js scroll event how call google analytics function scroll event ? can please me how solve this. ?

a guy worked here in company developed library use google analytics classic, took track scroll plugin , adapted fire universal google analytics, here code: (if have doubts, ask me)

/**   * gas - google analytics on steroids   *   * max-scroll tracking plugin   *   * copyright 2011, cardinal path , direct performance   * licensed under gplv3 license.   *   * @author eduardo cereto <eduardocereto@gmail.com>   */    var _maxscrollopts;    /**   * current browser viewpane heigtht   *   * @return {number} height.   */  function _get_window_height() {      return window.innerheight || documentelement.clientheight ||          document.body.clientheight || 0;  }    /**   * current absolute window scroll position   *   * @return {number} yscroll.   */  function _get_window_yscroll() {      return window.pageyoffset || document.body.scrolltop ||          documentelement.scrolltop || 0;  }    /**   * 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      );  }      /**   * 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 max scroll on page.   *   * @param {object} opts gas options used.   * @this {gashelper} 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();


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -