Skip to content

Commit

Permalink
feat(tracker): added setDomainName
Browse files Browse the repository at this point in the history
add custom domainName support that allow localhost testing
  • Loading branch information
sjurba authored and revolunet committed Jul 7, 2013
1 parent 5dac41c commit ce2889f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
9 changes: 8 additions & 1 deletion README.md
Expand Up @@ -10,6 +10,7 @@ Proudly brought to you by the [@revolunet](http://twitter.com/revolunet) team.
- automatic page tracking
- events tracking
- e-commerce tracking
- multiple-domains

## example

Expand All @@ -21,7 +22,10 @@ var app = angular.module('app', ['angular-google-analytics'])

// track all routes (or not)
AnalyticsProvider.trackPages(true);


//Optional set domain (Use 'none' for testing on localhost)
//AnalyticsProvider.setDomainName('XXX');

// url prefix (default is empty)
// - for example: when an app doesn't run in the root directory
AnalyticsProvider.trackPrefix('my-application');
Expand Down Expand Up @@ -53,6 +57,9 @@ var app = angular.module('app', ['angular-google-analytics'])
AnalyticsProvider.setAccount('UA-XXXXX-xx');
// automatic route tracking (default=true)
AnalyticsProvider.trackPages(false);
//Optional set domain (Use 'none' for testing on localhost)
AnalyticsProvider.setDomainName('XXX');

```

## Licence
Expand Down
11 changes: 9 additions & 2 deletions src/angular-google-analytics.js
Expand Up @@ -7,7 +7,8 @@ angular.module('angular-google-analytics', [])
var created = false,
trackRoutes = true,
accountId,
trackPrefix = '';
trackPrefix = ''',
domainName;

this._logs = [];

Expand All @@ -25,6 +26,11 @@ angular.module('angular-google-analytics', [])
return true;
};

this.setDomainName = function(domain) {
domainName = domain;
return true;
};

// public service
this.$get = ['$document', '$rootScope', '$location', '$window', function($document, $rootScope, $location, $window) {
// private methods
Expand All @@ -34,6 +40,7 @@ angular.module('angular-google-analytics', [])
$window._gaq = [];
$window._gaq.push(['_setAccount', accountId]);
if (trackRoutes) $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;
Expand Down Expand Up @@ -141,4 +148,4 @@ angular.module('angular-google-analytics', [])
};
}];

});
});

0 comments on commit ce2889f

Please sign in to comment.