diff --git a/README.rdoc b/README.rdoc index f7abf91..4c244bf 100644 --- a/README.rdoc +++ b/README.rdoc @@ -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 is a simple javascript object that will contain "instantaneous" versions of the tracking commands for each of your modules. diff --git a/lib/analytical.rb b/lib/analytical.rb index a8fdb21..f936300 100644 --- a/lib/analytical.rb +++ b/lib/analytical.rb @@ -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 diff --git a/lib/analytical/api.rb b/lib/analytical/api.rb index 3a51d08..23998a2 100644 --- a/lib/analytical/api.rb +++ b/lib/analytical/api.rb @@ -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 diff --git a/lib/analytical/modules/base.rb b/lib/analytical/modules/base.rb index f1999f4..5521bc0 100644 --- a/lib/analytical/modules/base.rb +++ b/lib/analytical/modules/base.rb @@ -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 diff --git a/lib/analytical/session_command_store.rb b/lib/analytical/session_command_store.rb deleted file mode 100644 index eaf6744..0000000 --- a/lib/analytical/session_command_store.rb +++ /dev/null @@ -1,39 +0,0 @@ -module Analytical - class SessionCommandStore - attr_reader :session, :module_key - - def initialize(session, module_key, initial_list=nil) - @session = session - @module_key = module_key - @session_key = ('analytical_'+module_key.to_s).to_sym - ensure_session_setup!(initial_list) - end - - def assign(v) - self.commands = v - end - - def commands - @session[@session_key] - end - def commands=(v) - @session[@session_key] = v - end - - def flush - self.commands = [] - end - - # Pass any array methods on to the internal array - def method_missing(method, *args, &block) - commands.send(method, *args, &block) - end - - private - - def ensure_session_setup!(initial_list=nil) - self.commands ||= (initial_list || []) - end - - end -end \ No newline at end of file diff --git a/spec/analytical/api_spec.rb b/spec/analytical/api_spec.rb index 16be675..df2158b 100644 --- a/spec/analytical/api_spec.rb +++ b/spec/analytical/api_spec.rb @@ -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 diff --git a/spec/analytical/modules/base_spec.rb b/spec/analytical/modules/base_spec.rb index 945c013..1ee9eeb 100644 --- a/spec/analytical/modules/base_spec.rb +++ b/spec/analytical/modules/base_spec.rb @@ -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