From f4045568eca58e98a3f606927b4b2a4126b75e13 Mon Sep 17 00:00:00 2001 From: thomaswelton Date: Mon, 27 Jan 2014 11:55:17 +0000 Subject: [PATCH] Only create a tracker and fire a page view is config was passed --- dist/GoogleAnalytics.js | 21 +++++++++------------ src/GoogleAnalytics.litcoffee | 18 +++++++----------- 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/dist/GoogleAnalytics.js b/dist/GoogleAnalytics.js index 1787e8a..1b3428f 100644 --- a/dist/GoogleAnalytics.js +++ b/dist/GoogleAnalytics.js @@ -40,19 +40,16 @@ this.__ga = __bind(this.__ga, this); this.ready = __bind(this.ready, this); GoogleAnalytics.__super__.constructor.call(this); - if (!(this.config.fields && this.config.fields.name)) { - console.log('GA: Created tracker for ' + this.config.id); - } else { - console.log('GA: Created ' + this.config.fields.name + ' for ' + this.config.id); - } - this.create(this.config.id, this.config.fields); - if (this.config.expId) { - this.set('expId', this.config.expId); - } - if (this.config.expVar) { - this.set('expVar', this.config.expVar); + if (this.config.id != null) { + this.create(this.config.id, this.config.fields); + if (this.config.expId) { + this.set('expId', this.config.expId); + } + if (this.config.expVar) { + this.set('expVar', this.config.expVar); + } + this.view(); } - this.view(); if (!this.config.ga) { require(['ga'], function(ga) { _this.ga = ga; diff --git a/src/GoogleAnalytics.litcoffee b/src/GoogleAnalytics.litcoffee index bf61803..c9b446d 100644 --- a/src/GoogleAnalytics.litcoffee +++ b/src/GoogleAnalytics.litcoffee @@ -32,22 +32,18 @@ for holding an event queue whilst Google Analytics downloads. super() - unless @config.fields and @config.fields.name - console.log 'GA: Created tracker for ' + @config.id - else - console.log 'GA: Created ' + @config.fields.name + ' for ' + @config.id - - @create @config.id, @config.fields + if @config.id? + @create @config.id, @config.fields Set the chosen variation for the Visitor for [experiments](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#experiments). - if @config.expId # The id of the experiment the user has been exposed to. - @set 'expId', @config.expId - if @config.expVar # The index of the variation shown to the visitor. - @set 'expVar', @config.expVar + if @config.expId # The id of the experiment the user has been exposed to. + @set 'expId', @config.expId + if @config.expVar # The index of the variation shown to the visitor. + @set 'expVar', @config.expVar - @view() + @view() unless @config.ga # Load the actual Google Analytics library