-
Notifications
You must be signed in to change notification settings - Fork 4
/
EventAnalytics-1.0.min.js
1 lines (1 loc) · 7.82 KB
/
EventAnalytics-1.0.min.js
1
if(typeof String.prototype.startsWith!="function"){String.prototype.startsWith=function(a){return this.indexOf(a)===0}}var EventAnalytics=EventAnalytics||{};EventAnalytics.Hostname=window.location.host||window.location.hostname;EventAnalytics.IsPiwik=false;EventAnalytics.IsGA=false;EventAnalytics.Init=function(){if(Piwik!==null&&typeof(Piwik)==="object"){EventAnalytics.IsPiwik=true;EventAnalytics.Tracker=Piwik.getAsyncTracker();EventAnalytics._Init()}else{if(ga!==null&&typeof(ga)==="function"){EventAnalytics.IsGA=true;EventAnalytics._Init()}else{console.log("No Piwik or GA analytics library detected!")}}};EventAnalytics._Init=function(){EventAnalytics.InitVisitor();EventAnalytics.RegisterLateEventData();EventAnalytics.RegisterDelayEventData();var a={"25":false,"50":false,"75":false};EventAnalytics.Scroll=a;EventAnalytics.InitScrollEvents();EventAnalytics.InitTextSelection()};EventAnalytics.RegisterNewVisitorCallback=function(b,a){a=typeof a!=="undefined"?a:25;if(EventAnalytics.IsNewVisitor){setTimeout(b,a)}};EventAnalytics.RegisterReturingVisitorCallback=function(b,a){a=typeof a!=="undefined"?a:25;if(!EventAnalytics.IsNewVisitor){setTimeout(b,a)}};EventAnalytics.RegisterLateEventData=function(){var b=window.location.hash;if(b.startsWith("#_ea_pwkdt_=")){window.location.hash="";var a=b.replace("#_ea_pwkdt_=","").split(";");EventAnalytics.RegisterUIEvent(a[0],a[1],a[2],a[3])}};EventAnalytics.RegisterDelayEventData=function(){var a=EventAnalytics.CookieStorage.read("_ea_pwkdt_");if(a!=null&&a!=""){var b=a.split("|");EventAnalytics.RegisterUIEvent(b[0],b[1],b[2],b[3]);EventAnalytics.CookieStorage.erase("_ea_pwkdt_")}};EventAnalytics.InitScrollEvents=function(){var a=$(document).height()-$(window).height();$(window).scroll(function(){if($(window).scrollTop()>25){if($(window).scrollTop()>3*(a/4)&&EventAnalytics.Scroll["75"]==false){EventAnalytics.Scroll["75"]=true;EventAnalytics.RegisterUIEvent("Window","scroll","scroll75")}else{if($(window).scrollTop()>2*(a/4)&&EventAnalytics.Scroll["50"]==false){EventAnalytics.Scroll["50"]=true;EventAnalytics.RegisterUIEvent("Window","scroll","scroll50")}else{if($(window).scrollTop()>(a/4)&&EventAnalytics.Scroll["25"]==false){EventAnalytics.Scroll["25"]=true;EventAnalytics.RegisterUIEvent("Window","scroll","scroll25")}}}}})};EventAnalytics.InitVisitor=function(){if(EventAnalytics.IsGA){EventAnalytics.InitVisitorGA()}else{if(EventAnalytics.IsPiwik){EventAnalytics.InitVisitorPiwik()}}};EventAnalytics.InitVisitorPiwik=function(){var a=EventAnalytics.Tracker.getVisitorInfo();EventAnalytics.IsNewVisitor=a[0];EventAnalytics.VisitorID=a[1];EventAnalytics.ProfileCreationTimestamp=a[2];EventAnalytics.NumberOfVisits=a[3];EventAnalytics.CurrentVisitTimestamp=a[4];EventAnalytics.LastVisitTimestamp=a[5];EventAnalytics.LastEcommerceOrderTimestamp=a[6];if(EventAnalytics.NumberOfVisits==1){EventAnalytics.IsNewVisitor=1}else{EventAnalytics.IsNewVisitor=0}};EventAnalytics.InitVisitorGA=function(){var b=EventAnalytics.CookieStorage.read("_ga").split(".");EventAnalytics.IsNewVisitor=true;EventAnalytics.VisitorID=b[2];EventAnalytics.ProfileCreationTimestamp=b[3];EventAnalytics.NumberOfVisits=0;EventAnalytics.CurrentVisitTimestamp=false;EventAnalytics.LastVisitTimestamp=false;EventAnalytics.LastEcommerceOrderTimestamp=false;var d=new Date().getTime();var a=d-(EventAnalytics.ProfileCreationTimestamp*1000);var c=a/1000/60/60;console.log(c);if(EventAnalytics.ProfileCreationTimestamp>2){EventAnalytics.IsNewVisitor=false}};EventAnalytics.InitTextSelection=function(){EventAnalytics.Utils.StartListenSelectTextEvent(EventAnalytics._TextSelectCallBack)};EventAnalytics._TextSelectCallBack=function(a){EventAnalytics.RegisterUIEvent("document","selection","text",a)};EventAnalytics.RegisterUIEvent=function(c,e,b,d){var a="UI_"+c;if(EventAnalytics.IsGA){ga("send","event",a,e,b,d)}else{if(EventAnalytics.IsPiwik){EventAnalytics.Tracker.trackEvent(a,e,b,d)}}};EventAnalytics.RegisterCustomDimension=function(a,b){if(EventAnalytics.IsGA){ga("send","pageview",{index:b})}else{if(EventAnalytics.IsPiwik){EventAnalytics.Tracker.setCustomDimension(a,b)}}};EventAnalytics.ParseNameVariables=function(d,a){var b=$(d.target);var c="unkwown";if(a=="%content"){c=b.text().trim()}else{if(a=="%title"){c=b.attr("title").trim()}else{if(a=="%parentcontent"){c=b.parent().text().trim()}else{if(a=="%parenttitle"){c=b.parent().attr("title").trim()}else{c=a}}}}return c};EventAnalytics.RegisterDOMEvent=function(a,b,d,f,c,e){$(a).on(b,function(h){var g=EventAnalytics.ParseNameVariables(h,c);EventAnalytics.RegisterUIEvent(d,f,g,e)})};EventAnalytics.LateRegisterDOMEvent=function(a,b,d,f,c,e){$(a).on(b,function(j){var h=$(j.target);var i=EventAnalytics.ParseNameVariables(j,c);if(h.prop("tagName")=="A"){var g=h.attr("href");if(g.indexOf("#")===-1){h.attr("href",g+"#_ea_pwkdt_="+d+"_late;"+f+";"+i+";"+e)}else{}}})};EventAnalytics.DelayRegisterDOMEvent=function(a,b,d,f,c,e){$(a).on(b,function(i){var g=$(i.target);var h=EventAnalytics.ParseNameVariables(i,c);EventAnalytics.CookieStorage.create("_ea_pwkdt_",d+"_delay|"+f+"|"+h+"|"+e);if(g.prop("tagName")=="A"){g.unbind("click");setTimeout(function(){window.location=$(g).attr("href")},125);return false}else{if(g.prop("tagName")=="FORM"){g.unbind("submit");setTimeout(function(){g.submit()},125);return false}}})};EventAnalytics.TrackFormInteraction=function(){var a=$("form.EventAnalytics");if(a.size()==1){a.find("input").each(function(b){EventAnalytics.RegisterInputFieldEvent(this)})}else{}};EventAnalytics.RegisterInputFieldEvent=function(b){var d=$(b).attr("type");var c=$(b).attr("name");var a=$(b).attr("id");if(!a){a=c}if(d!="hidden"){var e;if($(b).attr("placeholder")){e=$(b).attr("placeholder")}else{e=$('label[for="'+a+'"]').text()}$(b).attr("data-input-name",e);$(b).on("focus",EventAnalytics.InputInteractionDetectorCallback);$(b).on("keyup",EventAnalytics.InputInteractionDetectorCallback)}};EventAnalytics.InputInteractionDetectorCallback=function(b){var c=$(b.target);console.log(b.type);if(b.type=="keyup"){if(c.val()!=""){$(this).unbind(b.type);var a=$(this).attr("data-input-name");EventAnalytics.RegisterUIEvent("FormInput",b.type,a)}}else{if(b.type!="keyup"){$(this).unbind(b.type);var a=$(this).attr("data-input-name");EventAnalytics.RegisterUIEvent("FormInput",b.type,a)}}};EventAnalytics.CookieStorage=EventAnalytics.CookieStorage||{};EventAnalytics.CookieStorage.DefaultExpire=2;EventAnalytics.CookieStorage.create=function(d,f,e){if(e){var c=new Date();c.setTime(c.getTime()+(e*60*1000));var a="; expires="+c.toGMTString()}else{var c=new Date();var b=EventAnalytics.CookieStorage.DefaultExpire*60*1000;c.setTime(c.getTime()+(b));var a="; expires="+c.toGMTString()}document.cookie=d+"="+f+a+"; path=/"};EventAnalytics.CookieStorage.read=function(d){var d=d+"=";var a=document.cookie.split(";");for(var b=0;b<a.length;b++){var e=a[b].trim();if(e.startsWith(d)){return e.split("=")[1]}}return null};EventAnalytics.CookieStorage.erase=function(a){EventAnalytics.CookieStorage.create(a,"",-1)};EventAnalytics.Utils=EventAnalytics.Utils||{};EventAnalytics.Utils.getSelectedText=function(){var a="";if(window.getSelection){a=window.getSelection().toString()}else{if(document.selection){a=document.selection.createRange().text}}return a};EventAnalytics.Utils.LastSelectedText=false;EventAnalytics.Utils.SelectTextEventFired=false;EventAnalytics.Utils.StartListenSelectTextEvent=function(a){$("*").not("a").on("mouseup touchend onselectstart onselectend onselectionchange",function(b){b.preventDefault();if(!EventAnalytics.Utils.SelectTextEventFired){var c=EventAnalytics.Utils.getSelectedText();if(c!=""&&c!=EventAnalytics.Utils.LastSelectedText){EventAnalytics.Utils.LastSelectedText=c;a(c)}EventAnalytics.Utils.SelectTextEventFired=true;setTimeout(function(){EventAnalytics.Utils.SelectTextEventFired=false},50)}})};EventAnalytics.Utils.getMetadata=function(){var c=document.title;var b=$("meta[name='description']").attr("content");var a=$("meta[name='keywords']").attr("content")};