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

Commit

Permalink
remove session command store
Browse files Browse the repository at this point in the history
  • Loading branch information
Duarte Henriques committed Oct 8, 2012
1 parent e8b7b45 commit 050e513
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 81 deletions.
15 changes: 0 additions & 15 deletions README.rdoc
Original file line number Diff line number Diff line change
Expand Up @@ -93,21 +93,6 @@ This can be useful for enabling the console logger optionally in your app, based

New modules should be fairly easy to add. Follow the structure that I've used in the Clicky, Google, and KISSMetrics modules... and you should be fine. All modules should include the Analytical::Base::Api module, so that they have some default behavior for methods that they don't support or need.

== Session-based command queues

By default, any Analytical commands that are queued in a controller that subsequently redirects won't be emitted to the client. This is because the redirect triggers a new request, and everything is cleared out at the beginning of each request.

However, if you would like to be able to queue commands between requests... there's a new option that supports this behavior:

analytical :modules=>[:console, :google], :use_session_store=>true

This will store the queued commands in the user session, clearing them out when they are emitted to the client, but allowing you to make calls like:

analytical.track 'something'

... in your controller. After a redirect, the corresponding track() call will be emitted in the next request made by the client.
NOTE: This is new and somewhat experimental, and could cause problems if you store large amounts of data in the session. (there is a 4k limit to session data)

== Javascript tracking/event commands

Sometimes you want to trigger an analytics track/event via javascript. Analytical now provides a solution for this by default. Appended to your <head> is a simple javascript object that will contain "instantaneous" versions of the tracking commands for each of your modules.
Expand Down
2 changes: 0 additions & 2 deletions lib/analytical.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,10 @@ def analytical
if options[:disable_if] && options[:disable_if].call(self)
options[:modules] = []
end
options[:session] = session if options[:use_session_store]
if analytical_is_robot?(request.user_agent)
options[:modules] = []
end
options[:modules] = options[:filter_modules].call(self, options[:modules]) if options[:filter_modules]
options[:javascript_helpers] ||= true if options[:javascript_helpers].nil?
Analytical::Api.new options
end
end
Expand Down
1 change: 0 additions & 1 deletion lib/analytical/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ def initialize(options={})
@options[:modules].each do |m|
module_options = @options.merge(@options[m] || {})
module_options.delete(:modules)
module_options[:session_store] = Analytical::SessionCommandStore.new(@options[:session], m) if @options[:session]
@modules[m] = get_mod(m).new(module_options)
end
@dummy_module = Analytical::Modules::DummyModule.new
Expand Down
2 changes: 1 addition & 1 deletion lib/analytical/modules/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def initialize(_options={})
@options = _options
@tracking_command_location = :body_prepend
@initialized = false
@command_store = @options[:session_store] || Analytical::CommandStore.new
@command_store = Analytical::CommandStore.new
end

def protocol
Expand Down
39 changes: 0 additions & 39 deletions lib/analytical/session_command_store.rb

This file was deleted.

12 changes: 0 additions & 12 deletions spec/analytical/api_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@
Analytical::Modules::Console.should_receive(:new).with(hash_including(:ssl=>true)).and_return(@console = mock('console'))
Analytical::Api.new :modules=>[:console], :ssl=>true
end
describe 'with a session option' do
before(:each) do
@session = {}
end
it 'should create a new SessionCommandStore for each module' do
Analytical::SessionCommandStore.should_receive(:new).with(@session, :console).and_return(@console_store = mock('console_store'))
Analytical::SessionCommandStore.should_receive(:new).with(@session, :google).and_return(@google_store = mock('google_store'))
Analytical::Modules::Console.should_receive(:new).with(:session_store=>@console_store, :session=>@session).and_return(mock('console'))
Analytical::Modules::Google.should_receive(:new).with(:session_store=>@google_store, :session=>@session).and_return(mock('google'))
Analytical::Api.new :modules=>[:console, :google], :session=>@session
end
end
end

describe 'with modules' do
Expand Down
11 changes: 0 additions & 11 deletions spec/analytical/modules/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,15 +124,4 @@ class BaseApiDummy
end
end
end

describe 'with a custom session_store' do
before(:each) do
@session = {}
@store = Analytical::SessionCommandStore.new @session, :some_module
end
it 'should use the session_store' do
@api = BaseApiDummy.new :session_store=>@store
@api.command_store.should == @store
end
end
end

0 comments on commit 050e513

Please sign in to comment.