staccato 0.3.1 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1de9ca3518d24e4139fc2311de9ff15aa79d18a2
4
- data.tar.gz: bccdd80d9c617e2303ce2290ceddcd06828d888d
3
+ metadata.gz: 3b939560977963d95eee659f167c7a8d5815c1e3
4
+ data.tar.gz: 02ac189ce8e4bfae7e3748750a7472b28e8d64b8
5
5
  SHA512:
6
- metadata.gz: fde81fda9b06a81f5c45cea7ed60cfe51fd4942ff7f104227817e2424666654976ab6ad935efb27a114e5d2b6ae1840bc5cdde33bd451770a1e92cd15a5eba70
7
- data.tar.gz: 58e26c6147b312c0a8ed846d39b36edd416d6a8a7f20c60f6a5eb048c8a8417fe21a387924145da2e9e5560e088920444838edefb005c2209ceb4e669e59e9ef
6
+ metadata.gz: 1eb4c798052ac93e811cb1ff6996c0288e7246f9ad95d00deb01293452bad88a596570a34f120c1bd99eb0990f03697341073178955e67e1c03c3d77ceb30e8a
7
+ data.tar.gz: 3941be84e6f0fd6dc632ff0b19d1094e3fa199f18eb95d971f5e2f6e54bee58718ddf613064ccc86cb8e09d362d3fc68920849f737adc1a5613db65630a764f7
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## Staccato 0.4.0 ##
2
+
3
+ * UDP Adapter for use with Staccato::Proxy
4
+
5
+ *Tony Pitale <@tpitale>*
6
+
1
7
  ## Staccato 0.3.1 ##
2
8
 
3
9
  * Add customer dimensions and metrics to Product and ProductImpression measurements
@@ -0,0 +1,22 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality.
6
+
7
+ Examples of unacceptable behavior by participants include:
8
+
9
+ * The use of sexualized language or imagery
10
+ * Personal attacks
11
+ * Trolling or insulting/derogatory comments
12
+ * Public or private harassment
13
+ * Publishing other's private information, such as physical or electronic addresses, without explicit permission
14
+ * Other unethical or unprofessional conduct.
15
+
16
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team.
17
+
18
+ This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community.
19
+
20
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
21
+
22
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/)
data/README.md CHANGED
@@ -31,7 +31,7 @@ Or install it yourself as:
31
31
  tracker = Staccato.tracker('UA-XXXX-Y') # REQUIRED, your Google Analytics Tracking ID
32
32
  ```
33
33
 
34
- `#tracker` optionally takes a second param for the `client_id` value
34
+ `#tracker` optionally takes a second param for the `client_id` value.
35
35
  By default, the `client_id` is set to a random UUID with `SecureRandom.uuid`
36
36
 
37
37
  ### Track some data ###
@@ -136,7 +136,8 @@ Staccato::Hit::GLOBAL_OPTIONS.keys # =>
136
136
  :experiment_variant,
137
137
  :product_action,
138
138
  :product_action_list,
139
- :promotion_action]
139
+ :promotion_action,
140
+ :geographical_id]
140
141
  ```
141
142
 
142
143
  Boolean options like `anonymize_ip` will be converted from `true`/`false` into `1`/`0` as per the tracking API docs.
@@ -176,7 +177,7 @@ tracker.pageview(path: '/blog', start_session: true)
176
177
  tracker.pageview(path: '/blog', end_session: true)
177
178
  ```
178
179
 
179
- Other options are acceptable to start and end a session: `session_start`, `sessoin_end`, and `stop_session`.
180
+ Other options are acceptable to start and end a session: `session_start`, `session_end`, and `stop_session`.
180
181
 
181
182
  #### Content Experiment ####
182
183
 
@@ -466,6 +467,36 @@ tracker = Staccato.tracker('UA-XXXX-Y') do |c|
466
467
  end
