From 37fca15bc86bb59a4ac74575b2a25baa004881a9 Mon Sep 17 00:00:00 2001 From: Jeff Avallone Date: Thu, 1 Jan 2015 11:56:36 -0500 Subject: [PATCH] Removing _trackEvent method It has become an unnecessary abstraction around _gaq.push --- spec/regexper_spec.js | 23 +++++------------------ src/js/regexper.js | 18 +++++++----------- 2 files changed, 12 insertions(+), 29 deletions(-) diff --git a/spec/regexper_spec.js b/spec/regexper_spec.js index a4a05fc..1e29fca 100644 --- a/spec/regexper_spec.js +++ b/spec/regexper_spec.js @@ -239,19 +239,6 @@ describe('regexper.js', function() { }); - describe('#_trackEvent', function() { - - beforeEach(function() { - spyOn(window._gaq, 'push'); - }); - - it('adds a _trackEvent call to gaq', function() { - this.regexper._trackEvent('category', 'action'); - expect(window._gaq.push).toHaveBeenCalledWith(['_trackEvent', 'category', 'action']); - }); - - }); - describe('#showExpression', function() { beforeEach(function() { @@ -365,7 +352,7 @@ describe('regexper.js', function() { spyOn(Parser.prototype, 'render').and.returnValue(this.renderPromise.promise); spyOn(Parser.prototype, 'cancel'); - spyOn(this.regexper, '_trackEvent'); + spyOn(window._gaq, 'push'); spyOn(this.regexper, 'updateLinks'); spyOn(this.regexper, 'displayWarnings'); }); @@ -377,7 +364,7 @@ describe('regexper.js', function() { it('tracks the beginning of the render', function() { this.regexper.renderRegexp('example expression'); - expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'start'); + expect(window._gaq.push).toHaveBeenCalledWith(['_trackEvent', 'visualization', 'start']); }); it('keeps a copy of the running property parser', function() { @@ -417,7 +404,7 @@ describe('regexper.js', function() { it('tracks the parse error', function(done) { this.regexper.renderRegexp('example expression') .then(() => { - expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'parse error'); + expect(window._gaq.push).toHaveBeenCalledWith(['_trackEvent', 'visualization', 'parse error']); }, fail) .finally(done) .done(); @@ -482,7 +469,7 @@ describe('regexper.js', function() { it('tracks the complete render', function(done) { this.regexper.renderRegexp('example expression') .then(() => { - expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'complete'); + expect(window._gaq.push).toHaveBeenCalledWith(['_trackEvent', 'visualization', 'complete']); }, fail) .finally(done) .done(); @@ -519,7 +506,7 @@ describe('regexper.js', function() { it('tracks the cancelled render', function(done) { this.regexper.renderRegexp('example expression') .then(() => { - expect(this.regexper._trackEvent).toHaveBeenCalledWith('visualization', 'cancelled'); + expect(window._gaq.push).toHaveBeenCalledWith(['_trackEvent', 'visualization', 'cancelled']); }, fail) .finally(done) .done(); diff --git a/src/js/regexper.js b/src/js/regexper.js index 9843312..13a2908 100644 --- a/src/js/regexper.js +++ b/src/js/regexper.js @@ -72,10 +72,6 @@ export default class Regexper { return decodeURIComponent(location.hash.slice(1)); } - _trackEvent(category, action) { - window._gaq.push(['_trackEvent', category, action]); - } - set state(state) { this.root.className = state; } @@ -144,7 +140,7 @@ export default class Regexper { } this.state = 'is-loading'; - this._trackEvent('visualization', 'start'); + window._gaq.push(['_trackEvent', 'visualization', 'start']); this.running = new Parser(this.svgContainer); @@ -161,17 +157,17 @@ export default class Regexper { }) .invoke('render') .then(() => { - this.state = 'has-results'; - this.updateLinks(); - this.displayWarnings(this.running.warnings); - this._trackEvent('visualization', 'complete'); + this.state = 'has-results'; + this.updateLinks(); + this.displayWarnings(this.running.warnings); + window._gaq.push(['_trackEvent', 'visualization', 'complete']); }) .then(null, message => { if (message === 'Render cancelled') { - this._trackEvent('visualization', 'cancelled'); + window._gaq.push(['_trackEvent', 'visualization', 'cancelled']); this.state = ''; } else if (parseError) { - this._trackEvent('visualization', 'parse error'); + window._gaq.push(['_trackEvent', 'visualization', 'parse error']); } else { throw message; }