analytical 2.2.0 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,7 +55,7 @@ You can sprinkle the track() and event() tracking methods throughout your views
55
55
  analytical.track '/a/really/nice/url'
56
56
  analytical.event 'Some Awesome Event', :with=>:data
57
57
 
58
- By default, Analytical will be disabled in development mode... and it will enable the Console module only. To change this behavior, you can pass a Proc/lambda to the :disable_if option, as well as specify the :development_modules that you want to use:
58
+ By default, Analytical will be disabled in all environments except 'production'... and it will enable the Console module only. To change this behavior, you can pass a Proc/lambda to the :disable_if option, as well as specify the :development_modules that you want to use:
59
59
 
60
60
  analytical :modules=>[:google], :development_modules=>[], :disable_if=>lambda{ |controller| controller.i_can_haz_tracking? }
61
61
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.2.0
1
+ 2.3.0
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{analytical}
8
- s.version = "2.2.0"
8
+ s.version = "2.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joshua Krall", "Nathan Phelps", "Adam Anderson"]
12
- s.date = %q{2010-09-30}
12
+ s.date = %q{2011-01-12}
13
13
  s.description = %q{Gem for managing multiple analytics services in your rails app.}
14
14
  s.email = %q{josh@transfs.com}
15
15
  s.extra_rdoc_files = [
@@ -89,6 +89,7 @@ Gem::Specification.new do |s|
89
89
  "lib/analytical/modules/google.rb",
90
90
  "lib/analytical/modules/hubspot.rb",
91
91
  "lib/analytical/modules/kiss_metrics.rb",
92
+ "lib/analytical/modules/mixpanel.rb",
92
93
  "lib/analytical/modules/optimizely.rb",
93
94
  "lib/analytical/session_command_store.rb",
94
95
  "rails/init.rb",
@@ -102,6 +103,7 @@ Gem::Specification.new do |s|
102
103
  "spec/analytical/modules/comscore_spec.rb",
103
104
  "spec/analytical/modules/google_spec.rb",
104
105
  "spec/analytical/modules/kiss_metrics_spec.rb",
106
+ "spec/analytical/modules/mixpanel_spec.rb",
105
107
  "spec/analytical/modules/optimizely_spec.rb",
106
108
  "spec/analytical/session_command_store_spec.rb",
107
109
  "spec/analytical_spec.rb",
@@ -125,6 +127,7 @@ Gem::Specification.new do |s|
125
127
  "spec/analytical/modules/comscore_spec.rb",
126
128
  "spec/analytical/modules/google_spec.rb",
127
129
  "spec/analytical/modules/kiss_metrics_spec.rb",
130
+ "spec/analytical/modules/mixpanel_spec.rb",
128
131
  "spec/analytical/modules/optimizely_spec.rb",
129
132
  "spec/analytical/session_command_store_spec.rb",
130
133
  "spec/analytical_spec.rb",
@@ -0,0 +1,51 @@
1
+ module Analytical
2
+ module Modules
3
+ class Mixpanel
4
+ include Analytical::Modules::Base
5
+
6
+ def initialize(options={})
7
+ super
8
+ @tracking_command_location = :body_append
9
+ end
10
+
11
+ def init_javascript(location)
12
+ init_location(location) do
13
+ js = <<-HTML
14
+ <!-- Analytical Init: Mixpanel -->
15
+ <script type="text/javascript" src="http://api.mixpanel.com/site_media/js/api/mixpanel.js"></script>
16
+ <script type="text/javascript">
17
+ try {
18
+ var mix = new MixpanelLib('#{options[:key]}');
19
+ } catch(err) {
20
+ null_fn = function () {};
21
+ var mpmetrics = { track: null_fn, track_funnel: null_fn, register: null_fn, register_once: null_fn };
22
+ }
23
+ </script>
24
+ HTML
25
+ js
26
+ end
27
+ end
28
+
29
+ def track(event, properties = {})
30
+ callback = properties.delete(:callback) || "function(){}"
31
+ "mpmetrics.track('#{event}', #{properties.to_json}, #{callback});"
32
+ end
33
+
34
+ def identify(id, *args)
35
+ "mpmetrics.identify('#{id}');"
36
+ end
37
+
38
+ def event(funnel, *args)
39
+ data = args.last || {}
40
+ step = data.delete(:step)
41
+ goal = data.delete(:goal)
42
+ callback = data.delete(:callback) || "function(){}"
43
+ return "/* API Error: Funnel is not set for 'mpmetrics.track_funnel(funnel:string, step:int, goal:string, properties:object, callback:function); */" if funnel.blank?
44
+ return "/* API Error: Step is not set for 'mpmetrics.track_funnel(#{funnel}, ...); */" unless step && step.to_i >= 0
45
+ return "/* API Error: Goal is not set for 'mpmetrics.track_funnel(#{funnel}, #{step}, ...); */" if goal.blank?
46
+ "mpmetrics.track_funnel('#{funnel}', '#{step}', '#{goal}', #{data.to_json}, #{callback});"
47
+ end
48
+
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,71 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe "Analytical::Modules::Mixpanel" do
4
+ before(:each) do
5
+ @parent = mock('api', :options=>{:google=>{:js_url_key=>'abc'}})
6
+ end
7
+ describe 'on initialize' do
8
+ it 'should set the command_location' do
9
+ a = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abc'
10
+ a.tracking_command_location.should == :body_append
11
+ end
12
+ it 'should set the options' do
13
+ a = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abc'
14
+ a.options.should == {:js_url_key=>'abc', :parent=>@parent}
15
+ end
16
+ end
17
+ describe '#identify' do
18
+ it 'should return a js string' do
19
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
20
+ @api.identify('id', {:email=>'test@test.com'}).should == "mpmetrics.identify('id');"
21
+ end
22
+ end
23
+ describe '#track' do
24
+ it 'should return the tracking javascript' do
25
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :key=>'abcdef'
26
+ @api.track('pagename', {:some=>'data'}).should == "mpmetrics.track('pagename', {\"some\":\"data\"}, function(){};);"
27
+ end
28
+ it 'should return the tracking javascript with a callback' do
29
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :key=>'abcdef'
30
+ @api.track('pagename', {:some=>'data', :callback=>'fubar'}).should == "mpmetrics.track('pagename', {\"some\":\"data\"}, fubar);"
31
+ end
32
+ end
33
+ describe '#event' do
34
+ it 'should return a js string' do
35
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
36
+ @api.event('My Funnel', {:step=>5, :goal=>'thegoal'}).should == "mpmetrics.track_funnel('My Funnel', '5', 'thegoal', {}, function(){};);"
37
+ end
38
+ describe 'without the proper data' do
39
+ it 'should return an error string with blank funnel' do
40
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
41
+ @api.event('', {:step=>5, :goal=>'thegoal'}).should =~ /Funnel is not set/
42
+ end
43
+ it 'should return an error string with blank step' do
44
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
45
+ @api.event('My Funnel', {:goal=>'thegoal'}).should =~ /Step is not set/
46
+ end
47
+ it 'should return an error string with step < 0' do
48
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
49
+ @api.event('My Funnel', {:step=>-1, :goal=>'thegoal'}).should =~ /Step is not set/
50
+ end
51
+ it 'should return an error string with blank goal' do
52
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
53
+ @api.event('My Funnel', {:step=>5}).should =~ /Goal is not set/
54
+ end
55
+ end
56
+ it 'should return a js string' do
57
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
58
+ @api.event('My Funnel', {:step=>5, :goal=>'thegoal', :callback=>'thecallback', :other=>'data'}).should == "mpmetrics.track_funnel('My Funnel', '5', 'thegoal', {\"other\":\"data\"}, thecallback);"
59
+ end
60
+ end
61
+ describe '#init_javascript' do
62
+ it 'should return the init javascript' do
63
+ @api = Analytical::Modules::Mixpanel.new :parent=>@parent, :js_url_key=>'abcdef'
64
+ @api.init_javascript(:head_prepend).should == ''
65
+ @api.init_javascript(:head_append).should == ''
66
+ @api.init_javascript(:body_prepend).should == ''
67
+ @api.init_javascript(:body_append).should =~ /api\.mixpanel\.com\/site_media\/js\/api\/mixpanel\.js/
68
+ @api.init_javascript(:body_append).should =~ /new MixpanelLib\('.*'\)/
69
+ end
70
+ end
71
+ end
@@ -8,11 +8,6 @@ require 'spec'
8
8
  require 'spec/autorun'
9
9
 
10
10
  require 'analytical'
11
- require 'analytical/api'
12
- require 'analytical/base'
13
- require 'analytical/console'
14
- require 'analytical/google'
15
- require 'analytical/clicky'
16
11
 
17
12
  Spec::Runner.configure do |config|
18
13
  end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 2
7
- - 2
7
+ - 3
8
8
  - 0
9
- version: 2.2.0
9
+ version: 2.3.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Joshua Krall
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-09-30 00:00:00 -05:00
19
+ date: 2011-01-12 00:00:00 -06:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -127,6 +127,7 @@ files:
127
127
  - lib/analytical/modules/google.rb
128
128
  - lib/analytical/modules/hubspot.rb
129
129
  - lib/analytical/modules/kiss_metrics.rb
130
+ - lib/analytical/modules/mixpanel.rb
130
131
  - lib/analytical/modules/optimizely.rb
131
132
  - lib/analytical/session_command_store.rb
132
133
  - rails/init.rb
@@ -140,6 +141,7 @@ files:
140
141
  - spec/analytical/modules/comscore_spec.rb
141
142
  - spec/analytical/modules/google_spec.rb
142
143
  - spec/analytical/modules/kiss_metrics_spec.rb
144
+ - spec/analytical/modules/mixpanel_spec.rb
143
145
  - spec/analytical/modules/optimizely_spec.rb
144
146
  - spec/analytical/session_command_store_spec.rb
145
147
  - spec/analytical_spec.rb
@@ -187,6 +189,7 @@ test_files:
187
189
  - spec/analytical/modules/comscore_spec.rb
188
190
  - spec/analytical/modules/google_spec.rb
189
191
  - spec/analytical/modules/kiss_metrics_spec.rb
192
+ - spec/analytical/modules/mixpanel_spec.rb
190
193
  - spec/analytical/modules/optimizely_spec.rb
191
194
  - spec/analytical/session_command_store_spec.rb
192
195
  - spec/analytical_spec.rb