|
|
|
"use strict";angular.module("angular-google-analytics",[]).provider("Analytics",function(){var e,t,n,i,a,c,r=!1,o=!0,s="",u=!1,l="$routeChangeSuccess",g="auto",d=!1,m=!1,_=!1,f=!1,h=!1,p={allowLinker:!0},k=!1,v=!1;this._logs=[],this.setAccount=function(t){return e=t,!0},this.trackPages=function(e){return o=e,!0},this.trackPrefix=function(e){return s=e,!0},this.setDomainName=function(e){return n=e,!0},this.useDisplayFeatures=function(e){return t=!!e,!0},this.useAnalytics=function(e){return u=!!e,!0},this.useEnhancedLinkAttribution=function(e){return _=!!e,!0},this.useCrossDomainLinker=function(e){return h=!!e,!0},this.setCrossLinkDomains=function(e){return c=e,!0},this.setPageEvent=function(e){return l=e,!0},this.setCookieConfig=function(e){return g=e,!0},this.useECommerce=function(e,t){return d=!!e,m=!!t,!0},this.setRemoveRegExp=function(e){return e instanceof RegExp?(i=e,!0):!1},this.setExperimentId=function(e){return a=e,!0},this.ignoreFirstPageLoad=function(e){return f=!!e,!0},this.trackUrlParams=function(e){return k=!!e,!0},this.delayScriptTag=function(e){return v=!!e,!0},this.$get=["$document","$location","$log","$rootScope","$window",function(E,y,w,A,T){function P(e){!u&&T._gaq&&"function"==typeof e&&e()}function b(e){u&&T.ga&&"function"==typeof e&&e()}function C(e,t){return!angular.isUndefined(t)&&"name"in t&&t.name?t.name+"."+e:e}function q(e,t){return e in t&&t[e]}var I=this,j=function(){var e=k?y.url():y.path();return i?e.replace(i,""):e};return this._log=function(){arguments.length>0&&(arguments.length>1&&"warn"===arguments[0]&&w.warn(Array.prototype.slice.call(arguments,1)),this._logs.push(arguments))},this._createScriptTag=function(){if(!e)return I._log("warn","No account id set to create script tag"),void 0;if(r)return I._log("warn","Script tag already created"),void 0;T._gaq=[],T._gaq.push(["_setAccount",e]),n&&T._gaq.push(["_setDomainName",n]),_&&T._gaq.push(["_require","inpage_linkid","//www.google-analytics.com/plugins/ga/inpage_linkid.js"]),o&&!f&&(i?T._gaq.push(["_trackPageview",j()]):T._gaq.push(["_trackPageview"]));var a;return a=t?("https:"===document.location.protocol?"https://":"http://")+"stats.g.doubleclick.net/dc.js":("https:"===document.location.protocol?"https://ssl":"http://www")+".google-analytics.com/ga.js",function(){var e=E[0],t=e.createElement("script");t.type="text/javascript",t.async=!0,t.src=a;var n=e.getElementsByTagName("script")[0];n.parentNode.insertBefore(t,n)}(a),r=!0},this._createAnalyticsScriptTag=function(){if(!e)return I._log("warn","No account id set to create analytics script tag"),void 0;if(r)return I._log("warn","Analytics script tag already created"),void 0;if(function(e,t,n,i,a,c,r){e.GoogleAnalyticsObject=a,e[a]=e[a]||function(){(e[a].q=e[a].q||[]).push(arguments)},e[a].l=1*new Date,c=t.createElement(n),r=t.getElementsByTagName(n)[0],c.async=1,c.src=i,r.parentNode.insertBefore(c,r)}(window,document,"script","//www.google-analytics.com/analytics.js","ga"),angular.isArray(e)?e.forEach(function(e){var t,n="cookieConfig"in e?e.cookieConfig:g;q("crossDomainLinker",e)&&(e.allowLinker=e.crossDomainLinker),angular.forEach(["name","allowLinker"],function(n){n in e&&(angular.isUndefined(t)&&(t={}),t[n]=e[n])}),angular.isUndefined(t)?T.ga("create",e.tracker,n):T.ga("create",e.tracker,n,t),t&&"allowLinker"in t&&t.allowLinker&&(T.ga(C("require",e),"linker"),q("crossLinkDomains",e)&&T.ga(C("linker:autoLink",e),e.crossLinkDomains))}):h?(T.ga("create",e,g,p),T.ga("require","linker"),c&&T.ga("linker:autoLink",c)):T.ga("create",e,g),t&&T.ga("require","displayfeatures"),o&&!f&&T.ga("send","pageview",j()),T.ga&&(d&&(m?T.ga("require","ec","ec.js"):T.ga("require","ecommerce","ecommerce.js")),_&&T.ga("require","linkid","linkid.js"),a)){var n=document.createElement("script"),i=document.getElementsByTagName("script")[0];n.src="//www.google-analytics.com/cx/api.js?experiment="+a,i.parentNode.insertBefore(n,i)}return r=!0},this._ecommerceEnabled=function(){return d?m?(this._log("warn","Enhanced ecommerce plugin is enabled. Only one plugin(ecommerce/ec) can be used at a time. Use AnalyticsPro
|