diff --git a/dist/angular-google-analytics.min.js b/dist/angular-google-analytics.min.js index 5a6ecd1..6a1fa6f 100644 --- a/dist/angular-google-analytics.min.js +++ b/dist/angular-google-analytics.min.js @@ -1,8 +1 @@ -/** - * Angular Google Analytics - Easy tracking for your AngularJS application - * @version v0.0.3 - 2014-06-05 - * @link http://revolunet.com.github.com/angular-google-analytics - * @author Julien Bouquillon - * @license MIT License, http://www.opensource.org/licenses/MIT - */ -"use strict";angular.module("angular-google-analytics",[]).provider("Analytics",function(){var e,t,n,a,r=!1,i=!0,s="",c=!1,o="$routeChangeSuccess",g="auto",u=!1,m=!1,l=!1;this._logs=[],this.setAccount=function(t){return e=t,!0},this.trackPages=function(e){return i=e,!0},this.trackPrefix=function(e){return s=e,!0},this.setDomainName=function(e){return t=e,!0},this.useAnalytics=function(e){return c=!!e,!0},this.useEnhancedLinkAttribution=function(e){return m=!!e,!0},this.setPageEvent=function(e){return o=e,!0},this.setCookieConfig=function(e){return g=e,!0},this.useECommerce=function(e){return u=!!e,!0},this.setRemoveRegExp=function(e){return e instanceof RegExp?(n=e,!0):!1},this.setExperimentId=function(e){return a=e,!0},this.ignoreFirstPageLoad=function(e){l=!!e},this.$get=["$document","$rootScope","$location","$window",function(_,d,h,f){function p(){e&&(f._gaq=[],f._gaq.push(["_setAccount",e]),m&&f._gaq.push(["_require","inpage_linkid","//www.google-analytics.com/plugins/ga/inpage_linkid.js"]),i&&!l&&(n?f._gaq.push(["_trackPageview",v()]):f._gaq.push(["_trackPageview"])),t&&f._gaq.push(["_setDomainName",t]),function(){var e=_[0],t=e.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===e.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";var n=e.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)}(),r=!0)}function k(){if(!e)return console.warn("No account id set for Analytics.js");if(function(e,t,n,a,r,i,s){e.GoogleAnalyticsObject=r,e[r]=e[r]||function(){(e[r].q=e[r].q||[]).push(arguments)},e[r].l=1*new Date,i=t.createElement(n),s=t.getElementsByTagName(n)[0],i.async=1,i.src=a,s.parentNode.insertBefore(i,s)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),f.ga("create",e,g),i&&!l&&f.ga("send","pageview",v()),f.ga&&(u&&f.ga("require","ecommerce","ecommerce.js"),m&&f.ga("require","linkid","linkid.js"),a)){var t=document.createElement("script"),n=document.getElementsByTagName("script")[0];t.src="//www.google-analytics.com/cx/api.js?experiment="+a,n.parentNode.insertBefore(t,n)}}var v=function(){var e=h.path();return n?e.replace(n,""):e};this._log=function(){this._logs.push(arguments)},this._trackPage=function(e,t){t=t?t:_[0].title,i&&!c&&f._gaq?(f._gaq.push(["_set","title",t]),f._gaq.push(["_trackPageview",s+e]),this._log("_trackPageview",arguments)):i&&c&&f.ga&&(f.ga("send","pageview",{page:s+e,title:t}),this._log("pageview",arguments))},this._trackEvent=function(e,t,n,a){!c&&f._gaq?(f._gaq.push(["_trackEvent",e,t,n,a]),this._log("trackEvent",arguments)):f.ga&&(f.ga("send","event",e,t,n,a),this._log("event",arguments))},this._addTrans=function(e,t,n,a,r,i,s,o,g){!c&&f._gaq?(f._gaq.push(["_addTrans",e,t,n,a,r,i,s,o]),this._log("_addTrans",arguments)):f.ga&&(u?(f.ga("ecommerce:addTransaction",{id:e,affiliation:t,revenue:n,tax:a,shipping:r,currency:g||"USD"}),this._log("ecommerce:addTransaction",arguments)):console.warn("ecommerce no set. Use AnalyticsProvider.setECommerce(true);"))},this._addItem=function(e,t,n,a,r,i){!c&&f._gaq?(f._gaq.push(["_addItem",e,t,n,a,r,i]),this._log("_addItem",arguments)):f.ga&&(f.ga("ecommerce:addItem",{id:e,name:n,sku:t,category:a,price:r,quantity:i}),this._log("ecommerce:addItem",arguments))},this._trackTrans=function(){!c&&f._gaq?(f._gaq.push(["_trackTrans"]),this._log("_trackTrans",arguments)):f.ga&&(f.ga("ecommerce:send"),this._log("ecommerce:send",arguments))},this._clearTrans=function(){f.ga&&(f.ga("ecommerce:clear"),this._log("ecommerce:clear",arguments))},this._send=function(e){f.ga&&(f.ga("send",e),this._log("send",e))},c?k():p();var w=this;return i&&d.$on(o,function(){w._trackPage(v())}),{_logs:w._logs,cookieConfig:g,ecommerce:u,enhancedLinkAttribution:m,getUrl:v,experimentId:a,ignoreFirstPageLoad:l,trackPage:function(e,t){w._trackPage(e,t)},trackEvent:function(e,t,n,a){w._trackEvent(e,t,n,a)},addTrans:function(e,t,n,a,r,i,s,c,o){w._addTrans(e,t,n,a,r,i,s,c,o)},addItem:function(e,t,n,a,r,i){w._addItem(e,t,n,a,r,i)},trackTrans:function(){w._trackTrans()},clearTrans:function(){w._clearTrans()},send:function(e){w._send(e)}}}]}); \ No newline at end of file +"use strict";angular.module("angular-google-analytics",[]).provider("Analytics",function(){var e=false,t=true,n,r="",i,s=false,o="$routeChangeSuccess",u="auto",a=false,f=false,l,c,h=false;this._logs=[];this.setAccount=function(e){n=e;return true};this.trackPages=function(e){t=e;return true};this.trackPrefix=function(e){r=e;return true};this.setDomainName=function(e){i=e;return true};this.useAnalytics=function(e){s=!!e;return true};this.useEnhancedLinkAttribution=function(e){f=!!e;return true};this.setPageEvent=function(e){o=e;return true};this.setCookieConfig=function(e){u=e;return true};this.useECommerce=function(e){a=!!e;return true};this.setRemoveRegExp=function(e){if(e instanceof RegExp){l=e;return true}return false};this.setExperimentId=function(e){c=e;return true};this.ignoreFirstPageLoad=function(e){h=!!e};this.$get=["$document","$rootScope","$location","$window",function(p,d,v,m){function y(){if(!n)return;m._gaq=[];m._gaq.push(["_setAccount",n]);if(i)m._gaq.push(["_setDomainName",i]);if(f){m._gaq.push(["_require","inpage_linkid","//www.google-analytics.com/plugins/ga/inpage_linkid.js"])}if(t&&!h){if(l){m._gaq.push(["_trackPageview",g()])}else{m._gaq.push(["_trackPageview"])}}(function(){var e=p[0];var t=e.createElement("script");t.type="text/javascript";t.async=true;t.src=("https:"===e.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js";var n=e.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)})();e=true}function b(){if(!n){return console.warn("No account id set for Analytics.js")}(function(e,t,n,r,i,s,o){e["GoogleAnalyticsObject"]=i;e[i]=e[i]||function(){(e[i].q=e[i].q||[]).push(arguments)},e[i].l=1*new Date;s=t.createElement(n),o=t.getElementsByTagName(n)[0];s.async=1;s.src=r;o.parentNode.insertBefore(s,o)})(window,document,"script","//www.google-analytics.com/analytics.js","ga");m.ga("create",n,u);if(t&&!h){m.ga("send","pageview",g())}if(m.ga){if(a){m.ga("require","ecommerce","ecommerce.js")}if(f){m.ga("require","linkid","linkid.js")}if(c){var e=document.createElement("script"),r=document.getElementsByTagName("script")[0];e.src="//www.google-analytics.com/cx/api.js?experiment="+c;r.parentNode.insertBefore(e,r)}}}var g=function(){var e=v.path();if(l){return e.replace(l,"")}return e};this._log=function(){this._logs.push(arguments)};this._trackPage=function(e,n){n=n?n:p[0].title;if(t&&!s&&m._gaq){m._gaq.push(["_set","title",n]);m._gaq.push(["_trackPageview",r+e]);this._log("_trackPageview",arguments)}else if(t&&s&&m.ga){m.ga("send","pageview",{page:r+e,title:n});this._log("pageview",arguments)}};this._trackEvent=function(e,t,n,r){if(!s&&m._gaq){m._gaq.push(["_trackEvent",e,t,n,r]);this._log("trackEvent",arguments)}else if(m.ga){m.ga("send","event",e,t,n,r);this._log("event",arguments)}};this._addTrans=function(e,t,n,r,i,o,u,f,l){if(!s&&m._gaq){m._gaq.push(["_addTrans",e,t,n,r,i,o,u,f]);this._log("_addTrans",arguments)}else if(m.ga){if(!a){console.warn("ecommerce no set. Use AnalyticsProvider.setECommerce(true);")}else{m.ga("ecommerce:addTransaction",{id:e,affiliation:t,revenue:n,tax:r,shipping:i,currency:l||"USD"});this._log("ecommerce:addTransaction",arguments)}}};this._addItem=function(e,t,n,r,i,o){if(!s&&m._gaq){m._gaq.push(["_addItem",e,t,n,r,i,o]);this._log("_addItem",arguments)}else if(m.ga){m.ga("ecommerce:addItem",{id:e,name:n,sku:t,category:r,price:i,quantity:o});this._log("ecommerce:addItem",arguments)}};this._trackTrans=function(){if(!s&&m._gaq){m._gaq.push(["_trackTrans"]);this._log("_trackTrans",arguments)}else if(m.ga){m.ga("ecommerce:send");this._log("ecommerce:send",arguments)}};this._clearTrans=function(){if(m.ga){m.ga("ecommerce:clear");this._log("ecommerce:clear",arguments)}};this._send=function(e){if(m.ga){m.ga("send",e);this._log("send",e)}};if(s){b()}else{y()}var w=this;if(t)d.$on(o,function(){w._trackPage(g())});return{_logs:w._logs,cookieConfig:u,ecommerce:a,enhancedLinkAttribution:f,getUrl:g,experimentId:c,ignoreFirstPageLoad:h,trackPage:function(e,t){w._trackPage(e,t)},trackEvent:function(e,t,n,r){w._trackEvent(e,t,n,r)},addTrans:function(e,t,n,r,i,s,o,u,a){w._addTrans(e,t,n,r,i,s,o,u,a)},addItem:function(e,t,n,r,i,s){w._addItem(e,t,n,r,i,s)},trackTrans:function(){w._trackTrans()},clearTrans:function(){w._clearTrans()},send:function(e){w._send(e)}}}]})