Skip to content
Browse files

Revert form tracking to use DOMReady instead of delegate. Thi is a te…

…mporary solution that works better now. I want to find a better solution to form tracking in the future.

Ref: #17.
  • Loading branch information...
1 parent dc4816f commit dc9e0ba266b859b018483e286bc3ec9542cd1c00 @eduardocereto eduardocereto committed Mar 1, 2012
Showing with 37 additions and 7 deletions.
  1. +18 −3 dist/gas.js
  2. +1 −1 dist/gas.min.js
  3. +18 −3 src/plugins/form_tracking.js
View
21 dist/gas.js
@@ -655,9 +655,24 @@ _gas.push(['_addHook', '_trackForms', function(opts) {
_gas.push(['_trackEvent', opts['category'], action, label]);
}
- scp._liveEvent('input,select,textarea,hidden', 'change', trackField);
- //scp._liveEvent('button,submit,image,reset', 'click', trackField);
- scp._liveEvent('form', 'submit', trackField);
+ scp._DOMReady(function() {
+ var changeTags = ['input', 'select', 'textarea', 'hidden'];
+ var submitTags = ['form'];
+ var elements = [];
+ var i, j;
+ for (i = 0; i < changeTags.length; i++) {
+ elements = document.getElementsByTagName(changeTags[i]);
+ for (j = 0; j < elements.length; j++) {
+ scp._addEventListener(elements[j], 'change', trackField);
+ }
+ }
+ for (i = 0; i < submitTags.length; i++) {
+ elements = document.getElementsByTagName(submitTags[i]);
+ for (j = 0; j < elements.length; j++) {
+ scp._addEventListener(elements[j], 'submit', trackField);
+ }
+ }
+ });
}]);
View
2 dist/gas.min.js
@@ -6,4 +6,4 @@
*
* @author Eduardo Cereto <eduardocereto@gmail.com>
* Licensed under the MIT license.
- */(function(a,b){function o(){var a=this;a.version="1.3.5",a._accounts={},a._accounts_length=0,a._queue=d,a._default_tracker="_gas1",a.gh={},a._hooks={_addHook:[a._addHook]},a.push(function(){a.gh=new c})}function p(a){return a===_gas._default_tracker?"":a+"."}function q(b){if(_gas.debug_mode)try{console.log(b)}catch(c){}return a._gaq.push(b)}function r(a,b){if(typeof a!="string")return!1;var c=a.split("?")[0];return c=c.split("."),c=c[c.length-1],c&&this.inArray(b,c)?c:!1}function s(a){var b=this;b._liveEvent("a","mousedown",function(c){var d=this;if(d.href){var e=r.call(b,d.href,a.extensions);e&&_gas.push(["_trackEvent",a.category,e,d.href])}})}function t(a){while(a&&a.nodeName!=="HTML"){if(a.nodeName==="FORM")break;a=a.parentNode}return a.nodeName==="FORM"?a.name||a.id||"none":"none"}function u(a){_gas.push(["_trackEvent",this.tagName,a.type,this.currentSrc])}function v(a){var b=this;b._liveEvent(a,"play",u),b._liveEvent(a,"pause",u),b._liveEvent(a,"ended",u)}function w(){if(!!this._videoTracked)return;this._videoTracked=!0,v.call(this,"video")}function x(){if(!!this._audioTracked)return;this._audioTracked=!0,v.call(this,"audio")}function y(){return a.innerHeight||n.clientHeight||e.body.clientHeight||0}function z(){return a.pageYOffset||e.body.scrollTop||n.scrollTop||0}function A(){return Math.max(e.body.scrollHeight||0,n.scrollHeight||0,e.body.offsetHeight||0,n.offsetHeight||0,e.body.clientHeight||0,n.clientHeight||0)}function B(){return(z()+y())/A()*100}function E(a){C&&clearTimeout(C);if(a===!0){D=Math.max(B(),D);return}C=setTimeout(function(){D=Math.max(B(),D)},400)}function F(){E(!0),D=Math.floor(D);if(D<=0||D>100)return;var a=(D>10?1:0)*(Math.floor((D-1)/10)*10+1);a=String(a)+"-"+String(Math.ceil(D/10)*10),_gas.push(["_trackEvent",G.category,m,a,Math.floor(D),!0])}function H(b){if(!!this._maxScrollTracked)return;this._maxScrollTracked=!0,G=b||{},G.category=G.category||"Max Scroll",this._addEventListener(a,"scroll",E),this._addEventListener(a,"beforeunload",F)}function K(a){if(!this._multidomainTracked){this._multidomainTracked=!0;var b=e.location.hostname,c=this,d,f,g,h=e.getElementsByTagName("a");a!=="now"&&a!=="mousedown"&&(a="click");for(d=0;d<h.length;d++){g=h[d];if(k.call(g.href,"http")===0){if(g.hostname==b||k.call(g.hostname,J)>=0)continue;for(f=0;f<I.length;f++)k.call(g.hostname,I[f])>=0&&(a==="now"?g.href=c.tracker._getLinkerUrl(g.href,_gas._allowAnchor):a==="click"?this._addEventListener(g,a,function(a){return _gas.push(["_link",this.href,_gas._allowAnchor]),a.preventDefault?a.preventDefault():a.returnValue=!1,!1}):this._addEventListener(g,a,function(){this.href=c.tracker._getLinkerUrl(this.href,_gas._allowAnchor)}))}}return!1}return}function L(a){if(!!this._outboundTracked)return;this._outboundTracked=!0;var b=this;a||(a={}),a.category=a.category||"Outbound",b._liveEvent("a","mousedown",function(b){var c=this;if((c.protocol=="http:"||c.protocol=="https:")&&k.call(c.href,e.location.hostname)===-1){var d=c.pathname+c.search+"",f=k.call(d,"__utm");f!==-1&&(d=d.substring(0,f)),_gas.push(["_trackEvent",a.category,c.hostname,d])}})}function P(a){N[a.player_id]||(N[a.player_id]={},N[a.player_id].timeTriggers=i.call(M));if(N[a.player_id].timeTriggers.length>0&&a.data.percent*100>=N[a.player_id].timeTriggers[0]){var b=N[a.player_id].timeTriggers.shift();_gas.push(["_trackEvent","Vimeo Video",b+"%",O[a.player_id]])}}function Q(a,b,c){if(!c.contentWindow||!c.contentWindow.postMessage||!JSON)return!1;var d=c.getAttribute("src").split("?")[0],e=JSON.stringify({method:a,value:b});return c.contentWindow.postMessage(e,d),!0}function T(a){if(k.call(a.origin,"//player.vimeo.com")>-1){var b=JSON.parse(a.data);b.event==="ready"?U.call(_gas.gh):b.method?b.method=="getVideoUrl"&&(O[b.player_id]=b.value):b.event==="playProgress"?P(b):_gas.push(["_trackEvent",S.category,b.event,O[b.player_id]])}}function U(){var b=e.getElementsByTagName("iframe"),c=0,d,f,g,h=S.force,i=S.percentages;for(var j=0;j<b.length;j++)if(k.call(b[j].src,"//player.vimeo.com")>-1){d="gas_vimeo_"+j,f=b[j].src,g="?",k.call(f,"?")>-1&&(g="&");if(k.call(f,"api=1")<0){if(!h)continue;f+=g+"api=1&player_id="+d}else k.call(f,"player_id=")<-1&&(f+=g+"player_id="+d);c++,b[j].id=d;if(b[j].src!==f){b[j].src=f;break}Q("getVideoUrl","",b[j]),Q("addEventListener","play",b[j]),Q("addEventListener","pause",b[j]),Q("addEventListener","finish",b[j]),i&&(M=i,Q("addEventListener","playProgress",b[j]))}c>0&&R===!1&&(this._addEventListener(a,"message",T,!1),R=!0)}function Y(a){if(V&&V.length){var b=a.getVideoData().video_id;X[b]?$(a):(X[b]={},X[b].timeTriggers=i.call(V)),X[b].timer=setTimeout(Z,1e3,a,b)}}function Z(a,c){if(X[c]==b||X[c].timeTriggers.length<=0)return!1;var d=a.getCurrentTime()/a.getDuration()*100;if(d>=X[c].timeTriggers[0]){var e=X[c].timeTriggers.shift();_gas.push(["_trackEvent",W.category,e+"%",a.getVideoUrl()])}X[c].timer=setTimeout(Z,1e3,a,c)}function $(a){var b=a.getVideoData().video_id;X[b]&&X[b].timer&&(Z(a,b),clearTimeout(X[b].timer))}function _(a){var b="";switch(a.data){case 0:b="finish",$(a.target);break;case 1:b="play",Y(a.target);break;case 2:b="pause",$(a.target)}b&&_gas.push(["_trackEvent",W.category,b,a.target.getVideoUrl()])}function ba(a){_gas.push(["_trackEvent",W.category,"error ("+a.data+")",a.target.getVideoUrl()])}function bb(){var a=e.getElementsByTagName("object"),b,c,d,f=/(https?:\/\/www\.youtube(-nocookie)?\.com[^/]*).*\/v\/([^&?]+)/;for(var g=0;g<a.length;g++){b=a[g].getElementsByTagName("param");for(var h=0;h<b.length;h++)if(b[h].name=="movie"&&b[h].value){d=b[h].value.match(f),d&&d[1]&&d[3]&&(c=e.createElement("iframe"),c.src=d[1]+"/embed/"+d[3]+"?enablejsapi=1",c.width=a[g].width,c.height=a[g].height,c.setAttribute("frameBorder","0"),c.setAttribute("allowfullscreen",""),a[g].parentNode.insertBefore(c,a[g]),a[g].parentNode.removeChild(a[g]),g--);break}}}function bc(b){var c=b.force,d=b.percentages;if(c)try{bb()}catch(f){_gas.push(["_trackException",f,"GAS Error on youtube.js:_ytMigrateObjectEmbed"])}var g=[],h=e.getElementsByTagName("iframe");for(var i=0;i<h.length;i++)if(k.call(h[i].src,"//www.youtube.com/embed")>-1){if(k.call(h[i].src,"enablejsapi=1")<0){if(!c)continue;k.call(h[i].src,"?")<0?h[i].src+="?enablejsapi=1":h[i].src+="&enablejsapi=1"}g.push(h[i])}if(g.length>0){d&&d.length&&(V=d),a.onYouTubePlayerAPIReady=function(){var b;for(var c=0;c<g.length;c++)b=new a.YT.Player(g[c]),b.addEventListener("onStateChange",_),b.addEventListener("onError",ba)};var j=e.createElement("script"),l="http:";e.location.protocol==="https:"&&(l="https:"),j.src=l+"//www.youtube.com/player_api",j.type="text/javascript",j.async=!0;var m=e.getElementsByTagName("script")[0];m.parentNode.insertBefore(j,m)}}var c=function(){this._setDummyTracker()};c.prototype._setDummyTracker=function(){if(!this.tracker){var b=a._gat._getTrackers();b.length>0&&(this.tracker=b[0])}},c.prototype.inArray=function(a,b){if(a&&a.length)for(var c=0;c<a.length;c++)if(a[c]===b)return!0;return!1},c.prototype.isArray=function(a){return f.call(a)==="[object Array]"},c.prototype._sanitizeString=function(a,b){return a=a.toLowerCase().replace(/^\ +/,"").replace(/\ +$/,"").replace(/\s+/g,"_").replace(/[áàâãåäæª]/g,"a").replace(/[éèêëЄ€]/g,"e").replace(/[íìîï]/g,"i").replace(/[óòôõöøº]/g,"o").replace(/[úùûü]/g,"u").replace(/[碩]/g,"c"),b&&(a=a.replace(/[^a-z0-9_-]/g,"_")),a.replace(/_+/g,"_")},c.prototype._addEventListener=function(b,c,d,e){var f=function(c){if(!c||!c.target)c=a.event,c.target=c.srcElement;return d.call(b,c)};return b.addEventListener?(b.addEventListener(c,f,!!e),!0):b.attachEvent?b.attachEvent("on"+c,f):(c="on"+c,typeof b[c]=="function"&&(f=function(a,b){return function(){a.apply(this,arguments),b.apply(this,arguments)}}(b[c],f)),b[c]=f,!0)},c.prototype._liveEvent=function(a,b,c){var d=this;a=a.toUpperCase(),a=a.split(","),d._addEventListener(e,b,function(b){for(var e=b.srcElement;e.nodeName!=="HTML";e=e.parentNode)if(d.inArray(a,e.nodeName)||e.parentNode===null)break;e&&d.inArray(a,e.nodeName)&&c.call(e,b)},!0)},c.prototype._DOMReady=function(b){var c=this,d=function(){if(arguments.callee.done)return;arguments.callee.done=!0,b.apply(c,arguments)};if(/^(interactive|complete)/.test(e.readyState))return d();this._addEventListener(e,"DOMContentLoaded",d,!1),this._addEventListener(a,"load",d,!1)},a._gaq=a._gaq||[];var d=a._gas||[];if(d._accounts_length>=0)return;var e=a.document,f=Object.prototype.toString,g=Object.prototype.hasOwnProperty,h=Array.prototype.push,i=Array.prototype.slice,j=String.prototype.trim,k=String.prototype.indexOf,l=Array.prototype.indexOf,m=e.location.href,n=e.documentElement;o.prototype._addHook=function(a,b){return typeof a=="string"&&typeof b=="function"&&(typeof _gas._hooks[a]=="undefined"&&(_gas._hooks[a]=[]),_gas._hooks[a].push(b)),!1},o.prototype._execute=function(){var a=i.call(arguments),c=this,d=a.shift(),e=!0,f,h,j,l,m,n=0;if(typeof d=="function")return q(function(a,b){return function(){a.call(b)}}(d,c.gh));if(typeof d=="object"&&d.length>0){h=d.shift(),k.call(h,".")>=0?(l=h.split(".")[0],h=h.split(".")[1]):l=b,j=c._hooks[h];if(j&&j.length>0)for(f=0;f<j.length;f++)try{m=j[f].apply(c.gh,d),m===!1?e=!1:m&&m.length>0&&(d=m)}catch(o){h!=="_trackException"&&c.push(["_trackException",o])}if(e===!1)return 1;if(h==="_setAccount"){for(f in c._accounts)if(c._accounts[f]==d[0]&&l===b)return 1;return l=l||"_gas"+String(c._accounts_length+1),typeof c._accounts["_gas1"]=="undefined"&&k.call(l,"_gas")!=-1&&(l="_gas1"),c._accounts[l]=d[0],c._accounts_length+=1,l=p(l),n=q([l+h,d[0]]),c.gh._setDummyTracker(),n}if(h==="_link"||h==="_linkByPost")return a=i.call(d),a.unshift(h),q(a);var r;if(l&&c._accounts[l])return r=p(l)+h,a=i.call(d),a.unshift(r),q(a);for(f in c._accounts)g.call(c._accounts,f)&&(r=p(f)+h,a=i.call(d),a.unshift(r),n+=q(a));return n?1:0}},o.prototype.push=function(){var b=this,c=i.call(arguments);for(var d=0;d<c.length;d++)(function(b,c){a._gaq.push(function(){c._execute.call(c,b)})})(c[d],b)},a._gas=_gas=new o,_gas.push(["_addHook","_trackException",function(a,b){return _gas.push(["_trackEvent","Exception "+(a.name||"Error"),b||a.message||a,m]),!1}]),_gas.push(["_addHook","_setDebug",function(a){_gas.debug_mode=!!a}]),_gas.push(["_addHook","_popHook",function(a){var b=_gas._hooks[a];return b&&b.pop&&b.pop(),!1}]),_gas.push(["_addHook","_setDefaultTracker",function(a){_gas._default_tracker=a}]),_gas.push(["_addHook","_trackPageview",function(){var a=i.call(arguments);return a.length>=2&&typeof a[0]=="string"&&typeof a[1]=="string"?[{page:a[0],title:a[1]}]:a}]),_gas.push(["_addHook","_trackDownloads",function(a){if(!this._downloadTracked){this._downloadTracked=!0,a?typeof a=="string"?a={extensions:a.split(",")}:a.length>=1&&(a={extensions:a}):a={extensions:[]},a.category=a.category||"Download";var b="xls,xlsx,doc,docx,ppt,pptx,pdf,txt,zip";return b+=",rar,7z,exe,wma,mov,avi,wmv,mp3,csv,tsv",b=b.split(","),a.extensions=a.extensions.concat(b),s.call(this,a),!1}return}]),_gas.push(["_addHook","_trackEvent",function(){var a=i.call(arguments);return a[3]&&(a[3]=(a[3]<0?0:Math.round(a[3]))||0),a}]),_gas.push(["_addHook","_trackForms",function(a){if(!!this._formTracked)return;this._formTracked=!0;var b=this;typeof a!="object"&&(a={}),a.category=a.category||"Form Tracking";var c=function(b){var c=b.target,d=c.name||c.id||c.type||c.nodeName,e=t(c),f="form ("+e+")",g=d+" ("+b.type+")";_gas.push(["_trackEvent",a.category,f,g])};b._liveEvent("input,select,textarea,hidden","change",c),b._liveEvent("form","submit",c)}]),_gas.push(["_addHook","_trackVideo",w]),_gas.push(["_addHook","_trackAudio",x]),_gas.push(["_addHook","_trackMailto",function(a){if(!this._mailtoTracked)return this._mailtoTracked=!0,a||(a={}),a.category=a.category||"Mailto",this._liveEvent("a","mousedown",function(b){var c=b.target;c&&c.href&&c.href.toLowerCase().indexOf("mailto:")===0&&_gas.push(["_trackEvent",a.category,c.href.substr(7)])}),!1;return}]);var C=null,D=0,G;_gas.push(["_addHook","_trackMaxScroll",H]),_gas._allowAnchor=!1,_gas.push(["_addHook","_setAllowAnchor",function(a){_gas._allowAnchor=!!a}]),_gas.push(["_addHook","_link",function(a,c){return c===b&&(c=_gas._allowAnchor),[a,c]}]),_gas.push(["_addHook","_linkByPost",function(a,c){return c===b&&(c=_gas._allowAnchor),[a,c]}]);var I=[],J=b;_gas.push(["_addHook","_setDomainName",function(a){if(k.call("."+e.location.hostname,a)<0)return I.push(a),!1;J=a}]),_gas.push(["_addHook","_addExternalDomainName",function(a){return I.push(a),!1}]),_gas.push(["_addHook","_setMultiDomain",K]),_gas.push(["_addHook","_trackOutboundLinks",L]);var M=[],N={},O={},R=!1,S;_gas.push(["_addHook","_trackVimeo",function(a){var b=this;if(typeof a=="boolean"||a==="force")a={force:!!a};return a=a||{},a.category=a.category||"Vimeo Video",a.percentages=a.percentages||[],a.force=a.force||!1,S=a,b._DOMReady(function(){U.call(b)}),!1}]);var V=[],W,X={};_gas.push(["_addHook","_trackYoutube",function(a){var b=i.call(arguments);!b[0]||typeof b[0]!="boolean"&&b[0]!=="force"?a={}:a={force:!!b[0]},b[1]&&b[1].length&&(a.percentages=b[1]),a=a||{},a.force=a.force||!1,a.category=a.category||"YouTube Video",a.percentages=a.percentages||[],W=a;var c=this;return c._DOMReady(function(){bc.call(c,a)}),!1}]);while(_gas._queue.length>0)_gas.push(_gas._queue.shift());_gaq&&_gaq.length>=0&&function(){var a=e.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"==e.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";var b=e.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)}()})(window);
+ */(function(a,b){function o(){var a=this;a.version="1.3.5",a._accounts={},a._accounts_length=0,a._queue=d,a._default_tracker="_gas1",a.gh={},a._hooks={_addHook:[a._addHook]},a.push(function(){a.gh=new c})}function p(a){return a===_gas._default_tracker?"":a+"."}function q(b){if(_gas.debug_mode)try{console.log(b)}catch(c){}return a._gaq.push(b)}function r(a,b){if(typeof a!="string")return!1;var c=a.split("?")[0];return c=c.split("."),c=c[c.length-1],c&&this.inArray(b,c)?c:!1}function s(a){var b=this;b._liveEvent("a","mousedown",function(c){var d=this;if(d.href){var e=r.call(b,d.href,a.extensions);e&&_gas.push(["_trackEvent",a.category,e,d.href])}})}function t(a){while(a&&a.nodeName!=="HTML"){if(a.nodeName==="FORM")break;a=a.parentNode}return a.nodeName==="FORM"?a.name||a.id||"none":"none"}function u(a){_gas.push(["_trackEvent",this.tagName,a.type,this.currentSrc])}function v(a){var b=this;b._liveEvent(a,"play",u),b._liveEvent(a,"pause",u),b._liveEvent(a,"ended",u)}function w(){if(!!this._videoTracked)return;this._videoTracked=!0,v.call(this,"video")}function x(){if(!!this._audioTracked)return;this._audioTracked=!0,v.call(this,"audio")}function y(){return a.innerHeight||n.clientHeight||e.body.clientHeight||0}function z(){return a.pageYOffset||e.body.scrollTop||n.scrollTop||0}function A(){return Math.max(e.body.scrollHeight||0,n.scrollHeight||0,e.body.offsetHeight||0,n.offsetHeight||0,e.body.clientHeight||0,n.clientHeight||0)}function B(){return(z()+y())/A()*100}function E(a){C&&clearTimeout(C);if(a===!0){D=Math.max(B(),D);return}C=setTimeout(function(){D=Math.max(B(),D)},400)}function F(){E(!0),D=Math.floor(D);if(D<=0||D>100)return;var a=(D>10?1:0)*(Math.floor((D-1)/10)*10+1);a=String(a)+"-"+String(Math.ceil(D/10)*10),_gas.push(["_trackEvent",G.category,m,a,Math.floor(D),!0])}function H(b){if(!!this._maxScrollTracked)return;this._maxScrollTracked=!0,G=b||{},G.category=G.category||"Max Scroll",this._addEventListener(a,"scroll",E),this._addEventListener(a,"beforeunload",F)}function K(a){if(!this._multidomainTracked){this._multidomainTracked=!0;var b=e.location.hostname,c=this,d,f,g,h=e.getElementsByTagName("a");a!=="now"&&a!=="mousedown"&&(a="click");for(d=0;d<h.length;d++){g=h[d];if(k.call(g.href,"http")===0){if(g.hostname==b||k.call(g.hostname,J)>=0)continue;for(f=0;f<I.length;f++)k.call(g.hostname,I[f])>=0&&(a==="now"?g.href=c.tracker._getLinkerUrl(g.href,_gas._allowAnchor):a==="click"?this._addEventListener(g,a,function(a){return _gas.push(["_link",this.href,_gas._allowAnchor]),a.preventDefault?a.preventDefault():a.returnValue=!1,!1}):this._addEventListener(g,a,function(){this.href=c.tracker._getLinkerUrl(this.href,_gas._allowAnchor)}))}}return!1}return}function L(a){if(!!this._outboundTracked)return;this._outboundTracked=!0;var b=this;a||(a={}),a.category=a.category||"Outbound",b._liveEvent("a","mousedown",function(b){var c=this;if((c.protocol=="http:"||c.protocol=="https:")&&k.call(c.href,e.location.hostname)===-1){var d=c.pathname+c.search+"",f=k.call(d,"__utm");f!==-1&&(d=d.substring(0,f)),_gas.push(["_trackEvent",a.category,c.hostname,d])}})}function P(a){N[a.player_id]||(N[a.player_id]={},N[a.player_id].timeTriggers=i.call(M));if(N[a.player_id].timeTriggers.length>0&&a.data.percent*100>=N[a.player_id].timeTriggers[0]){var b=N[a.player_id].timeTriggers.shift();_gas.push(["_trackEvent","Vimeo Video",b+"%",O[a.player_id]])}}function Q(a,b,c){if(!c.contentWindow||!c.contentWindow.postMessage||!JSON)return!1;var d=c.getAttribute("src").split("?")[0],e=JSON.stringify({method:a,value:b});return c.contentWindow.postMessage(e,d),!0}function T(a){if(k.call(a.origin,"//player.vimeo.com")>-1){var b=JSON.parse(a.data);b.event==="ready"?U.call(_gas.gh):b.method?b.method=="getVideoUrl"&&(O[b.player_id]=b.value):b.event==="playProgress"?P(b):_gas.push(["_trackEvent",S.category,b.event,O[b.player_id]])}}function U(){var b=e.getElementsByTagName("iframe"),c=0,d,f,g,h=S.force,i=S.percentages;for(var j=0;j<b.length;j++)if(k.call(b[j].src,"//player.vimeo.com")>-1){d="gas_vimeo_"+j,f=b[j].src,g="?",k.call(f,"?")>-1&&(g="&");if(k.call(f,"api=1")<0){if(!h)continue;f+=g+"api=1&player_id="+d}else k.call(f,"player_id=")<-1&&(f+=g+"player_id="+d);c++,b[j].id=d;if(b[j].src!==f){b[j].src=f;break}Q("getVideoUrl","",b[j]),Q("addEventListener","play",b[j]),Q("addEventListener","pause",b[j]),Q("addEventListener","finish",b[j]),i&&(M=i,Q("addEventListener","playProgress",b[j]))}c>0&&R===!1&&(this._addEventListener(a,"message",T,!1),R=!0)}function Y(a){if(V&&V.length){var b=a.getVideoData().video_id;X[b]?$(a):(X[b]={},X[b].timeTriggers=i.call(V)),X[b].timer=setTimeout(Z,1e3,a,b)}}function Z(a,c){if(X[c]==b||X[c].timeTriggers.length<=0)return!1;var d=a.getCurrentTime()/a.getDuration()*100;if(d>=X[c].timeTriggers[0]){var e=X[c].timeTriggers.shift();_gas.push(["_trackEvent",W.category,e+"%",a.getVideoUrl()])}X[c].timer=setTimeout(Z,1e3,a,c)}function $(a){var b=a.getVideoData().video_id;X[b]&&X[b].timer&&(Z(a,b),clearTimeout(X[b].timer))}function _(a){var b="";switch(a.data){case 0:b="finish",$(a.target);break;case 1:b="play",Y(a.target);break;case 2:b="pause",$(a.target)}b&&_gas.push(["_trackEvent",W.category,b,a.target.getVideoUrl()])}function ba(a){_gas.push(["_trackEvent",W.category,"error ("+a.data+")",a.target.getVideoUrl()])}function bb(){var a=e.getElementsByTagName("object"),b,c,d,f=/(https?:\/\/www\.youtube(-nocookie)?\.com[^/]*).*\/v\/([^&?]+)/;for(var g=0;g<a.length;g++){b=a[g].getElementsByTagName("param");for(var h=0;h<b.length;h++)if(b[h].name=="movie"&&b[h].value){d=b[h].value.match(f),d&&d[1]&&d[3]&&(c=e.createElement("iframe"),c.src=d[1]+"/embed/"+d[3]+"?enablejsapi=1",c.width=a[g].width,c.height=a[g].height,c.setAttribute("frameBorder","0"),c.setAttribute("allowfullscreen",""),a[g].parentNode.insertBefore(c,a[g]),a[g].parentNode.removeChild(a[g]),g--);break}}}function bc(b){var c=b.force,d=b.percentages;if(c)try{bb()}catch(f){_gas.push(["_trackException",f,"GAS Error on youtube.js:_ytMigrateObjectEmbed"])}var g=[],h=e.getElementsByTagName("iframe");for(var i=0;i<h.length;i++)if(k.call(h[i].src,"//www.youtube.com/embed")>-1){if(k.call(h[i].src,"enablejsapi=1")<0){if(!c)continue;k.call(h[i].src,"?")<0?h[i].src+="?enablejsapi=1":h[i].src+="&enablejsapi=1"}g.push(h[i])}if(g.length>0){d&&d.length&&(V=d),a.onYouTubePlayerAPIReady=function(){var b;for(var c=0;c<g.length;c++)b=new a.YT.Player(g[c]),b.addEventListener("onStateChange",_),b.addEventListener("onError",ba)};var j=e.createElement("script"),l="http:";e.location.protocol==="https:"&&(l="https:"),j.src=l+"//www.youtube.com/player_api",j.type="text/javascript",j.async=!0;var m=e.getElementsByTagName("script")[0];m.parentNode.insertBefore(j,m)}}var c=function(){this._setDummyTracker()};c.prototype._setDummyTracker=function(){if(!this.tracker){var b=a._gat._getTrackers();b.length>0&&(this.tracker=b[0])}},c.prototype.inArray=function(a,b){if(a&&a.length)for(var c=0;c<a.length;c++)if(a[c]===b)return!0;return!1},c.prototype.isArray=function(a){return f.call(a)==="[object Array]"},c.prototype._sanitizeString=function(a,b){return a=a.toLowerCase().replace(/^\ +/,"").replace(/\ +$/,"").replace(/\s+/g,"_").replace(/[áàâãåäæª]/g,"a").replace(/[éèêëЄ€]/g,"e").replace(/[íìîï]/g,"i").replace(/[óòôõöøº]/g,"o").replace(/[úùûü]/g,"u").replace(/[碩]/g,"c"),b&&(a=a.replace(/[^a-z0-9_-]/g,"_")),a.replace(/_+/g,"_")},c.prototype._addEventListener=function(b,c,d,e){var f=function(c){if(!c||!c.target)c=a.event,c.target=c.srcElement;return d.call(b,c)};return b.addEventListener?(b.addEventListener(c,f,!!e),!0):b.attachEvent?b.attachEvent("on"+c,f):(c="on"+c,typeof b[c]=="function"&&(f=function(a,b){return function(){a.apply(this,arguments),b.apply(this,arguments)}}(b[c],f)),b[c]=f,!0)},c.prototype._liveEvent=function(a,b,c){var d=this;a=a.toUpperCase(),a=a.split(","),d._addEventListener(e,b,function(b){for(var e=b.srcElement;e.nodeName!=="HTML";e=e.parentNode)if(d.inArray(a,e.nodeName)||e.parentNode===null)break;e&&d.inArray(a,e.nodeName)&&c.call(e,b)},!0)},c.prototype._DOMReady=function(b){var c=this,d=function(){if(arguments.callee.done)return;arguments.callee.done=!0,b.apply(c,arguments)};if(/^(interactive|complete)/.test(e.readyState))return d();this._addEventListener(e,"DOMContentLoaded",d,!1),this._addEventListener(a,"load",d,!1)},a._gaq=a._gaq||[];var d=a._gas||[];if(d._accounts_length>=0)return;var e=a.document,f=Object.prototype.toString,g=Object.prototype.hasOwnProperty,h=Array.prototype.push,i=Array.prototype.slice,j=String.prototype.trim,k=String.prototype.indexOf,l=Array.prototype.indexOf,m=e.location.href,n=e.documentElement;o.prototype._addHook=function(a,b){return typeof a=="string"&&typeof b=="function"&&(typeof _gas._hooks[a]=="undefined"&&(_gas._hooks[a]=[]),_gas._hooks[a].push(b)),!1},o.prototype._execute=function(){var a=i.call(arguments),c=this,d=a.shift(),e=!0,f,h,j,l,m,n=0;if(typeof d=="function")return q(function(a,b){return function(){a.call(b)}}(d,c.gh));if(typeof d=="object"&&d.length>0){h=d.shift(),k.call(h,".")>=0?(l=h.split(".")[0],h=h.split(".")[1]):l=b,j=c._hooks[h];if(j&&j.length>0)for(f=0;f<j.length;f++)try{m=j[f].apply(c.gh,d),m===!1?e=!1:m&&m.length>0&&(d=m)}catch(o){h!=="_trackException"&&c.push(["_trackException",o])}if(e===!1)return 1;if(h==="_setAccount"){for(f in c._accounts)if(c._accounts[f]==d[0]&&l===b)return 1;return l=l||"_gas"+String(c._accounts_length+1),typeof c._accounts["_gas1"]=="undefined"&&k.call(l,"_gas")!=-1&&(l="_gas1"),c._accounts[l]=d[0],c._accounts_length+=1,l=p(l),n=q([l+h,d[0]]),c.gh._setDummyTracker(),n}if(h==="_link"||h==="_linkByPost")return a=i.call(d),a.unshift(h),q(a);var r;if(l&&c._accounts[l])return r=p(l)+h,a=i.call(d),a.unshift(r),q(a);for(f in c._accounts)g.call(c._accounts,f)&&(r=p(f)+h,a=i.call(d),a.unshift(r),n+=q(a));return n?1:0}},o.prototype.push=function(){var b=this,c=i.call(arguments);for(var d=0;d<c.length;d++)(function(b,c){a._gaq.push(function(){c._execute.call(c,b)})})(c[d],b)},a._gas=_gas=new o,_gas.push(["_addHook","_trackException",function(a,b){return _gas.push(["_trackEvent","Exception "+(a.name||"Error"),b||a.message||a,m]),!1}]),_gas.push(["_addHook","_setDebug",function(a){_gas.debug_mode=!!a}]),_gas.push(["_addHook","_popHook",function(a){var b=_gas._hooks[a];return b&&b.pop&&b.pop(),!1}]),_gas.push(["_addHook","_setDefaultTracker",function(a){_gas._default_tracker=a}]),_gas.push(["_addHook","_trackPageview",function(){var a=i.call(arguments);return a.length>=2&&typeof a[0]=="string"&&typeof a[1]=="string"?[{page:a[0],title:a[1]}]:a}]),_gas.push(["_addHook","_trackDownloads",function(a){if(!this._downloadTracked){this._downloadTracked=!0,a?typeof a=="string"?a={extensions:a.split(",")}:a.length>=1&&(a={extensions:a}):a={extensions:[]},a.category=a.category||"Download";var b="xls,xlsx,doc,docx,ppt,pptx,pdf,txt,zip";return b+=",rar,7z,exe,wma,mov,avi,wmv,mp3,csv,tsv",b=b.split(","),a.extensions=a.extensions.concat(b),s.call(this,a),!1}return}]),_gas.push(["_addHook","_trackEvent",function(){var a=i.call(arguments);return a[3]&&(a[3]=(a[3]<0?0:Math.round(a[3]))||0),a}]),_gas.push(["_addHook","_trackForms",function(a){if(!!this._formTracked)return;this._formTracked=!0;var b=this;typeof a!="object"&&(a={}),a.category=a.category||"Form Tracking";var c=function(b){var c=b.target,d=c.name||c.id||c.type||c.nodeName,e=t(c),f="form ("+e+")",g=d+" ("+b.type+")";_gas.push(["_trackEvent",a.category,f,g])};b._DOMReady(function(){var a=["input","select","textarea","hidden"],d=["form"],f=[],g,h;for(g=0;g<a.length;g++){f=e.getElementsByTagName(a[g]);for(h=0;h<f.length;h++)b._addEventListener(f[h],"change",c)}for(g=0;g<d.length;g++){f=e.getElementsByTagName(d[g]);for(h=0;h<f.length;h++)b._addEventListener(f[h],"submit",c)}})}]),_gas.push(["_addHook","_trackVideo",w]),_gas.push(["_addHook","_trackAudio",x]),_gas.push(["_addHook","_trackMailto",function(a){if(!this._mailtoTracked)return this._mailtoTracked=!0,a||(a={}),a.category=a.category||"Mailto",this._liveEvent("a","mousedown",function(b){var c=b.target;c&&c.href&&c.href.toLowerCase().indexOf("mailto:")===0&&_gas.push(["_trackEvent",a.category,c.href.substr(7)])}),!1;return}]);var C=null,D=0,G;_gas.push(["_addHook","_trackMaxScroll",H]),_gas._allowAnchor=!1,_gas.push(["_addHook","_setAllowAnchor",function(a){_gas._allowAnchor=!!a}]),_gas.push(["_addHook","_link",function(a,c){return c===b&&(c=_gas._allowAnchor),[a,c]}]),_gas.push(["_addHook","_linkByPost",function(a,c){return c===b&&(c=_gas._allowAnchor),[a,c]}]);var I=[],J=b;_gas.push(["_addHook","_setDomainName",function(a){if(k.call("."+e.location.hostname,a)<0)return I.push(a),!1;J=a}]),_gas.push(["_addHook","_addExternalDomainName",function(a){return I.push(a),!1}]),_gas.push(["_addHook","_setMultiDomain",K]),_gas.push(["_addHook","_trackOutboundLinks",L]);var M=[],N={},O={},R=!1,S;_gas.push(["_addHook","_trackVimeo",function(a){var b=this;if(typeof a=="boolean"||a==="force")a={force:!!a};return a=a||{},a.category=a.category||"Vimeo Video",a.percentages=a.percentages||[],a.force=a.force||!1,S=a,b._DOMReady(function(){U.call(b)}),!1}]);var V=[],W,X={};_gas.push(["_addHook","_trackYoutube",function(a){var b=i.call(arguments);!b[0]||typeof b[0]!="boolean"&&b[0]!=="force"?a={}:a={force:!!b[0]},b[1]&&b[1].length&&(a.percentages=b[1]),a=a||{},a.force=a.force||!1,a.category=a.category||"YouTube Video",a.percentages=a.percentages||[],W=a;var c=this;return c._DOMReady(function(){bc.call(c,a)}),!1}]);while(_gas._queue.length>0)_gas.push(_gas._queue.shift());_gaq&&_gaq.length>=0&&function(){var a=e.createElement("script");a.type="text/javascript",a.async=!0,a.src=("https:"==e.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";var b=e.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)}()})(window);
View
21 src/plugins/form_tracking.js
@@ -52,9 +52,24 @@ _gas.push(['_addHook', '_trackForms', function(opts) {
_gas.push(['_trackEvent', opts['category'], action, label]);
}
- scp._liveEvent('input,select,textarea,hidden', 'change', trackField);
- //scp._liveEvent('button,submit,image,reset', 'click', trackField);
- scp._liveEvent('form', 'submit', trackField);
+ scp._DOMReady(function() {
+ var changeTags = ['input', 'select', 'textarea', 'hidden'];
+ var submitTags = ['form'];
+ var elements = [];
+ var i, j;
+ for (i = 0; i < changeTags.length; i++) {
+ elements = document.getElementsByTagName(changeTags[i]);
+ for (j = 0; j < elements.length; j++) {
+ scp._addEventListener(elements[j], 'change', trackField);
+ }
+ }
+ for (i = 0; i < submitTags.length; i++) {
+ elements = document.getElementsByTagName(submitTags[i]);
+ for (j = 0; j < elements.length; j++) {
+ scp._addEventListener(elements[j], 'submit', trackField);
+ }
+ }
+ });
}]);

0 comments on commit dc9e0ba

Please sign in to comment.
Something went wrong with that request. Please try again.