/*! adjusted-bounce-rate - v1.2.1 - 2015-04-06 */ /*! * JavaScript Debug - v0.4 - 6/22/2010 * http://benalman.com/projects/javascript-debug-console-log/ * * Copyright (c) 2010 "Cowboy" Ben Alman * Dual licensed under the MIT and GPL licenses. * http://benalman.com/about/license/ * * With lots of help from Paul Irish! * http://paulirish.com/ */ /*! * Adjusted Bounce Rate */ if("undefined"==typeof debug&&(window.debug=function(){function e(n){!f||!g&&d&&d.log||f.apply(i,n)}function k(n){return m>0?m>n:c.length+m<=n}for(var f,g,i=this,b=Array.prototype.slice,d=i.console,h={},m=9,c=["error","warn","info","debug","log"],l="assert clear count dir dirxml exception group groupCollapsed groupEnd profile profileEnd table time timeEnd trace".split(" "),j=l.length,a=[];--j>=0;)!function(n){h[n]=function(){0!==m&&d&&d[n]&&d[n].apply(d,arguments)}}(l[j]);for(j=c.length;--j>=0;)!function(n,o){h[o]=function(){var q=b.call(arguments),p=[o].concat(q);a.push(p),e(p),d&&k(n)&&(d.firebug?d[o].apply(i,q):d[o]?d[o](q):d.log(q))}}(j,c[j]);return h.setLevel=function(n){m="number"==typeof n?n:9},h.setCallback=function(){var o=b.call(arguments),n=a.length,p=n;for(f=o.shift()||null,g="boolean"==typeof o[0]?o.shift():!1,p-="number"==typeof o[0]?o.shift():n;n>p;)e(a[p++])},h}()),"undefined"==typeof gkn||!gkn)var gkn={};!function($){gkn.AdjustedBounceRate=function(){var startTime,elapsedTime,timer,gaTracking,sandboxMode=!1,hitCount=0,elapsedSecs=0,_self={init:function(_options){_self.options=_options,_self.options.debug_mode!==!0&&debug.setLevel(0),_self.options.debug_mode&&debug.log("Adjusted_Bounce_Rate.init(): _self.options="+JSON.stringify(_self.options)),"undefined"!=typeof window.pageTracker||"undefined"!=typeof window._gaq||"undefined"!=typeof window.ga||"undefined"!=typeof window.__gaTracker?(_self.initAjaxify(),_self.options.min_engagement_seconds>0?setTimeout(this.start,1e3*_self.options.min_engagement_seconds):this.start()):_self.options.debug_mode&&debug.log("Adjusted Bounce Rate: GA is not loaded.")},initAjaxify:function(){$(window).on("statechangecomplete",function(){_self.restart()})},start:function(){_self.options.debug_mode&&debug.log("Adjusted_Bounce_Rate.start()"),startTime=new Date,elapsedTime=startTime,hitCount=0,elapsedSecs=0,_self.tick(!0),timer=setInterval(_self.tick,500)},restart:function(){_self.options.debug_mode&&debug.log("Adjusted_Bounce_Rate.restart()"),_self.stop(),_self.options.min_engagement_seconds>0?setTimeout(this.start,1e3*_self.options.min_engagement_seconds):this.start()},stop:function(){var elapsedTime=_self.formatElapsedTime(elapsedSecs);_self.options.debug_mode&&debug.log('Adjusted_Bounce_Rate.stop(): stopped after "'+elapsedTime+'" ('+elapsedSecs+" seconds)."),clearInterval(timer)},tick:function(firstTick){"undefined"==typeof firstTick&&(firstTick=!1);var now=new Date,elapsedDiff=_self.dateDiff(elapsedTime,now,"seconds");(elapsedDiff>=_self.options.engagement_interval_seconds||firstTick===!0)&&(hitCount++,elapsedSecs=hitCount*_self.options.engagement_interval_seconds,_self.trackEvent(),elapsedTime=new Date),elapsedSecs>=_self.options.max_engagement_seconds&&_self.stop()},trackEvent:function(){var elapsedTime=_self.formatElapsedTime(elapsedSecs);_self.options.debug_mode&&debug.log("Adjusted_Bounce_Rate.trackEvent(): "+hitCount+" hits, elapsedSecs="+elapsedSecs+", elapsedTime="+elapsedTime),("undefined"==typeof gaTracking||""==gaTracking)&&("undefined"!=typeof window.pageTracker?gaTracking="pageTracker":"undefined"!=typeof window._gaq?gaTracking="_gaq":"undefined"!=typeof window.ga?gaTracking="ga":"undefined"!=typeof window.__gaTracker&&(gaTracking="__gaTracker")),sandboxMode||("pageTracker"==gaTracking?window.pageTracker._trackEvent(_self.options.engagement_event_category,_self.options.engagement_event_action,elapsedTime,elapsedSecs||0):"_gaq"==gaTracking?window._gaq.push(["_trackEvent",_self.options.engagement_event_category,_self.options.engagement_event_action,elapsedTime,elapsedSecs||0]):"ga"==gaTracking?ga("send",{hitType:"event",eventCategory:_self.options.engagement_event_category,eventAction:_self.options.engagement_event_action,eventLabel:elapsedTime,eventValue:elapsedSecs||0}):"__gaTracker"==gaTracking?__gaTracker("send",{hitType:"event",eventCategory:_self.options.engagement_event_category,eventAction:_self.options.engagement_event_action,eventLabel:elapsedTime,eventValue:elapsedSecs||0}):debug.warn("Adjusted_Bounce_Rate: [warning] No supported version of Google Analytics script seems to be loaded."))},formatElapsedTime:function(totalSecs){var mins=Math.floor(totalSecs/60),secs=totalSecs%60;return 10>mins&&(mins="0"+mins),10>secs&&(secs="0"+secs),mins+":"+secs},dateDiff:function(fromDate,toDate,interval){var second=1e3,minute=60*second;interval||(interval="milliseconds"),"string"==typeof fromDate&&(fromDate=new Date(fromDate)),"string"==typeof toDate&&(toDate=new Date(toDate));var timeDiff=toDate-fromDate;if(isNaN(timeDiff))return 0/0;switch(interval){case"years":return toDate.getFullYear()-fromDate.getFullYear();case"months":return 12*toDate.getFullYear()+toDate.getMonth()-(12*fromDate.getFullYear()+fromDate.getMonth());case"weeks":return Math.floor(timeDiff/week);case"days":return Math.floor(timeDiff/day);case"hours":return Math.floor(timeDiff/hour);case"minutes":return Math.floor(timeDiff/minute);case"seconds":return Math.floor(timeDiff/second);case"milliseconds":return timeDiff;default:return void 0}}};return _self}()}(jQuery);