From 5792b68271846b62df28d917cbb9fd812afe76d4 Mon Sep 17 00:00:00 2001 From: Julien Bouquillon Date: Thu, 5 Jun 2014 10:07:34 +0200 Subject: [PATCH] chore: add dist folder for bower --- dist/angular-google-analytics.js | 353 +++++++++++++++++++++++++++ dist/angular-google-analytics.min.js | 8 + 2 files changed, 361 insertions(+) create mode 100644 dist/angular-google-analytics.js create mode 100644 dist/angular-google-analytics.min.js diff --git a/dist/angular-google-analytics.js b/dist/angular-google-analytics.js new file mode 100644 index 0000000..39de5b4 --- /dev/null +++ b/dist/angular-google-analytics.js @@ -0,0 +1,353 @@ +/** + * 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 + */ +/* global angular, console */ + +'use strict'; + +angular.module('angular-google-analytics', []) + .provider('Analytics', function() { + var created = false, + trackRoutes = true, + accountId, + trackPrefix = '', + domainName, + analyticsJS = false, + pageEvent = '$routeChangeSuccess', + cookieConfig = 'auto', + ecommerce = false, + enhancedLinkAttribution = false, + removeRegExp, + experimentId, + ignoreFirstPageLoad = false; + + this._logs = []; + + // config methods + this.setAccount = function(id) { + accountId = id; + return true; + }; + this.trackPages = function(doTrack) { + trackRoutes = doTrack; + return true; + }; + + this.trackPrefix = function(prefix) { + trackPrefix = prefix; + return true; + }; + + this.setDomainName = function(domain) { + domainName = domain; + return true; + }; + + this.useAnalytics = function(val) { + analyticsJS = !!val; + return true; + }; + + this.useEnhancedLinkAttribution = function (val) { + enhancedLinkAttribution = !!val; + return true; + }; + + this.setPageEvent = function(name) { + pageEvent = name; + return true; + }; + + this.setCookieConfig = function (config) { + cookieConfig = config; + return true; + }; + + this.useECommerce = function (val) { + ecommerce = !!val; + return true; + }; + + this.setRemoveRegExp = function (regex) { + if (regex instanceof RegExp) { + removeRegExp = regex; + return true; + } + return false; + }; + + this.setExperimentId = function (id) { + experimentId = id; + return true; + }; + + this.ignoreFirstPageLoad = function (val) { + ignoreFirstPageLoad = !!val; + }; + + // public service + this.$get = ['$document', '$rootScope', '$location', '$window', function($document, $rootScope, $location, $window) { + var getUrl = function () { + var url = $location.path(); + if (removeRegExp) { + return url.replace(removeRegExp, ''); + } + return url; + }; + + // private methods + function _createScriptTag() //noinspection JSValidateTypes + { + // inject the google analytics tag + if (!accountId) return; + $window._gaq = []; + $window._gaq.push(['_setAccount', accountId]); + if (enhancedLinkAttribution) { + $window._gaq.push(['_require', 'inpage_linkid', '//www.google-analytics.com/plugins/ga/inpage_linkid.js']); + } + if (trackRoutes && !ignoreFirstPageLoad) { + if (removeRegExp) { + $window._gaq.push(['_trackPageview', getUrl()]); + } else { + $window._gaq.push(['_trackPageview']); + } + } + if(domainName) $window._gaq.push(['_setDomainName', domainName]); + (function() { + var document = $document[0]; + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; + ga.src = ('https:' === document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); + })(); + created = true; + } + function _createAnalyticsScriptTag() { + if (!accountId) { + return console.warn('No account id set for Analytics.js'); + } + + (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){ + (i[r].q=i[r].q||[]).push(arguments);},i[r].l=1*new Date();a=s.createElement(o), + m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m); + })(window,document,'script','//www.google-analytics.com/analytics.js','ga'); + + $window.ga('create', accountId, cookieConfig); + + if (trackRoutes && !ignoreFirstPageLoad) { + $window.ga('send', 'pageview', getUrl()); + } + + if ($window.ga) { + if (ecommerce) { + $window.ga('require', 'ecommerce', 'ecommerce.js'); + } + if (enhancedLinkAttribution) { + $window.ga('require', 'linkid', 'linkid.js'); + } + if (experimentId) { + var expScript = document.createElement('script'), + s = document.getElementsByTagName('script')[0]; + expScript.src = "//www.google-analytics.com/cx/api.js?experiment=" + experimentId; + s.parentNode.insertBefore(expScript, s); + } + + } + + } + this._log = function() { + // for testing + //console.info('analytics log:', arguments); + this._logs.push(arguments); + }; + this._trackPage = function(url, title) { + title = title ? title : $document[0].title; + if (trackRoutes && !analyticsJS && $window._gaq) { + // http://stackoverflow.com/questions/7322288/how-can-i-set-a-page-title-with-google-analytics + $window._gaq.push(["_set", "title", title]); + $window._gaq.push(['_trackPageview', trackPrefix + url]); + this._log('_trackPageview', arguments); + } else if (trackRoutes && analyticsJS && $window.ga) { + $window.ga('send', 'pageview', { + 'page': trackPrefix + url, + 'title': title + }); + this._log('pageview', arguments); + } + }; + this._trackEvent = function(category, action, label, value) { + if (!analyticsJS && $window._gaq) { + $window._gaq.push(['_trackEvent', category, action, label, value]); + this._log('trackEvent', arguments); + } else if ($window.ga) { + $window.ga('send', 'event', category, action, label, value); + this._log('event', arguments); + } + + }; + + /** + * Add transaction + * https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEcommerce#_gat.GA_Tracker_._addTrans + * https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#addTrans + * @param transactionId + * @param affiliation + * @param total + * @param tax + * @param shipping + * @param city + * @param state + * @param country + * @private + */ + this._addTrans = function (transactionId, affiliation, total, tax, shipping, city, state, country, currency) { + if (!analyticsJS && $window._gaq) { + $window._gaq.push(['_addTrans', transactionId, affiliation, total, tax, shipping, city, state, country]); + this._log('_addTrans', arguments); + } else if ($window.ga) { + if (!ecommerce) { + console.warn('ecommerce no set. Use AnalyticsProvider.setECommerce(true);'); + } else { + $window.ga('ecommerce:addTransaction', { + id: transactionId, + affiliation: affiliation, + revenue: total, + tax: tax, + shipping: shipping, + currency: currency || 'USD' + }); + this._log('ecommerce:addTransaction', arguments); + } + + } + }; + + /** + * Add item to transaction + * https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEcommerce#_gat.GA_Tracker_._addItem + * https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#addItem + * @param transactionId + * @param sku + * @param name + * @param category + * @param price + * @param quantity + * @private + */ + this._addItem = function (transactionId, sku, name, category, price, quantity) { + if (!analyticsJS && $window._gaq) { + $window._gaq.push(['_addItem', transactionId, sku, name, category, price, quantity]); + this._log('_addItem', arguments); + } else if ($window.ga) { + $window.ga('ecommerce:addItem', { + id: transactionId, + name: name, + sku: sku, + category: category, + price: price, + quantity: quantity + }); + this._log('ecommerce:addItem', arguments); + } + }; + + /** + * Track transaction + * https://developers.google.com/analytics/devguides/collection/gajs/methods/gaJSApiEcommerce#_gat.GA_Tracker_._trackTrans + * https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#sendingData + * @private + */ + this._trackTrans = function () { + if (!analyticsJS && $window._gaq) { + $window._gaq.push(['_trackTrans']); + this._log('_trackTrans', arguments); + } else if ($window.ga) { + $window.ga('ecommerce:send'); + this._log('ecommerce:send', arguments); + } + + }; + + /** + * Clear transaction + * https://developers.google.com/analytics/devguides/collection/analyticsjs/ecommerce#clearingData + * + * @private + */ + this._clearTrans = function () { + if ($window.ga) { + $window.ga('ecommerce:clear'); + this._log('ecommerce:clear', arguments); + } + }; + + /** + * Send custom events + * https://developers.google.com/analytics/devguides/collection/analyticsjs/user-timings#implementation + * https://developers.google.com/analytics/devguides/collection/analyticsjs/social-interactions#implementation + * + * @param obj + * @private + */ + this._send = function (obj) { + if ($window.ga) { + $window.ga('send', obj); + this._log('send', obj); + } + }; + + + + // creates the ganalytics tracker + if (analyticsJS) { + _createAnalyticsScriptTag(); + } else { + _createScriptTag(); + } + + + var me = this; + + // activates page tracking + if (trackRoutes) $rootScope.$on(pageEvent, function() { + me._trackPage(getUrl()); + }); + + return { + _logs: me._logs, + cookieConfig: cookieConfig, + ecommerce: ecommerce, + enhancedLinkAttribution: enhancedLinkAttribution, + getUrl: getUrl, + experimentId: experimentId, + ignoreFirstPageLoad: ignoreFirstPageLoad, + trackPage: function(url, title) { + // add a page event + me._trackPage(url, title); + }, + trackEvent: function(category, action, label, value) { + // add an action event + me._trackEvent(category, action, label, value); + }, + addTrans: function (transactionId, affiliation, total, tax, shipping, city, state, country, currency) { + me._addTrans(transactionId, affiliation, total, tax, shipping, city, state, country, currency); + }, + addItem: function (transactionId, sku, name, category, price, quantity) { + me._addItem(transactionId, sku, name, category, price, quantity); + }, + trackTrans: function () { + me._trackTrans(); + }, + clearTrans: function () { + me._clearTrans(); + }, + send: function (obj) { + me._send(obj); + } + }; + }]; + + }); diff --git a/dist/angular-google-analytics.min.js b/dist/angular-google-analytics.min.js new file mode 100644 index 0000000..5a6ecd1 --- /dev/null +++ b/dist/angular-google-analytics.min.js @@ -0,0 +1,8 @@ +/** + * 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