Skip to content
Browse files

Fix multidomain bug caused by _getTrackers modified behaviour. Now I …

…check if there is any tracker created, and retry to create trackers on _setaccounts
  • Loading branch information...
1 parent e123f81 commit c2fff8ed3d12fc011c24bf824e3832815a7294ee @eduardocereto eduardocereto committed Jan 20, 2012
Showing with 73 additions and 39 deletions.
  1. +15 −4 dist/gas.core.js
  2. +5 −5 dist/gas.core.min.js
  3. +15 −4 dist/gas.js
  4. +21 −21 dist/gas.min.js
  5. +5 −3 src/core.js
  6. +10 −1 src/helpers.js
  7. +1 −1 test/gas.html
  8. +1 −0 test/index.html
View
19 dist/gas.core.js
@@ -29,7 +29,16 @@
* @constructor
*/
var GasHelper = function() {
- this['tracker'] = window['_gat']['_getTrackers']()[0];
+ this._setDummyTracker();
+};
+
+GasHelper.prototype._setDummyTracker = function() {
+ if (!this['tracker']) {
+ var trackers = window['_gat']['_getTrackers']();
+ if (trackers.length > 0) {
+ this['tracker'] = trackers[0];
+ }
+ }
};
/**
@@ -262,7 +271,7 @@ GAS.prototype._execute = function() {
self = this,
sub = args.shift(),
gaq_execute = true,
- i, foo, hooks, acct_name, repl_sub;
+ i, foo, hooks, acct_name, repl_sub, return_val = 0;
if (typeof sub === 'function') {
// Pushed functions are executed right away
@@ -332,7 +341,10 @@ GAS.prototype._execute = function() {
self._accounts[acct_name] = sub[0];
self._accounts_length += 1;
acct_name = _build_acct_name(acct_name);
- return _gaq_push([acct_name + foo, sub[0]]);
+ return_val = _gaq_push([acct_name + foo, sub[0]]);
+ // Must try t get the tracker if it's a _setAccount
+ self.gh._setDummyTracker();
+ return return_val;
}
// Intercept _linka and _linkByPost
@@ -352,7 +364,6 @@ GAS.prototype._execute = function() {
}
// Call Original _gaq, for all accounts
- var return_val = 0;
for (i in self._accounts) {
if (hasOwn.call(self._accounts, i)) {
acc_foo = _build_acct_name(i) + foo;
View
10 dist/gas.core.min.js
@@ -9,8 +9,8 @@
$Date$
Licensed under the MIT license.
*/
-(function(c,l){function o(){this.tracker=c._gat._getTrackers()[0]}function h(){var a=this;a.a={};a.d=0;a.f=m;a.c="_gas1";a.e={};a.b={_addHook:[a.g]};a.push(function(){a.e=new o})}function i(a){if(_gas.i)try{console.log(a)}catch(b){}return c._gaq.push(a)}c._gaq=c._gaq||[];var m=c._gas||[];if(!(m.d>=0)){var k=c.document,p=Object.prototype.hasOwnProperty,j=Array.prototype.slice,n=String.prototype.indexOf,q=k.location.href;h.prototype.g=function(a,b){typeof a==="string"&&typeof b==="function"&&(typeof _gas.b[a]===
-"undefined"&&(_gas.b[a]=[]),_gas.b[a].push(b));return!1};h.prototype.h=function(){var a=j.call(arguments),b=a.shift(),a=!0,f,e,c,d,g;if(typeof b==="function")return i(function(a,b){return function(){a.call(b)}}(b,this.e));else if(typeof b==="object"&&b.length>0){e=b.shift();n.call(e,".")>=0?(d=e.split(".")[0],e=e.split(".")[1]):d=l;if((c=this.b[e])&&c.length>0)for(f=0;f<c.length;f++)try{g=c[f].apply(this.e,b),g===!1?a=!1:g&&g.length>0&&(b=g)}catch(h){e!=="_trackException"&&this.push(["_trackException",
-h])}if(a===!1)return 1;if(e==="_setAccount"){for(f in this.a)if(this.a[f]==b[0]&&d===l)return 1;d=d||"_gas"+String(this.d+1);typeof this.a._gas1=="undefined"&&n.call(d,"_gas")!=-1&&(d="_gas1");this.a[d]=b[0];this.d+=1;d=d===_gas.c?"":d+".";return i([d+e,b[0]])}if(e==="_link"||e==="_linkByPost")return a=j.call(b),a.unshift(e),i(a);if(d&&this.a[d])return g=(d===_gas.c?"":d+".")+e,a=j.call(b),a.unshift(g),i(a);c=0;for(f in this.a)p.call(this.a,f)&&(g=(f===_gas.c?"":f+".")+e,a=j.call(b),a.unshift(g),
-c+=i(a));return c?1:0}};h.prototype.push=function(){for(var a=j.call(arguments),b=0;b<a.length;b++)(function(a,b){c._gaq.push(function(){b.h.call(b,a)})})(a[b],this)};c._gas=_gas=new h;_gas.push(["_addHook","_trackException",function(a,b){_gas.push(["_trackEvent","Exception "+(a.name||"Error"),b||a.message||a,q]);return!1}]);_gas.push(["_addHook","_setDebug",function(a){_gas.i=!!a}]);_gas.push(["_addHook","_popHook",function(a){(a=_gas.b[a])&&a.pop&&a.pop();return!1}]);for(_gas.push(["_addHook","_setDefaultTracker",
-function(a){_gas.c=a}]);_gas.f.length>0;)_gas.push(_gas.f.shift());_gaq&&_gaq.length>=0&&function(){var a=k.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"==k.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";var b=k.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)}()}})(window);
+(function(e,l){function m(){this.g()}function g(){var a=this;a.a={};a.e=0;a.f=n;a.c="_gas1";a.d={};a.b={_addHook:[a.h]};a.push(function(){a.d=new m})}function j(a){if(_gas.j)try{console.log(a)}catch(b){}return e._gaq.push(a)}m.prototype.g=function(){if(!this.tracker){var a=e._gat._getTrackers();a.length>0&&(this.tracker=a[0])}};e._gaq=e._gaq||[];var n=e._gas||[];if(!(n.e>=0)){var i=e.document,p=Object.prototype.hasOwnProperty,k=Array.prototype.slice,o=String.prototype.indexOf,q=i.location.href;g.prototype.h=
+function(a,b){typeof a==="string"&&typeof b==="function"&&(typeof _gas.b[a]==="undefined"&&(_gas.b[a]=[]),_gas.b[a].push(b));return!1};g.prototype.i=function(){var a=k.call(arguments),b=a.shift(),a=!0,f,d,e,c,h,g=0;if(typeof b==="function")return j(function(a,b){return function(){a.call(b)}}(b,this.d));else if(typeof b==="object"&&b.length>0){d=b.shift();o.call(d,".")>=0?(c=d.split(".")[0],d=d.split(".")[1]):c=l;if((e=this.b[d])&&e.length>0)for(f=0;f<e.length;f++)try{h=e[f].apply(this.d,b),h===!1?
+a=!1:h&&h.length>0&&(b=h)}catch(i){d!=="_trackException"&&this.push(["_trackException",i])}if(a===!1)return 1;if(d==="_setAccount"){for(f in this.a)if(this.a[f]==b[0]&&c===l)return 1;c=c||"_gas"+String(this.e+1);typeof this.a._gas1=="undefined"&&o.call(c,"_gas")!=-1&&(c="_gas1");this.a[c]=b[0];this.e+=1;c=c===_gas.c?"":c+".";g=j([c+d,b[0]]);this.d.g();return g}if(d==="_link"||d==="_linkByPost")return a=k.call(b),a.unshift(d),j(a);if(c&&this.a[c])return h=(c===_gas.c?"":c+".")+d,a=k.call(b),a.unshift(h),
+j(a);for(f in this.a)p.call(this.a,f)&&(h=(f===_gas.c?"":f+".")+d,a=k.call(b),a.unshift(h),g+=j(a));return g?1:0}};g.prototype.push=function(){for(var a=k.call(arguments),b=0;b<a.length;b++)(function(a,b){e._gaq.push(function(){b.i.call(b,a)})})(a[b],this)};e._gas=_gas=new g;_gas.push(["_addHook","_trackException",function(a,b){_gas.push(["_trackEvent","Exception "+(a.name||"Error"),b||a.message||a,q]);return!1}]);_gas.push(["_addHook","_setDebug",function(a){_gas.j=!!a}]);_gas.push(["_addHook","_popHook",
+function(a){(a=_gas.b[a])&&a.pop&&a.pop();return!1}]);for(_gas.push(["_addHook","_setDefaultTracker",function(a){_gas.c=a}]);_gas.f.length>0;)_gas.push(_gas.f.shift());_gaq&&_gaq.length>=0&&function(){var a=i.createElement("script");a.type="text/javascript";a.async=!0;a.src=("https:"==i.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";var b=i.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)}()}})(window);
View
19 dist/gas.js
@@ -29,7 +29,16 @@
* @constructor
*/
var GasHelper = function() {
- this['tracker'] = window['_gat']['_getTrackers']()[0];
+ this._setDummyTracker();
+};
+
+GasHelper.prototype._setDummyTracker = function() {
+ if (!this['tracker']) {
+ var trackers = window['_gat']['_getTrackers']();
+ if (trackers.length > 0) {
+ this['tracker'] = trackers[0];
+ }
+ }
};
/**
@@ -262,7 +271,7 @@ GAS.prototype._execute = function() {
self = this,
sub = args.shift(),
gaq_execute = true,
- i, foo, hooks, acct_name, repl_sub;
+ i, foo, hooks, acct_name, repl_sub, return_val = 0;
if (typeof sub === 'function') {
// Pushed functions are executed right away
@@ -332,7 +341,10 @@ GAS.prototype._execute = function() {
self._accounts[acct_name] = sub[0];
self._accounts_length += 1;
acct_name = _build_acct_name(acct_name);
- return _gaq_push([acct_name + foo, sub[0]]);
+ return_val = _gaq_push([acct_name + foo, sub[0]]);
+ // Must try t get the tracker if it's a _setAccount
+ self.gh._setDummyTracker();
+ return return_val;
}
// Intercept _linka and _linkByPost
@@ -352,7 +364,6 @@ GAS.prototype._execute = function() {
}
// Call Original _gaq, for all accounts
- var return_val = 0;
for (i in self._accounts) {
if (hasOwn.call(self._accounts, i)) {
acc_foo = _build_acct_name(i) + foo;
View
42 dist/gas.min.js
@@ -9,25 +9,25 @@
$Date$
Licensed under the MIT license.
*/
-(function(h,n){function p(){this.tracker=h._gat._getTrackers()[0]}function r(){var a=this;a.b={};a.h=0;a.l=z;a.f="_gas1";a.i={};a.d={_addHook:[a.m]};a.push(function(){a.i=new p})}function q(a){if(_gas.o)try{console.log(a)}catch(b){}return h._gaq.push(a)}function I(a,b){if(typeof a!=="string")return!1;var c=a.split("?")[0],c=c.split(".");return(c=c[c.length-1])&&this.g(b,c)?c:!1}function J(a){for(var b=this,c=g.getElementsByTagName("a"),d=0;d<c.length;d++)this.a(c[d],"mousedown",function(c){if(c.target&&
-c.target.tagName==="A"){var d=I.call(b,c.target.href,a);d&&_gas.push(["_trackEvent","Download",d,c.target.href])}})}function K(a,b){function c(b){var c=b.target,c=c.name||c.id||c.type||c.nodeName,b=b.type,d=a.name||a.id||n;_gas.push(["_trackEvent","Form Tracking","form"+(d?" ("+d+")":""),c+" ("+b+")"])}var d=this;if(b)d.a(h,"click",function(a){try{var b=a.target;a.type=="click"&&d.g(["button","submit","image","reset"],b.type.toLowerCase())&&c(a)}catch(e){}}),d.a(g.body,"change",function(a){try{var b=
-a.target;a.type=="change"&&d.g(["input","select","textarea","hidden"],b.nodeName.toLowerCase())&&c(a)}catch(e){}});else{var e,f;if(!a.elements||!a.elements.length)return!1;for(e=0;e<a.elements.length;e++)f=a.elements[e],d.g(["button","submit","image","reset"],f.type)?d.a(f,"click",c):d.a(f,"change",c);d.a(a,"submit",c)}}function v(a){_gas.push(["_trackEvent",this.tagName,a.type,this.currentSrc])}function A(a){var b=this;b.e(function(){for(var c=g.getElementsByTagName(a),d=0;d<c.length;d++)b.a(c[d],
-"play",v),b.a(c[d],"ended",v),b.a(c[d],"pause",v)})}function B(){return Math.max(g.body.scrollHeight||0,o.scrollHeight||0,g.body.offsetHeight||0,o.offsetHeight||0,g.body.clientHeight||0,o.clientHeight||0)}function C(a){w&&clearTimeout(w);a===!0?k=Math.max(((h.pageYOffset||g.body.scrollTop||o.scrollTop||0)+(h.innerHeight||o.clientHeight||g.body.clientHeight||0))/B()*100,k):w=setTimeout(function(){k=Math.max(((h.pageYOffset||g.body.scrollTop||o.scrollTop||0)+(h.innerHeight||o.clientHeight||g.body.clientHeight||
-0))/B()*100,k)},400)}function L(){C(!0);k=Math.floor(k);if(!(k<=0||k>100)){var a=(k>10?1:0)*(Math.floor((k-1)/10)*10+1),a=String(a)+"-"+String(Math.ceil(k/10)*10);_gas.push(["_trackEvent","Max Scroll",D,a,Math.floor(k),!0])}}function s(a,b,c){if(c.contentWindow&&c.contentWindow.postMessage){var d=c.getAttribute("src").split("?")[0],a=JSON.stringify({method:a,value:b});c.contentWindow.postMessage(a,d)}}function E(a){for(var b=g.getElementsByTagName("iframe"),c=0,d,e,f,j=0;j<b.length;j++)if(i.call(b[j].src,
-"//player.vimeo.com")>-1){d="gas_vimeo_"+j;e=b[j].src;f="?";i.call(e,"?")>-1&&(f="&");if(i.call(e,"api=1")<0)if(a)e+=f+"api=1&player_id="+d;else break;else i.call(e,"player_id=")<-1&&(e+=f+"player_id="+d);c++;b[j].id=d;if(b[j].src!==e){b[j].src=e;break}s("getVideoUrl","",b[j]);s("addEventListener","play",b[j]);s("addEventListener","pause",b[j]);s("addEventListener","finish",b[j])}c>0&&F===!1&&(this.a(h,"message",function(a){if(i.call(a.origin,"//player.vimeo.com")>-1)if(a=JSON.parse(a.data),a.event===
-"ready")E();else if(a.method){if(a.method=="getVideoUrl")G[a.q]=a.value}else _gas.push(["_trackEvent","Vimeo Video",a.event,G[a.q]])},!1),F=!0)}function x(a,b){if(l[b]==n||l[b].j.length<=0)return!1;if(a.getCurrentTime()/a.getDuration()*100>=l[b].j[0]){var c=l[b].j.shift();_gas.push(["_trackEvent","YouTube Video",c+"%",a.getVideoUrl()])}l[b].k=setTimeout(x,1E3,a,b)}function y(a){var b=a.getVideoData().video_id;l[b]&&l[b].k&&(x(a,b),clearTimeout(l[b].k))}function M(a){var b="";switch(a.data){case 0:b=
-"finish";y(a.target);break;case 1:var b="play",c=a.target;if(t&&t.length){var d=c.getVideoData().video_id;l[d]?y(c):(l[d]={},l[d].j=m.call(t));l[d].k=setTimeout(x,1E3,c,d)}break;case 2:b="pause",y(a.target)}b&&_gas.push(["_trackEvent","YouTube Video",b,a.target.getVideoUrl()])}function N(a){_gas.push(["_trackEvent","YouTube Video","error ("+a.data+")",a.target.getVideoUrl()])}function O(){for(var a=g.getElementsByTagName("object"),b,c,d=/(https?:\/\/www\.youtube(-nocookie)?\.com[^/]*).*\/v\/([^&?]+)/,
-e=0;e<a.length;e++){b=a[e].getElementsByTagName("param");for(c=0;c<b.length;c++)if(b[c].name=="movie"&&b[c].value){if((c=b[c].value.match(d))&&c[1]&&c[3])b=g.createElement("iframe"),b.src=c[1]+"/embed/"+c[3]+"?enablejsapi=1",b.width=a[e].width,b.height=a[e].height,b.setAttribute("frameBorder","0"),b.setAttribute("allowfullscreen",""),a[e].parentNode.insertBefore(b,a[e]),a[e].parentNode.removeChild(a[e]),e--;break}}}function P(a,b){if(a)try{O()}catch(c){_gas.push(["_trackException",c,"GAS Error on youtube.js:_ytMigrateObjectEmbed"])}for(var d=
-[],e=g.getElementsByTagName("iframe"),f=0;f<e.length;f++)if(i.call(e[f].src,"//www.youtube.com/embed")>-1){if(i.call(e[f].src,"enablejsapi=1")<0)if(a)e[f].src+=i.call(e[f].src,"?")<0?"?enablejsapi=1":"&enablejsapi=1";else continue;d.push(e[f])}if(d.length>0)b&&b.length&&(t=b),h.onYouTubePlayerAPIReady=function(){for(var a,b=0;b<d.length;b++)a=new h.YT.Player(d[b]),a.addEventListener("onStateChange",M),a.addEventListener("onError",N)},e=g.createElement("script"),f="http:",g.location.protocol==="https:"&&
-(f="https:"),e.src=f+"//www.youtube.com/player_api",e.type="text/javascript",e.async=!0,f=g.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)}p.prototype.g=function(a,b){if(a&&a.length)for(var c=0;c<a.length;c++)if(a[c]===b)return!0;return!1};p.prototype.isArray=function(a){return Q.call(a)==="[object Array]"};p.prototype.a=function(a,b,c,d){function e(b){if(!b||!b.target)b=h.event,b.target=b.srcElement;return c.call(a,b)}a.addEventListener?a.addEventListener(b,e,!!d):a.attachEvent?
-a.attachEvent("on"+b,e):(b="on"+b,typeof a[b]==="function"&&(e=function(a,b){return function(){a.apply(this,arguments);b.apply(this,arguments)}}(a[b],e)),a[b]=e)};p.prototype.e=function(a){function b(){if(!arguments.callee.p)arguments.callee.p=!0,a.apply(c,arguments)}var c=this;/^(interactive|complete)/.test(g.readyState)?b():(this.a(g,"DOMContentLoaded",b,!1),this.a(h,"load",b,!1))};h._gaq=h._gaq||[];var z=h._gas||[];if(!(z.h>=0)){var g=h.document,Q=Object.prototype.toString,R=Object.prototype.hasOwnProperty,
-m=Array.prototype.slice,i=String.prototype.indexOf,D=g.location.href,o=g.documentElement;r.prototype.m=function(a,b){typeof a==="string"&&typeof b==="function"&&(typeof _gas.d[a]==="undefined"&&(_gas.d[a]=[]),_gas.d[a].push(b));return!1};r.prototype.n=function(){var a=m.call(arguments),b=a.shift(),a=!0,c,d,e,f,g;if(typeof b==="function")return q(function(a,b){return function(){a.call(b)}}(b,this.i));else if(typeof b==="object"&&b.length>0){d=b.shift();i.call(d,".")>=0?(f=d.split(".")[0],d=d.split(".")[1]):
-f=n;if((e=this.d[d])&&e.length>0)for(c=0;c<e.length;c++)try{g=e[c].apply(this.i,b),g===!1?a=!1:g&&g.length>0&&(b=g)}catch(h){d!=="_trackException"&&this.push(["_trackException",h])}if(a===!1)return 1;if(d==="_setAccount"){for(c in this.b)if(this.b[c]==b[0]&&f===n)return 1;f=f||"_gas"+String(this.h+1);typeof this.b._gas1=="undefined"&&i.call(f,"_gas")!=-1&&(f="_gas1");this.b[f]=b[0];this.h+=1;f=f===_gas.f?"":f+".";return q([f+d,b[0]])}if(d==="_link"||d==="_linkByPost")return a=m.call(b),a.unshift(d),
-q(a);if(f&&this.b[f])return g=(f===_gas.f?"":f+".")+d,a=m.call(b),a.unshift(g),q(a);e=0;for(c in this.b)R.call(this.b,c)&&(g=(c===_gas.f?"":c+".")+d,a=m.call(b),a.unshift(g),e+=q(a));return e?1:0}};r.prototype.push=function(){for(var a=m.call(arguments),b=0;b<a.length;b++)(function(a,b){h._gaq.push(function(){b.n.call(b,a)})})(a[b],this)};h._gas=_gas=new r;_gas.push(["_addHook","_trackException",function(a,b){_gas.push(["_trackEvent","Exception "+(a.name||"Error"),b||a.message||a,D]);return!1}]);
-_gas.push(["_addHook","_setDebug",function(a){_gas.o=!!a}]);_gas.push(["_addHook","_popHook",function(a){(a=_gas.d[a])&&a.pop&&a.pop();return!1}]);_gas.push(["_addHook","_setDefaultTracker",function(a){_gas.f=a}]);_gas.push(["_addHook","_trackPageview",function(a,b){if(b&&typeof b==="string"){var c=g.title;h.r.push(function(){g.title=b},["_trackPageview",a],function(){g.title=c});return!1}return[a]}]);_gas.push(["_addHook","_trackDownloads",function(a){var b="xls,xlsx,doc,docx,ppt,pptx,pdf,txt,zip";
-b+=",rar,7z,exe,wma,mov,avi,wmv,mp3,csv,tsv";b=b.split(",");typeof a==="string"?b=b.concat(a.split(",")):this.isArray(a)&&(b=b.concat(a));J.call(this,b);return!1}]);_gas.push(["_addHook","_trackEvent",function(){var a=m.call(arguments);a[3]&&(a[3]=(a[3]<0?0:Math.round(a[3]))||0);return a}]);_gas.push(["_addHook","_trackForms",function(a){var b=this;this.e(function(){for(var c=g.getElementsByTagName("form"),d=0;d<c.length;d++){try{K.call(b,c[d],a)}catch(e){}if(a)break}return!1})}]);_gas.push(["_addHook",
-"_trackVideo",function(){A.call(this,"video")}]);_gas.push(["_addHook","_trackAudio",function(){A.call(this,"audio")}]);var w=null,k=0;_gas.push(["_addHook","_trackMaxScroll",function(){this.a(h,"scroll",C);this.a(h,"beforeunload",L)}]);_gas.c=!1;_gas.push(["_addHook","_setAllowAnchor",function(a){_gas.c=!!a}]);_gas.push(["_addHook","_link",function(a,b){if(b===n)b=_gas.c;return[a,b]}]);_gas.push(["_addHook","_linkByPost",function(a,b){if(b===n)b=_gas.c;return[a,b]}]);var u=[],H=n;_gas.push(["_addHook",
-"_setDomainName",function(a){if(i.call("."+g.location.hostname,a)<0)return u.push(a),!1;H=a}]);_gas.push(["_addHook","_addExternalDomainName",function(a){u.push(a);return!1}]);_gas.push(["_addHook","_setMultiDomain",function(a){var b=g.location.hostname,c=this,d,e,f,h=g.getElementsByTagName("a");a!=="now"&&a!=="mousedown"&&(a="click");for(d=0;d<h.length;d++)if(f=h[d],i.call(f.href,"http")===0&&!(f.hostname==b||i.call(f.hostname,H)>=0))for(e=0;e<u.length;e++)if(i.call(f.hostname,u[e])>=0)a==="now"?
-f.href=c.tracker._getLinkerUrl(f.href,_gas.c):a==="click"?this.a(f,a,function(a){_gas.push(["_link",this.href,_gas.c]);a.preventDefault?a.preventDefault():a.returnValue=!1}):this.a(f,a,function(){this.href=c.tracker._getLinkerUrl(this.href,_gas.c)});return!1}]);_gas.push(["_addHook","_trackOutboundLinks",function(){for(var a=g.getElementsByTagName("a"),b=0;b<a.length;b++)this.a(a[b],"mousedown",function(a){a=a.target;if((a.protocol=="http:"||a.protocol=="https:")&&i.call(a.href,g.location.hostname)===
--1){var b=a.pathname+a.search+"",e=i.call(b,"__utm");e!==-1&&(b=b.substring(0,e));_gas.push(["_trackEvent","Outbound",a.hostname,b])}})}]);var G={},F=!1;_gas.push(["_addHook","_trackVimeo",function(a){var b=this;b.e(function(){E.call(b,a)});return!1}]);var t=[],l={};for(_gas.push(["_addHook","_trackYoutube",function(){var a=m.call(arguments),b=this;b.e(function(){P.apply(b,a)});return!1}]);_gas.l.length>0;)_gas.push(_gas.l.shift());_gaq&&_gaq.length>=0&&function(){var a=g.createElement("script");
+(function(h,n){function p(){this.m()}function r(){var a=this;a.b={};a.i=0;a.l=z;a.f="_gas1";a.g={};a.d={_addHook:[a.n]};a.push(function(){a.g=new p})}function q(a){if(_gas.p)try{console.log(a)}catch(b){}return h._gaq.push(a)}function I(a,b){if(typeof a!=="string")return!1;var c=a.split("?")[0],c=c.split(".");return(c=c[c.length-1])&&this.h(b,c)?c:!1}function J(a){for(var b=this,c=g.getElementsByTagName("a"),d=0;d<c.length;d++)this.a(c[d],"mousedown",function(c){if(c.target&&c.target.tagName==="A"){var d=
+I.call(b,c.target.href,a);d&&_gas.push(["_trackEvent","Download",d,c.target.href])}})}function K(a,b){function c(b){var c=b.target,c=c.name||c.id||c.type||c.nodeName,b=b.type,d=a.name||a.id||n;_gas.push(["_trackEvent","Form Tracking","form"+(d?" ("+d+")":""),c+" ("+b+")"])}var d=this;if(b)d.a(h,"click",function(a){try{var b=a.target;a.type=="click"&&d.h(["button","submit","image","reset"],b.type.toLowerCase())&&c(a)}catch(f){}}),d.a(g.body,"change",function(a){try{var b=a.target;a.type=="change"&&
+d.h(["input","select","textarea","hidden"],b.nodeName.toLowerCase())&&c(a)}catch(f){}});else{var e,f;if(!a.elements||!a.elements.length)return!1;for(e=0;e<a.elements.length;e++)f=a.elements[e],d.h(["button","submit","image","reset"],f.type)?d.a(f,"click",c):d.a(f,"change",c);d.a(a,"submit",c)}}function v(a){_gas.push(["_trackEvent",this.tagName,a.type,this.currentSrc])}function A(a){var b=this;b.e(function(){for(var c=g.getElementsByTagName(a),d=0;d<c.length;d++)b.a(c[d],"play",v),b.a(c[d],"ended",
+v),b.a(c[d],"pause",v)})}function B(){return Math.max(g.body.scrollHeight||0,o.scrollHeight||0,g.body.offsetHeight||0,o.offsetHeight||0,g.body.clientHeight||0,o.clientHeight||0)}function C(a){w&&clearTimeout(w);a===!0?j=Math.max(((h.pageYOffset||g.body.scrollTop||o.scrollTop||0)+(h.innerHeight||o.clientHeight||g.body.clientHeight||0))/B()*100,j):w=setTimeout(function(){j=Math.max(((h.pageYOffset||g.body.scrollTop||o.scrollTop||0)+(h.innerHeight||o.clientHeight||g.body.clientHeight||0))/B()*100,j)},
+400)}function L(){C(!0);j=Math.floor(j);if(!(j<=0||j>100)){var a=(j>10?1:0)*(Math.floor((j-1)/10)*10+1),a=String(a)+"-"+String(Math.ceil(j/10)*10);_gas.push(["_trackEvent","Max Scroll",D,a,Math.floor(j),!0])}}function s(a,b,c){if(c.contentWindow&&c.contentWindow.postMessage){var d=c.getAttribute("src").split("?")[0],a=JSON.stringify({method:a,value:b});c.contentWindow.postMessage(a,d)}}function E(a){for(var b=g.getElementsByTagName("iframe"),c=0,d,e,f,k=0;k<b.length;k++)if(i.call(b[k].src,"//player.vimeo.com")>
+-1){d="gas_vimeo_"+k;e=b[k].src;f="?";i.call(e,"?")>-1&&(f="&");if(i.call(e,"api=1")<0)if(a)e+=f+"api=1&player_id="+d;else break;else i.call(e,"player_id=")<-1&&(e+=f+"player_id="+d);c++;b[k].id=d;if(b[k].src!==e){b[k].src=e;break}s("getVideoUrl","",b[k]);s("addEventListener","play",b[k]);s("addEventListener","pause",b[k]);s("addEventListener","finish",b[k])}c>0&&F===!1&&(this.a(h,"message",function(a){if(i.call(a.origin,"//player.vimeo.com")>-1)if(a=JSON.parse(a.data),a.event==="ready")E();else if(a.method){if(a.method==
+"getVideoUrl")G[a.r]=a.value}else _gas.push(["_trackEvent","Vimeo Video",a.event,G[a.r]])},!1),F=!0)}function x(a,b){if(l[b]==n||l[b].j.length<=0)return!1;if(a.getCurrentTime()/a.getDuration()*100>=l[b].j[0]){var c=l[b].j.shift();_gas.push(["_trackEvent","YouTube Video",c+"%",a.getVideoUrl()])}l[b].k=setTimeout(x,1E3,a,b)}function y(a){var b=a.getVideoData().video_id;l[b]&&l[b].k&&(x(a,b),clearTimeout(l[b].k))}function M(a){var b="";switch(a.data){case 0:b="finish";y(a.target);break;case 1:var b=
+"play",c=a.target;if(t&&t.length){var d=c.getVideoData().video_id;l[d]?y(c):(l[d]={},l[d].j=m.call(t));l[d].k=setTimeout(x,1E3,c,d)}break;case 2:b="pause",y(a.target)}b&&_gas.push(["_trackEvent","YouTube Video",b,a.target.getVideoUrl()])}function N(a){_gas.push(["_trackEvent","YouTube Video","error ("+a.data+")",a.target.getVideoUrl()])}function O(){for(var a=g.getElementsByTagName("object"),b,c,d=/(https?:\/\/www\.youtube(-nocookie)?\.com[^/]*).*\/v\/([^&?]+)/,e=0;e<a.length;e++){b=a[e].getElementsByTagName("param");
+for(c=0;c<b.length;c++)if(b[c].name=="movie"&&b[c].value){if((c=b[c].value.match(d))&&c[1]&&c[3])b=g.createElement("iframe"),b.src=c[1]+"/embed/"+c[3]+"?enablejsapi=1",b.width=a[e].width,b.height=a[e].height,b.setAttribute("frameBorder","0"),b.setAttribute("allowfullscreen",""),a[e].parentNode.insertBefore(b,a[e]),a[e].parentNode.removeChild(a[e]),e--;break}}}function P(a,b){if(a)try{O()}catch(c){_gas.push(["_trackException",c,"GAS Error on youtube.js:_ytMigrateObjectEmbed"])}for(var d=[],e=g.getElementsByTagName("iframe"),
+f=0;f<e.length;f++)if(i.call(e[f].src,"//www.youtube.com/embed")>-1){if(i.call(e[f].src,"enablejsapi=1")<0)if(a)e[f].src+=i.call(e[f].src,"?")<0?"?enablejsapi=1":"&enablejsapi=1";else continue;d.push(e[f])}if(d.length>0)b&&b.length&&(t=b),h.onYouTubePlayerAPIReady=function(){for(var a,b=0;b<d.length;b++)a=new h.YT.Player(d[b]),a.addEventListener("onStateChange",M),a.addEventListener("onError",N)},e=g.createElement("script"),f="http:",g.location.protocol==="https:"&&(f="https:"),e.src=f+"//www.youtube.com/player_api",
+e.type="text/javascript",e.async=!0,f=g.getElementsByTagName("script")[0],f.parentNode.insertBefore(e,f)}p.prototype.m=function(){if(!this.tracker){var a=h._gat._getTrackers();a.length>0&&(this.tracker=a[0])}};p.prototype.h=function(a,b){if(a&&a.length)for(var c=0;c<a.length;c++)if(a[c]===b)return!0;return!1};p.prototype.isArray=function(a){return Q.call(a)==="[object Array]"};p.prototype.a=function(a,b,c,d){function e(b){if(!b||!b.target)b=h.event,b.target=b.srcElement;return c.call(a,b)}a.addEventListener?
+a.addEventListener(b,e,!!d):a.attachEvent?a.attachEvent("on"+b,e):(b="on"+b,typeof a[b]==="function"&&(e=function(a,b){return function(){a.apply(this,arguments);b.apply(this,arguments)}}(a[b],e)),a[b]=e)};p.prototype.e=function(a){function b(){if(!arguments.callee.q)arguments.callee.q=!0,a.apply(c,arguments)}var c=this;/^(interactive|complete)/.test(g.readyState)?b():(this.a(g,"DOMContentLoaded",b,!1),this.a(h,"load",b,!1))};h._gaq=h._gaq||[];var z=h._gas||[];if(!(z.i>=0)){var g=h.document,Q=Object.prototype.toString,
+R=Object.prototype.hasOwnProperty,m=Array.prototype.slice,i=String.prototype.indexOf,D=g.location.href,o=g.documentElement;r.prototype.n=function(a,b){typeof a==="string"&&typeof b==="function"&&(typeof _gas.d[a]==="undefined"&&(_gas.d[a]=[]),_gas.d[a].push(b));return!1};r.prototype.o=function(){var a=m.call(arguments),b=a.shift(),a=!0,c,d,e,f,g,h=0;if(typeof b==="function")return q(function(a,b){return function(){a.call(b)}}(b,this.g));else if(typeof b==="object"&&b.length>0){d=b.shift();i.call(d,
+".")>=0?(f=d.split(".")[0],d=d.split(".")[1]):f=n;if((e=this.d[d])&&e.length>0)for(c=0;c<e.length;c++)try{g=e[c].apply(this.g,b),g===!1?a=!1:g&&g.length>0&&(b=g)}catch(j){d!=="_trackException"&&this.push(["_trackException",j])}if(a===!1)return 1;if(d==="_setAccount"){for(c in this.b)if(this.b[c]==b[0]&&f===n)return 1;f=f||"_gas"+String(this.i+1);typeof this.b._gas1=="undefined"&&i.call(f,"_gas")!=-1&&(f="_gas1");this.b[f]=b[0];this.i+=1;f=f===_gas.f?"":f+".";h=q([f+d,b[0]]);this.g.m();return h}if(d===
+"_link"||d==="_linkByPost")return a=m.call(b),a.unshift(d),q(a);if(f&&this.b[f])return g=(f===_gas.f?"":f+".")+d,a=m.call(b),a.unshift(g),q(a);for(c in this.b)R.call(this.b,c)&&(g=(c===_gas.f?"":c+".")+d,a=m.call(b),a.unshift(g),h+=q(a));return h?1:0}};r.prototype.push=function(){for(var a=m.call(arguments),b=0;b<a.length;b++)(function(a,b){h._gaq.push(function(){b.o.call(b,a)})})(a[b],this)};h._gas=_gas=new r;_gas.push(["_addHook","_trackException",function(a,b){_gas.push(["_trackEvent","Exception "+
+(a.name||"Error"),b||a.message||a,D]);return!1}]);_gas.push(["_addHook","_setDebug",function(a){_gas.p=!!a}]);_gas.push(["_addHook","_popHook",function(a){(a=_gas.d[a])&&a.pop&&a.pop();return!1}]);_gas.push(["_addHook","_setDefaultTracker",function(a){_gas.f=a}]);_gas.push(["_addHook","_trackPageview",function(a,b){if(b&&typeof b==="string"){var c=g.title;h.s.push(function(){g.title=b},["_trackPageview",a],function(){g.title=c});return!1}return[a]}]);_gas.push(["_addHook","_trackDownloads",function(a){var b=
+"xls,xlsx,doc,docx,ppt,pptx,pdf,txt,zip";b+=",rar,7z,exe,wma,mov,avi,wmv,mp3,csv,tsv";b=b.split(",");typeof a==="string"?b=b.concat(a.split(",")):this.isArray(a)&&(b=b.concat(a));J.call(this,b);return!1}]);_gas.push(["_addHook","_trackEvent",function(){var a=m.call(arguments);a[3]&&(a[3]=(a[3]<0?0:Math.round(a[3]))||0);return a}]);_gas.push(["_addHook","_trackForms",function(a){var b=this;this.e(function(){for(var c=g.getElementsByTagName("form"),d=0;d<c.length;d++){try{K.call(b,c[d],a)}catch(e){}if(a)break}return!1})}]);
+_gas.push(["_addHook","_trackVideo",function(){A.call(this,"video")}]);_gas.push(["_addHook","_trackAudio",function(){A.call(this,"audio")}]);var w=null,j=0;_gas.push(["_addHook","_trackMaxScroll",function(){this.a(h,"scroll",C);this.a(h,"beforeunload",L)}]);_gas.c=!1;_gas.push(["_addHook","_setAllowAnchor",function(a){_gas.c=!!a}]);_gas.push(["_addHook","_link",function(a,b){if(b===n)b=_gas.c;return[a,b]}]);_gas.push(["_addHook","_linkByPost",function(a,b){if(b===n)b=_gas.c;return[a,b]}]);var u=
+[],H=n;_gas.push(["_addHook","_setDomainName",function(a){if(i.call("."+g.location.hostname,a)<0)return u.push(a),!1;H=a}]);_gas.push(["_addHook","_addExternalDomainName",function(a){u.push(a);return!1}]);_gas.push(["_addHook","_setMultiDomain",function(a){var b=g.location.hostname,c=this,d,e,f,h=g.getElementsByTagName("a");a!=="now"&&a!=="mousedown"&&(a="click");for(d=0;d<h.length;d++)if(f=h[d],i.call(f.href,"http")===0&&!(f.hostname==b||i.call(f.hostname,H)>=0))for(e=0;e<u.length;e++)if(i.call(f.hostname,
+u[e])>=0)a==="now"?f.href=c.tracker._getLinkerUrl(f.href,_gas.c):a==="click"?this.a(f,a,function(a){_gas.push(["_link",this.href,_gas.c]);a.preventDefault?a.preventDefault():a.returnValue=!1}):this.a(f,a,function(){this.href=c.tracker._getLinkerUrl(this.href,_gas.c)});return!1}]);_gas.push(["_addHook","_trackOutboundLinks",function(){for(var a=g.getElementsByTagName("a"),b=0;b<a.length;b++)this.a(a[b],"mousedown",function(a){a=a.target;if((a.protocol=="http:"||a.protocol=="https:")&&i.call(a.href,
+g.location.hostname)===-1){var b=a.pathname+a.search+"",e=i.call(b,"__utm");e!==-1&&(b=b.substring(0,e));_gas.push(["_trackEvent","Outbound",a.hostname,b])}})}]);var G={},F=!1;_gas.push(["_addHook","_trackVimeo",function(a){var b=this;b.e(function(){E.call(b,a)});return!1}]);var t=[],l={};for(_gas.push(["_addHook","_trackYoutube",function(){var a=m.call(arguments),b=this;b.e(function(){P.apply(b,a)});return!1}]);_gas.l.length>0;)_gas.push(_gas.l.shift());_gaq&&_gaq.length>=0&&function(){var a=g.createElement("script");
a.type="text/javascript";a.async=!0;a.src=("https:"==g.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";var b=g.getElementsByTagName("script")[0];b.parentNode.insertBefore(a,b)}()}})(window);
View
8 src/core.js
@@ -106,7 +106,7 @@ GAS.prototype._execute = function() {
self = this,
sub = args.shift(),
gaq_execute = true,
- i, foo, hooks, acct_name, repl_sub;
+ i, foo, hooks, acct_name, repl_sub, return_val = 0;
if (typeof sub === 'function') {
// Pushed functions are executed right away
@@ -176,7 +176,10 @@ GAS.prototype._execute = function() {
self._accounts[acct_name] = sub[0];
self._accounts_length += 1;
acct_name = _build_acct_name(acct_name);
- return _gaq_push([acct_name + foo, sub[0]]);
+ return_val = _gaq_push([acct_name + foo, sub[0]]);
+ // Must try t get the tracker if it's a _setAccount
+ self.gh._setDummyTracker();
+ return return_val;
}
// Intercept _linka and _linkByPost
@@ -196,7 +199,6 @@ GAS.prototype._execute = function() {
}
// Call Original _gaq, for all accounts
- var return_val = 0;
for (i in self._accounts) {
if (hasOwn.call(self._accounts, i)) {
acc_foo = _build_acct_name(i) + foo;
View
11 src/helpers.js
@@ -17,7 +17,16 @@
* @constructor
*/
var GasHelper = function() {
- this['tracker'] = window['_gat']['_getTrackers']()[0];
+ this._setDummyTracker();
+};
+
+GasHelper.prototype._setDummyTracker = function() {
+ if (!this['tracker']) {
+ var trackers = window['_gat']['_getTrackers']();
+ if (trackers.length > 0) {
+ this['tracker'] = trackers[0];
+ }
+ }
};
/**
View
2 test/gas.html
@@ -6,7 +6,7 @@
<link rel="stylesheet" href="qunit/qunit.css" type="text/css" media="screen">
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script>
<script type="text/javascript" src="qunit/qunit.js"></script>
- <script type="text/javascript" src="../dist/gas.min.js?cb=3"></script>
+ <script type="text/javascript" src="../dist/gas.js?cb=0"></script>
<script type="text/javascript" src="test_core.js"></script>
<script type="text/javascript" src="test_multidomain.js"></script>
<script type="text/javascript" src="test_form_tracking.js"></script>
View
1 test/index.html
@@ -7,6 +7,7 @@
<li><a href="./test_form.html">Test Form Tracking</a></li>
<li><a href="./test_outbound.html">Test Outbound Link Tracking</a></li>
<li><a href="./test_maxscroll.html">Test Max Scroll Tracking</a></li>
+ <li><a href="./test_multidomain.html">Test Multidomain Tracking</a></li>
</ul>
</body>
</html>

0 comments on commit c2fff8e

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