gooa 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in Gooa.gemspec
4
+ gemspec
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gooa/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gooa"
8
+ spec.version = Gooa::VERSION
9
+ spec.authors = ["Steven Yang"]
10
+ spec.email = ["yangchenyun@gmail.com"]
11
+ spec.description = %q{Implementation of server-side google analytics tracking.}
12
+ spec.summary = %q{Implementation of server-side google analytics tracking with measurement protocl. Support page tracking, event tracking, e-commerce tracking, social tracking, exception tracking and app tracking}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'faraday', ['>= 0.8', '< 0.10']
22
+ spec.add_dependency 'faraday_middleware', ['>= 0.8', '< 0.10']
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.3"
25
+ spec.add_development_dependency "rake"
26
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Steven Yang
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,27 @@
1
+ # Gooa
2
+
3
+ Implementation of server-side google analytics tracking.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'Gooa'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install Gooa
18
+
19
+ ## Usage
20
+
21
+ ## Contributing
22
+
23
+ 1. Fork it
24
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
25
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
26
+ 4. Push to the branch (`git push origin my-new-feature`)
27
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,2 @@
1
+ require "gooa/version"
2
+ require 'gooa/client'
@@ -0,0 +1,122 @@
1
+ require 'faraday'
2
+ require 'faraday/middleware'
3
+
4
+ module Gooa
5
+ class Client
6
+ class << self
7
+ def page_track(ga_client_id, url = nil, host = nil, path = nil, title = nil, desc = nil)
8
+ raise ArgumentError, 'no valid url or host/path is set' unless url || (host && path)
9
+
10
+ options = {
11
+ cid: ga_client_id,
12
+ dl: url, # Document location URL
13
+ dh: host, # Document Host Name
14
+ dp: path, # Document Path
15
+ dt: title, # Document Title
16
+ cd: desc # Content Description
17
+ }
18
+
19
+ add_action(options, 'pageview')
20
+ send_request(options)
21
+ end
22
+
23
+ def event_track(ga_client_id, category, action, label = nil, value = nil)
24
+ options = {
25
+ cid: ga_client_id,
26
+ ec: category, # Event Category
27
+ ea: action, # Event Action
28
+ el: label, # Event Label
29
+ ev: value # Event Value
30
+ }
31
+
32
+ add_action(options, 'event')
33
+ send_request(options)
34
+ end
35
+
36
+ def add_item_track(ga_client_id, transaction_id, name, price = nil, quantity = nil, sku = nil, category = nil, currency = nil)
37
+ options = {
38
+ cid: ga_client_id,
39
+ ti: transaction_id, # Transaction ID. Required.
40
+ in: name, # Item name. Required.
41
+ ip: price, # Item price.
42
+ iq: quantity, # Item quantity.
43
+ ic: sku, # Item code / SKU.
44
+ iv: category, # Item variation / category.
45
+ cu: currency # Currency code.
46
+ }
47
+
48
+ add_action(options, 'item')
49
+ send_request(options)
50
+ end
51
+
52
+ def transaction_track(ga_client_id, transaction_id, affiliation = nil, revenue = nil, shipping = nil, tax = nil, currency = nil)
53
+ options = {
54
+ cid: ga_client_id,
55
+ ti: transaction_id, # Transaction ID. Required.
56
+ ta: affiliation, # Transaction Affiliation
57
+ tr: revenue, # Transaction Revenue
58
+ ts: shipping, # Transaction Shipping
59
+ tt: tax, # ransaction Tax
60
+ cu: currency # Currency code.
61
+ }
62
+
63
+ add_action(options, 'transaction')
64
+ send_request(options)
65
+ end
66
+
67
+ def social_track(ga_client_id, action, network, target)
68
+ options = {
69
+ cid: ga_client_id,
70
+ sa: action, # Social Action. Required.
71
+ sn: network, # Social Network. Required.
72
+ st: target # Social Target. Required.
73
+ }
74
+
75
+ add_action(options, 'social')
76
+ send_request(options)
77
+ end
78
+
79
+ private
80
+
81
+ def send_request(options)
82
+ default_options = {
83
+ v: 1, # Version.
84
+ tid: Rails.env == 'production' ? ENV['GA_TRACKING_ID'] : ENV['GA_TRACKING_ID_DEV'] # Tracking ID / Web property / Property ID.
85
+ }
86
+
87
+ action = default_options.merge(options.reject {|k, v| v.nil? })
88
+
89
+ check_property_id(action)
90
+
91
+ conn = Faraday.new(url: 'http://www.google-analytics.com') do |faraday|
92
+ faraday.request :url_encoded # form-encode POST params
93
+ faraday.response :logger if Rails.env == 'development' # log requests to STDOUT
94
+ faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
95
+ end
96
+
97
+ res = conn.post do |req|
98
+ req.options[:timeout] = 8
99
+ req.options[:open_timeout] = 3
100
+ req.url('/collect')
101
+ req.body = action
102
+ end
103
+
104
+ status = res.status
105
+ error = res.body["error"]
106
+
107
+ raise Faraday::Error, res unless res.success?
108
+ end
109
+
110
+ def add_action(options, action)
111
+ unless action.in? ['pageview', 'event', 'item', 'transaction', 'social']
112
+ raise ArgumentError, 'invalid action name'
113
+ end
114
+ options[:t] = action
115
+ end
116
+
117
+ def check_property_id(action)
118
+ fail 'must provide google analytics property id' if action[:tid].nil?
119
+ end
120
+ end
121
+ end
122
+ end
@@ -0,0 +1,3 @@
1
+ module Gooa
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gooa
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Steven Yang
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-05-31 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: faraday
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0.8'
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: '0.10'
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0.8'
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: '0.10'
36
+ - !ruby/object:Gem::Dependency
37
+ name: faraday_middleware
38
+ requirement: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0.8'
44
+ - - <
45
+ - !ruby/object:Gem::Version
46
+ version: '0.10'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ - - <
56
+ - !ruby/object:Gem::Version
57
+ version: '0.10'
58
+ - !ruby/object:Gem::Dependency
59
+ name: bundler
60
+ requirement: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ~>
64
+ - !ruby/object:Gem::Version
65
+ version: '1.3'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ~>
72
+ - !ruby/object:Gem::Version
73
+ version: '1.3'
74
+ - !ruby/object:Gem::Dependency
75
+ name: rake
76
+ requirement: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ! '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ none: false
86
+ requirements:
87
+ - - ! '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ description: Implementation of server-side google analytics tracking.
91
+ email:
92
+ - yangchenyun@gmail.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - .gitignore
98
+ - Gemfile
99
+ - Gooa.gemspec
100
+ - LICENSE.txt
101
+ - README.md
102
+ - Rakefile
103
+ - lib/Gooa.rb
104
+ - lib/Gooa/client.rb
105
+ - lib/Gooa/version.rb
106
+ homepage: ''
107
+ licenses:
108
+ - MIT
109
+ post_install_message:
110
+ rdoc_options: []
111
+ require_paths:
112
+ - lib
113
+ required_ruby_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ none: false
121
+ requirements:
122
+ - - ! '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubyforge_project:
127
+ rubygems_version: 1.8.23
128
+ signing_key:
129
+ specification_version: 3
130
+ summary: Implementation of server-side google analytics tracking with measurement
131
+ protocl. Support page tracking, event tracking, e-commerce tracking, social tracking,
132
+ exception tracking and app tracking
133
+ test_files: []
134
+ has_rdoc: