Skip to content
This repository has been archived by the owner on Oct 17, 2020. It is now read-only.

Commit

Permalink
Only create a tracker and fire a page view is config was passed
Browse files Browse the repository at this point in the history
  • Loading branch information
thomaswelton committed Jan 27, 2014
1 parent accd796 commit f404556
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 23 deletions.
21 changes: 9 additions & 12 deletions dist/GoogleAnalytics.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 7 additions & 11 deletions src/GoogleAnalytics.litcoffee
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

2 comments on commit f404556

@thomaswelton
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@metalshark I found this to be useful on a new site that I'm working on where I need many trackers.
I create a new file called foo.js and pass in all my tracker IDs to that. Then from within foo.js load in google and create a new tracker for each.

@metalshark
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thomaswelton nice one two fronts. 1) loading of the initial tracker is optional. 2) you are getting benefits from it on projects

Please sign in to comment.