analytical 3.0.9 → 3.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,5 @@
1
1
  = Analytical
2
+ {<img src="https://secure.travis-ci.org/jkrall/analytical.png" />}[http://travis-ci.org/jkrall/analytical]
2
3
 
3
4
  Gem for managing multiple analytics services in your rails app.
4
5
 
@@ -17,6 +18,7 @@ Service implementations include:
17
18
  * Google Website Optimizer
18
19
  * Performancing
19
20
  * Quantcast[http://www.quantcast.com]
21
+ * MixPanel[http://www.mixpanel.com]
20
22
 
21
23
  == Usage
22
24
 
@@ -31,6 +33,8 @@ Add a configuration file (config/analytical.yml) to declare your API keys, like
31
33
  key: UA-5555555-5
32
34
  clicky:
33
35
  key: 55555
36
+ development:
37
+ test:
34
38
 
35
39
  You can add different configurations for different environments.
36
40
 
@@ -73,7 +73,7 @@ module Analytical
73
73
  ]
74
74
 
75
75
  if options[:javascript_helpers]
76
- if ::Rails::VERSION =~ /^3\.1/ # Rails 3.1 lets us override views in engines
76
+ if ::Rails::VERSION::STRING.to_i >= 3.1 # Rails 3.1 lets us override views in engines
77
77
  js << options[:controller].send(:render_to_string, :partial=>'analytical_javascript') if options[:controller]
78
78
  else # All other rails
79
79
  _partial_path = Pathname.new(__FILE__).dirname.join('..', '..', 'app/views/application', '_analytical_javascript.html.erb').to_s
@@ -33,7 +33,7 @@ module Analytical
33
33
  </script>
34
34
  <script type="text/javascript">
35
35
  var ClickTaleSSL=1;
36
- if(typeof ClickTale=='function') ClickTale(#{@options[:project_id]},#{@options[:site_traffic]},"www");
36
+ if(typeof ClickTale=='function') ClickTale(#{@options[:project_id]},#{@options[:site_traffic]},\"#{@options[:www_param] || 'www'}\");
37
37
  </script>
38
38
  <!-- ClickTale end of Bottom part -->
39
39
  HTML
@@ -44,4 +44,4 @@ module Analytical
44
44
 
45
45
  end
46
46
  end
47
- end
47
+ end
@@ -40,6 +40,81 @@ module Analytical
40
40
  "_gaq.push(['_trackEvent', \"Event\", \"#{name}\"" + data_string + "]);"
41
41
  end
42
42
 
43
+ def custom_event(category, action, opt_label=nil, opt_value=nil)
44
+ args = [category, action, opt_label, opt_value].compact
45
+ "_gaq.push(" + [ "_trackEvent", *args].to_json + ");"
46
+ end
47
+
48
+
49
+ # http://code.google.com/apis/analytics/docs/tracking/gaTrackingCustomVariables.html
50
+ #
51
+ #_setCustomVar(index, name, value, opt_scope)
52
+ #
53
+ # index — The slot for the custom variable. Required. This is a number whose value can range from 1 - 5, inclusive.
54
+ #
55
+ # name — The name for the custom variable. Required. This is a string that identifies the custom variable and appears in the top-level Custom Variables report of the Analytics reports.
56
+ #
57
+ # value — The value for the custom variable. Required. This is a string that is paired with a name.
58
+ #
59
+ # opt_scope — The scope for the custom variable. Optional. As described above, the scope defines the level of user engagement with your site.
60
+ # It is a number whose possible values are 1 (visitor-level), 2 (session-level), or 3 (page-level).
61
+ # When left undefined, the custom variable scope defaults to page-level interaction.
62
+ def set(data)
63
+ if data.is_a?(Hash) && data.keys.any?
64
+ index = data[:index].to_i
65
+ name = data[:name ]
66
+ value = data[:value]
67
+ scope = data[:scope]
68
+ if (1..5).to_a.include?(index) && !name.nil? && !value.nil?
69
+ data = "#{index}, '#{name}', '#{value}'"
70
+ data += (1..3).to_a.include?(scope) ? ", #{scope}" : ""
71
+ return "_gaq.push(['_setCustomVar', #{ data }]);"
72
+ end
73
+ end
74
+ end
75
+
76
+ # http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addTrans
77
+ # String orderId Required. Internal unique order id number for this transaction.
78
+ # String affiliation Optional. Partner or store affiliation (undefined if absent).
79
+ # String total Required. Total dollar amount of the transaction.
80
+ # String tax Optional. Tax amount of the transaction.
81
+ # String shipping Optional. Shipping charge for the transaction.
82
+ # String city Optional. City to associate with transaction.
83
+ # String state Optional. State to associate with transaction.
84
+ # String country Optional. Country to associate with transaction.
85
+ def add_trans(order_id, affiliation=nil, total=nil, tax=nil, shipping=nil, city=nil, state=nil, country=nil)
86
+ data = []
87
+ data << "'#{order_id}'"
88
+ data << "'#{affiliation}'"
89
+ data << "'#{total}'"
90
+ data << "'#{tax}'"
91
+ data << "'#{shipping}'"
92
+ data << "'#{city}'"
93
+ data << "'#{state}'"
94
+ data << "'#{country}'"
95
+
96
+ "_gaq.push(['_addTrans', #{data.join(', ')}]);"
97
+ end
98
+
99
+ # http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._addItem
100
+ # String orderId Optional Order ID of the transaction to associate with item.
101
+ # String sku Required. Item's SKU code.
102
+ # String name Required. Product name. Required to see data in the product detail report.
103
+ # String category Optional. Product category.
104
+ # String price Required. Product price.
105
+ # String quantity Required. Purchase quantity.
106
+ def add_item(order_id, sku, name, category, price, quantity)
107
+ data = "'#{order_id}', '#{sku}', '#{name}', '#{category}', '#{price}', '#{quantity}'"
108
+ "_gaq.push(['_addItem', #{data}]);"
109
+ end
110
+
111
+ # http://code.google.com/apis/analytics/docs/gaJS/gaJSApiEcommerce.html#_gat.GA_Tracker_._trackTrans
112
+ # Sends both the transaction and item data to the Google Analytics server.
113
+ # This method should be used in conjunction with the add_item and add_trans methods.
114
+ def track_trans
115
+ "_gaq.push(['_trackTrans']);"
116
+ end
117
+
43
118
  end
44
119
  end
45
120
  end
@@ -28,7 +28,7 @@ module Analytical
28
28
 
29
29
  def track(event, properties = {})
30
30
  callback = properties.delete(:callback) || "function(){}"
31
- "mpmetrics.track('#{event}', #{properties.to_json}, #{callback});"
31
+ %(mpmetrics.track("#{event}", #{properties.to_json}, #{callback});)
32
32
  end
33
33
 
34
34
  # Used to set "Super Properties" - http://mixpanel.com/api/docs/guides/super-properties
@@ -37,11 +37,14 @@ module Analytical
37
37
  end
38
38
 
39
39
  def identify(id, *args)
40
- "mpmetrics.identify('#{id}');"
40
+ opts = args.first || {}
41
+ name = opts.is_a?(Hash) ? opts[:name] : ""
42
+ name_str = name.blank? ? "" : " mpmetrics.name_tag('#{name}');"
43
+ %(mpmetrics.identify('#{id}');#{name_str})
41
44
  end
42
45
 
43
46
  def event(name, attributes = {})
44
- "mpmetrics.track('#{name}', #{attributes.to_json});"
47
+ %(mpmetrics.track("#{name}", #{attributes.to_json});)
45
48
  end
46
49
 
47
50
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: analytical
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
8
  - 0
9
- - 9
10
- version: 3.0.9
9
+ - 11
10
+ version: 3.0.11
11
11
  platform: ruby
12
12
  authors:
13
13
  - Joshua Krall
@@ -22,7 +22,7 @@ autorequire:
22
22
  bindir: bin
23
23
  cert_chain: []
24
24
 
25
- date: 2011-10-01 00:00:00 -05:00
25
+ date: 2012-01-22 00:00:00 -06:00
26
26
  default_executable:
27
27
  dependencies:
28
28
  - !ruby/object:Gem::Dependency