Skip to content

Commit

Permalink
Add setRemoveRegExp to README.md (Fix #82)
Browse files Browse the repository at this point in the history
* Added remark on setRemoveRegExp to Configuration section.
* Cleaned up comment capitalization and spacing.
* Wrapped HTML snippets in proper blocks for visual styling.
  • Loading branch information
justinsa committed Jul 27, 2015
1 parent 38cfed7 commit 4f721df
Showing 1 changed file with 33 additions and 25 deletions.
58 changes: 33 additions & 25 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,27 +32,28 @@ Or alternatively, grab the dist/angular-google-analytics.min.js and include it i
```js
var app = angular.module('app', ['angular-google-analytics'])
.config(function(AnalyticsProvider) {
// initial configuration
// Set analytics account
AnalyticsProvider.setAccount('UA-XXXXX-xx');
// using multiple tracking objects (analytics.js only)
// AnalyticsProvider.setAccount([
// { tracker: 'UA-12345-12', name: "tracker1" },
// { tracker: 'UA-12345-34', name: "tracker2" }
// ]);

// track all routes (or not)
// Or if using multiple tracking objects (analytics.js only)
AnalyticsProvider.setAccount([
{ tracker: 'UA-12345-12', name: "tracker1" },
{ tracker: 'UA-12345-34', name: "tracker2" }
]);

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

// track all url query params (default is false)
// Track all URL query params (default is false)
AnalyticsProvider.trackUrlParams(true);

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

// Use display features plugin
AnalyticsProvider.useDisplayFeatures(true);

// url prefix (default is empty)
// 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 @@ -86,16 +87,16 @@ var app = angular.module('app', ['angular-google-analytics'])
cookieExpires: 20000
});

// change page event name
// Change page event name
AnalyticsProvider.setPageEvent('$stateChangeSuccess');

// Delay script tag creation
// must manually call Analytics.createScriptTag(cookieConfig) or Analytics.createAnalyticsScriptTag(cookieConfig)
AnalyticsProvider.delayScriptTag(true);
}))
.run(function(Analytics) {
// In case you are relying on automatic page tracking, you need to inject Analytics
// at least once in your application (for example in the main run() block)
// In case you are relying on automatic page tracking, you need to inject Analytics
// at least once in your application (for example in the main run() block)
})
.controller('SampleController', function(Analytics) {
// create a new pageview event
Expand All @@ -114,14 +115,14 @@ var app = angular.module('app', ['angular-google-analytics'])
// create a new tracking event with optional value
Analytics.trackEvent('video', 'play', 'django.mp4', 4);

// create a new tracking event with optional value and noninteraction flag
// Create a new tracking event with optional value and noninteraction flag
Analytics.trackEvent('video', 'play', 'django.mp4', 4, true);

// create a new tracking event with optional value, noninteraction flag, and custom dimension and metric
// Create a new tracking event with optional value, noninteraction flag, and custom dimension and metric
// (analytics.js only)
Analytics.trackEvent('video', 'play', 'django.mp4', 4, true, {dimension15: 'My Custom Dimension', metric18: 8000});

// tracking e-commerce
// Tracking e-commerce
// - create transaction
Analytics.addTrans('1', '', '2.42', '0.42', '0', 'Amsterdam', '', 'Netherlands', 'EUR');

Expand Down Expand Up @@ -216,40 +217,45 @@ var app = angular.module('app', ['angular-google-analytics'])
// Manually create Analytics script tag after using delayScriptTag
Analytics.createAnalyticsScriptTag({userId: 1234})

//Track User Timings
// Track User Timings
Analytics.trackTimings(timingCategory, timingVar, timingValue, timingLabel)
//example:
// example:
var endTime = new Date().getTime();
var timeSpent = endTime - startTime;
Analytics.trackTimings('Time to Checkout', 'User Timings', timeSpent);

});
```

### Directive

Alternatively you can use a directive to avoid filling controllers with `Analytics.trackEvent()` statements. Note: the directive does not create an isolate scope.

```html
<button type="button" ga-track-event="['video', 'play', 'django.mp4']"></button>

```
<!-- OR -->

```html
<button type="button" ga-track-event="['video', 'play', 'django.mp4', 4, true, {dimension15: 'My Custom Dimension', metric18: 8000}]"></button>
```

You can define the properties on your controller too, `$scope.event = ['video', 'play', 'django.mp4']` and reference them

```html
<button type="button" ga-track-event="event"></button>
```

`ga-track-event-if` is a conditional check. If the attribute value evaluates to a falsey, the event will NOT be fired. Useful for user tracking opt-out, etc.

```html
<button type="button" ga-track-event="['video', 'play', 'django.mp4']" ga-track-event-if="shouldTrack"></button>
```

## Configuration

```js
// setup your account
// Setup your account
AnalyticsProvider.setAccount('UA-XXXXX-xx');
// automatic route tracking (default=true)
// Automatic route tracking (default: true)
AnalyticsProvider.trackPages(false);
// Optional set domain (Use 'none' for testing on localhost)
AnalyticsProvider.setDomainName('XXX');
Expand All @@ -259,6 +265,7 @@ AnalyticsProvider.useDisplayFeatures(true);
AnalyticsProvider.useAnalytics(true);
// Ignore first page view.
AnalyticsProvider.ignoreFirstPageLoad(true);

// Enable eCommerce module for analytics.js
AnalyticsProvider.useECommerce(true, false);
// Enable enhanced eCommerce module for analytics.js
Expand All @@ -275,9 +282,10 @@ AnalyticsProvider.setCookieConfig({
});
// Change the default page event name. This is useful for ui-router, which fires $stateChangeSuccess instead of $routeChangeSuccess
AnalyticsProvider.setPageEvent('$stateChangeSuccess');
// Delay script tage creation...must manually call Analytics.createScriptTag() or Analytics.createAnalyticsScriptTag() to enable analytics
// Delay script tag creation. Must manually call Analytics.createScriptTag() or Analytics.createAnalyticsScriptTag() to enable analytics
AnalyticsProvider.delayScriptTag(true);

// RegEx to scrub location before sending to analytics. Internally replaces all matching segments with an empty string
AnalyticsProvider.setRemoveRegExp(/\/\d+?$/);
```

## AdBlock EasyPrivacy
Expand Down

0 comments on commit 4f721df

Please sign in to comment.