Skip to content

Commit

Permalink
Add option to override URL
Browse files Browse the repository at this point in the history
Fixes #24

Clarify some instructions in README

Minor refactoring
  • Loading branch information
miguelzakharia committed Jun 11, 2017
1 parent edb1bb2 commit 8ee2ea2
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 136 deletions.
48 changes: 35 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,32 +22,54 @@ export function configure(aurelia) {
config.init('<Your Tracker ID>');
config.attach({
logging: {
enabled: true // Set to `true` to have some log messages appear in the browser console.
// Set to `true` to have some log messages appear in the browser console.
enabled: true
},
pageTracking: {
enabled: true // Set to `false` to disable in non-production environments.
// Set to `false` to disable in non-production environments.
enabled: true,
// Optional. By default it gets the title from payload.instruction.config.title.
getTitle: (payload) => {
// For example, if you want to retrieve the tile from the document instead override with the following.
return document.title;
},
// Optional. By default it gets the URL fragment from payload.instruction.fragment.
getUrl: (payload) => {
// For example, if you want to get full URL each time override with the following.
return window.location.href;
}
},
clickTracking: {
enabled: true // Set to `false` to disable in non-production environments.
// Set to `false` to disable in non-production environments.
enabled: true,
// Optional. By default it tracks clicks on anchors and buttons.
filter: (element) => {
// For example, if you want to also track clicks on span elements override with the following.
return element instanceof HTMLElement &&
(element.nodeName.toLowerCase() === 'a' ||
element.nodeName.toLowerCase() === 'button' ||
element.nodeName.toLowerCase() === 'span');
}
},
exceptionTracking: {
enabled: true // Set to `false` to disable in non-production environments.
// Set to `false` to disable in non-production environments.
enabled: true
}
});
});
});