467
468
  ```
468
469
 
470
+ ### Validation Adapter ###
471
+
472
+ The validation adapter sends hits to the debug endpoint, which responds with information about the validity of the hit.
473
+
474
+ ```ruby
475
+ tracker = Staccato.tracker('UA-XXXX-Y') do |c|
476
+ c.adapter = Staccato::Adapter::Validate.new
477
+ end
478
+ ```
479
+
480
+ By default, the staccato `default_adapter` is used to send validation hits, but a different adapter can be used (e.g. `Faraday` or `Net::HTTP`).
481
+
482
+ ```ruby
483
+ tracker = Staccato.tracker('UA-XXXX-Y') do |c|
484
+ c.adapter = Staccato::Adapter::Validate.new(Staccato::Adapter::HTTP)
485
+ end
486
+ ```
487
+
488
+ ### UDP Adapter for Staccato::Proxy ###
489
+
490
+ If you're using [Staccato::Proxy](https://github.com/tpitale/staccato-proxy), you can point Staccato at it using the UDP adapter.
491
+
492
+ ```ruby
493
+ tracker = Staccato.tracker('UA-XXXX-Y') do |c|
494
+ c.adapter = Staccato::Adapter::UDP.new(URI('udp://127.0.0.1:3003'))
495
+ end
496
+ ```
497
+
498
+ Be sure to set the ip or host and port to wherever you have configured Staccato::Proxy to run.
499
+
469
500
  ## Contributing ##
470
501
 
471
502
  1. Fork it
data/lib/staccato.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'ostruct'
2
2
  require 'forwardable'
3
3
  require 'securerandom'
4
+ require 'uri'
4
5
 
5
6
  require "staccato/version"
6
7
 
@@ -38,6 +39,12 @@ module Staccato
38
39
  url = (ssl ? 'https://ssl' : 'http://www') + '.google-analytics.com/collect'
39
40
  URI(url)
40
41
  end
42
+
43
+ # The default adapter to use for sending hits
44
+ def self.default_adapter
45
+ require 'staccato/adapter/net_http'
46
+ Staccato::Adapter::Net::HTTP
47
+ end
41
48
  end
42
49
 
43
50
  require 'staccato/boolean_helpers'
@@ -0,0 +1,23 @@
1
+ require 'uri'
2
+ require 'socket'
3
+
4
+ module Staccato
5
+ module Adapter
6
+ class UDP
7
+ # Takes a URI with host/port
8
+ # e.g.: URI('udp://127.0.0.1:3001')
9
+ def initialize(uri)
10
+ @host = uri.host
11
+ @port = uri.port
12
+
13
+ @socket = UDPSocket.new
14
+ end
15
+
16
+ def post(params)
17
+ body = URI.encode_www_form(params)
18
+
19
+ @socket.send(body, 0, @host, @port)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,13 @@
1
+ module Staccato
2
+ module Adapter
3
+ class Validate
4
+ def initialize(adapter = Staccato.default_adapter)
5
+ @adapter = adapter.new URI('https://www.google-analytics.com/debug/collect')
6
+ end
7
+
8
+ def post(params)
9
+ @adapter.post(params).body
10
+ end
11
+ end
12
+ end
13
+ end
data/lib/staccato/hit.rb CHANGED
@@ -71,7 +71,10 @@ module Staccato
71
71
  product_action_list: 'pal',
72
72
 
73
73
  # Promotion
74
- promotion_action: 'promoa'
74
+ promotion_action: 'promoa',
75
+
76
+ # Location
77
+ geographical_id: 'geoid'
75
78
  }.freeze
76
79
 
77
80
  # Fields which should be converted to boolean for google
@@ -118,16 +118,30 @@ module Staccato
118
118
  Staccato::Timing.new(self, options).track!(&block)
119
119
  end
120
120
 
121
+ # Build an ecommerce transaction
122
+ #
123
+ # @return [Transaction]
124
+ def build_transaction(options = {})
125
+ Staccato::Transaction.new(self, options)
126
+ end
127
+
121
128
  # Track an ecommerce transaction
122
129
  # @return [<Net::HTTPOK] the GA `/collect` endpoint always returns a 200
123
130
  def transaction(options = {})
124
- Staccato::Transaction.new(self, options).track!
131
+ build_transaction(options).track!
132
+ end
133
+
134
+ # Build an item in an ecommerce transaction
135
+ #
136
+ # @return [TransactionItem]
137
+ def build_transaction_item(options = {})
138
+ Staccato::TransactionItem.new(self, options)
125
139
  end
126
140
 
127
141
  # Track an item in an ecommerce transaction
128
142
  # @return [<Net::HTTPOK] the GA `/collect` endpoint always returns a 200
129
143
  def transaction_item(options = {})
130
- Staccato::TransactionItem.new(self, options).track!
144
+ build_transaction_item(options).track!
131
145
  end
132
146
 
133
147
  # post the hit to GA collection endpoint
@@ -144,11 +158,7 @@ module Staccato
144
158
  end
145
159
 
146
160
  def adapter
147
- @adapter ||= begin
148
- require 'staccato/adapter/net_http'
149
-
150
- Staccato::Adapter::Net::HTTP.new(Staccato.ga_collection_uri)
151
- end
161
+ @adapter ||= Staccato.default_adapter.new(Staccato.ga_collection_uri)
152
162
  end
153
163
  end
154
164
 
@@ -1,4 +1,4 @@
1
1
  module Staccato
2
2
  # The current Staccato VERSION
3
- VERSION = "0.3.1"
3
+ VERSION = "0.4.0"
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: staccato
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tony Pitale
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-18 00:00:00.000000000 Z
11
+ date: 2015-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,6 +106,7 @@ files:
106
106
  - ".ruby-version"
107
107
  - ".travis.yml"
108
108
  - CHANGELOG.md
109
+ - CODE_OF_CONDUCT.md
109
110
  - Gemfile
110
111
  - LICENSE.txt
111
112
  - README.md
@@ -114,6 +115,8 @@ files:
114
115
  - lib/staccato/adapter/faraday.rb
115
116
  - lib/staccato/adapter/http.rb
116
117
  - lib/staccato/adapter/net_http.rb
118
+ - lib/staccato/adapter/udp.rb
119
+ - lib/staccato/adapter/validate.rb
117
120
  - lib/staccato/boolean_helpers.rb
118
121
  - lib/staccato/event.rb
119
122
  - lib/staccato/exception.rb