Adding code to track visualization lifecycle events
This commit is contained in:
parent
c64e48946e
commit
7de0a6490a
@ -258,6 +258,15 @@ describe('regexper.js', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('#trackEvent', function() {
|
||||||
|
|
||||||
|
it('adds a _trackEvent call to gaq', function() {
|
||||||
|
this.regexper._trackEvent('category', 'action');
|
||||||
|
expect(this.regexper.gaq).toContain(['_trackEvent', 'category', 'action']);
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
describe('#showExpression', function() {
|
describe('#showExpression', function() {
|
||||||
|
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
|
@ -15,6 +15,8 @@ export default class Regexper {
|
|||||||
|
|
||||||
this.padding = 10;
|
this.padding = 10;
|
||||||
this.snap = Snap(this.svg);
|
this.snap = Snap(this.svg);
|
||||||
|
|
||||||
|
this.gaq = (typeof window._gaq === 'undefined') ? [] : window._gaq;
|
||||||
}
|
}
|
||||||
|
|
||||||
keypressListener(event) {
|
keypressListener(event) {
|
||||||
@ -80,6 +82,10 @@ export default class Regexper {
|
|||||||
return decodeURIComponent(location.hash.slice(1));
|
return decodeURIComponent(location.hash.slice(1));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_trackEvent(category, action) {
|
||||||
|
this.gaq.push(['_trackEvent', category, action]);
|
||||||
|
}
|
||||||
|
|
||||||
set state(state) {
|
set state(state) {
|
||||||
this.root.className = state;
|
this.root.className = state;
|
||||||
}
|
}
|
||||||
@ -94,15 +100,19 @@ export default class Regexper {
|
|||||||
|
|
||||||
if (expression !== '') {
|
if (expression !== '') {
|
||||||
this.state = 'is-loading';
|
this.state = 'is-loading';
|
||||||
|
this._trackEvent('visualization', 'start');
|
||||||
|
|
||||||
this.renderRegexp(expression)
|
this.renderRegexp(expression)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
this.state = 'has-results';
|
this.state = 'has-results';
|
||||||
this.updateLinks();
|
this.updateLinks();
|
||||||
}, (message) => {
|
this._trackEvent('visualization', 'complete');
|
||||||
|
})
|
||||||
|
.then(null, message => {
|
||||||
if (message === 'Render cancelled') {
|
if (message === 'Render cancelled') {
|
||||||
this.state = '';
|
this.state = '';
|
||||||
} else {
|
} else {
|
||||||
|
this._trackEvent('visualization', 'exception');
|
||||||
throw message;
|
throw message;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@ -144,6 +154,8 @@ export default class Regexper {
|
|||||||
this.error.innerHTML = '';
|
this.error.innerHTML = '';
|
||||||
this.error.appendChild(document.createTextNode(message));
|
this.error.appendChild(document.createTextNode(message));
|
||||||
|
|
||||||
|
this._trackEvent('visualization', 'parse error');
|
||||||
|
|
||||||
throw message;
|
throw message;
|
||||||
})
|
})
|
||||||
.invoke('render', this.snap.group())
|
.invoke('render', this.snap.group())
|
||||||
|
Loading…
Reference in New Issue
Block a user