aurelia.start().then(a => a.setRoot());
}
```
* If you are using [Aurelia CLI](http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/the-aurelia-cli/10), you need to add following two libraries to your bundle dependencies.
* If you are using [Aurelia CLI](http://aurelia.io/hub.html#/doc/article/aurelia/framework/latest/the-aurelia-cli/10), you need to add the following two libraries to your bundle dependencies.

```
"deepmerge",
{
"name": "aurelia-google-analytics",
"path": "../node_modules/aurelia-google-analytics/dist/amd",
"main": "index"
}
"deepmerge",
{
"name": "aurelia-google-analytics",
"path": "../node_modules/aurelia-google-analytics/dist/amd",
"main": "index"
}
```

In order to use the click tracking feature, each HTML element you want to track must contain a `data-analytics-category` and `data-analytics-action` attribute. `data-analytics-label` and `data-analytics-value` are supported and optional.
Expand Down
51 changes: 27 additions & 24 deletions dist/amd/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,6 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-event-aggregator', '

var _dec, _class;

var defaultOptions = {
logging: {
enabled: true
},
pageTracking: {
enabled: false,
getTitle: function getTitle(payload) {
return payload.instruction.config.title;
}
},
clickTracking: {
enabled: false,
filter: function filter(element) {
return element instanceof HTMLElement && (element.nodeName.toLowerCase() === 'a' || element.nodeName.toLowerCase() === 'button');
}
},
exceptionTracking: {
enabled: true,
applicationName: undefined,
applicationVersion: undefined
}
};

var criteria = {
isElement: function isElement(e) {
return e instanceof HTMLElement;
Expand All @@ -94,6 +71,32 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-event-aggregator', '
}
};

var defaultOptions = {
logging: {
enabled: true
},
pageTracking: {
enabled: false,
getTitle: function getTitle(payload) {
return payload.instruction.config.title;
},
getUrl: function getUrl(payload) {
return payload.instruction.fragment;
}
},
clickTracking: {
enabled: false,
filter: function filter(element) {
return criteria.isAnchor(element) || criteria.isButton(element);
}
},
exceptionTracking: {
enabled: true,
applicationName: undefined,
applicationVersion: undefined
}
};

var delegate = function delegate(criteria, listener) {
return function (evt) {
var el = evt.target;
Expand Down Expand Up @@ -164,7 +167,7 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-event-aggregator', '
}

this._eventAggregator.subscribe('router:navigation:success', function (payload) {
_this._trackPage(payload.instruction.fragment, _this._options.pageTracking.getTitle(payload));
_this._trackPage(_this._options.pageTracking.getUrl(payload), _this._options.pageTracking.getTitle(payload));
});
};

Expand Down
51 changes: 27 additions & 24 deletions dist/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,29 +48,6 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-event-aggregator', '

var _dec, _class;

var defaultOptions = {
logging: {
enabled: true
},
pageTracking: {
enabled: false,
getTitle: function getTitle(payload) {
return payload.instruction.config.title;
}
},
clickTracking: {
enabled: false,
filter: function filter(element) {
return element instanceof HTMLElement && (element.nodeName.toLowerCase() === 'a' || element.nodeName.toLowerCase() === 'button');
}
},
exceptionTracking: {
enabled: true,
applicationName: undefined,
applicationVersion: undefined
}
};

var criteria = {
isElement: function isElement(e) {
return e instanceof HTMLElement;
Expand All @@ -94,6 +71,32 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-event-aggregator', '
}
};

var defaultOptions = {
logging: {
enabled: true
},
pageTracking: {
enabled: false,
getTitle: function getTitle(payload) {
return payload.instruction.config.title;
},
getUrl: function getUrl(payload) {
return payload.instruction.fragment;
}
},
clickTracking: {
enabled: false,
filter: function filter(element) {
return criteria.isAnchor(element) || criteria.isButton(element);
}
},
exceptionTracking: {
enabled: true,
applicationName: undefined,
applicationVersion: undefined
}
};

var delegate = function delegate(criteria, listener) {
return function (evt) {
var el = evt.target;
Expand Down Expand Up @@ -164,7 +167,7 @@ define(['exports', 'aurelia-dependency-injection', 'aurelia-event-aggregator', '
}

this._eventAggregator.subscribe('router:navigation:success', function (payload) {
_this._trackPage(payload.instruction.fragment, _this._options.pageTracking.getTitle(payload));
_this._trackPage(_this._options.pageTracking.getUrl(payload), _this._options.pageTracking.getTitle(payload));
});
};

Expand Down
51 changes: 27 additions & 24 deletions dist/commonjs/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,6 @@ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj;

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

var defaultOptions = {
logging: {
enabled: true
},
pageTracking: {
enabled: false,
getTitle: function getTitle(payload) {
return payload.instruction.config.title;
}
},
clickTracking: {
enabled: false,
filter: function filter(element) {
return element instanceof HTMLElement && (element.nodeName.toLowerCase() === 'a' || element.nodeName.toLowerCase() === 'button');
}
},
exceptionTracking: {
enabled: true,
applicationName: undefined,
applicationVersion: undefined
}
};

var criteria = {
isElement: function isElement(e) {
return e instanceof HTMLElement;
Expand All @@ -75,6 +52,32 @@ var criteria = {
}
};

var defaultOptions = {
logging: {
enabled: true
},
pageTracking: {
enabled: false,
getTitle: function getTitle(payload) {
return payload.instruction.config.title;
},
getUrl: function getUrl(payload) {
return payload.instruction.fragment;
}
},
clickTracking: {
enabled: false,
filter: function filter(element) {
return criteria.isAnchor(element) || criteria.isButton(element);
}
},
exceptionTracking: {
enabled: true,
applicationName: undefined,
applicationVersion: undefined
}
};

var delegate = function delegate(criteria, listener) {
return function (evt) {
var el = evt.target;
Expand Down Expand Up @@ -145,7 +148,7 @@ var Analytics = exports.Analytics = (_dec = (0, _aureliaDependencyInjection.inje
}

this._eventAggregator.subscribe('router:navigation:success', function (payload) {
_this._trackPage(payload.instruction.fragment, _this._options.pageTracking.getTitle(payload));
_this._trackPage(_this._options.pageTracking.getUrl(payload), _this._options.pageTracking.getTitle(payload));
});
};

Expand Down
51 changes: 27 additions & 24 deletions dist/system/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
System.register(['aurelia-dependency-injection', 'aurelia-event-aggregator', 'aurelia-logging', 'deepmerge'], function (_export, _context) {
"use strict";

var inject, EventAggregator, LogManager, deepmerge, _typeof, _dec, _class, defaultOptions, criteria, delegate, Analytics;
var inject, EventAggregator, LogManager, deepmerge, _typeof, _dec, _class, criteria, defaultOptions, delegate, Analytics;

function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
Expand All @@ -29,28 +29,6 @@ System.register(['aurelia-dependency-injection', 'aurelia-event-aggregator', 'au
} : function (obj) {
return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
};
defaultOptions = {
logging: {
enabled: true
},
pageTracking: {
enabled: false,
getTitle: function getTitle(payload) {
return payload.instruction.config.title;
}
},
clickTracking: {
enabled: false,
filter: function filter(element) {
return element instanceof HTMLElement && (element.nodeName.toLowerCase() === 'a' || element.nodeName.toLowerCase() === 'button');
}
},
exceptionTracking: {
enabled: true,
applicationName: undefined,
applicationVersion: undefined
}
};
criteria = {
isElement: function isElement(e) {
return e instanceof HTMLElement;
Expand All @@ -73,6 +51,31 @@ System.register(['aurelia-dependency-injection', 'aurelia-event-aggregator', 'au
return criteria.isOfType(e, 'button');
}
};
defaultOptions = {
logging: {
enabled: true
},
pageTracking: {
enabled: false,
getTitle: function getTitle(payload) {
return payload.instruction.config.title;
},
getUrl: function getUrl(payload) {
return payload.instruction.fragment;
}
},
clickTracking: {
enabled: false,
filter: function filter(element) {
return criteria.isAnchor(element) || criteria.isButton(element);
}
},
exceptionTracking: {
enabled: true,
applicationName: undefined,
applicationVersion: undefined
}
};

delegate = function delegate(criteria, listener) {
return function (evt) {
Expand Down Expand Up @@ -144,7 +147,7 @@ System.register(['aurelia-dependency-injection', 'aurelia-event-aggregator', 'au
}

this._eventAggregator.subscribe('router:navigation:success', function (payload) {
_this._trackPage(payload.instruction.fragment, _this._options.pageTracking.getTitle(payload));
_this._trackPage(_this._options.pageTracking.getUrl(payload), _this._options.pageTracking.getTitle(payload));
});
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "aurelia-google-analytics",
"version": "2.2.0",
"version": "2.3.0",
"description": "An Aurelia plugin that adds Google Analytics page tracking to your application.",
"keywords": [
"analytics",
Expand Down
Loading

0 comments on commit 8ee2ea2

Please sign in to comment.