ga_collector_pusher 0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 142c35f3521dfa310afc55ddf9bda33e5a5556bd
4
+ data.tar.gz: 6a67f795bb2d50963bf6d01a9194658479c8af8c
5
+ SHA512:
6
+ metadata.gz: b13056ded8faf094b28a3cb2e7f600cefcc1140a817cd1d26d4c6bbb885c1388222bda5a551c74efc8b0563509a225a527493007c5b398801c5e70264337ba98
7
+ data.tar.gz: 3b395e79db9902c16dc11d0822d4639057db00ffbadab9eb8fc96d53b5fe4a4b9eca0d8b563edbd9dd121d474eeeda1e87e7900703d6f6a9d622aa052575a572
@@ -0,0 +1,2 @@
1
+ /pkg
2
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format documentation
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
@@ -0,0 +1,52 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ ga_collector_pusher (0.1)
5
+ activesupport
6
+ rest-client
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activesupport (4.1.6)
12
+ i18n (~> 0.6, >= 0.6.9)
13
+ json (~> 1.7, >= 1.7.7)
14
+ minitest (~> 5.1)
15
+ thread_safe (~> 0.1)
16
+ tzinfo (~> 1.1)
17
+ diff-lcs (1.2.5)
18
+ faker (1.4.3)
19
+ i18n (~> 0.5)
20
+ i18n (0.6.11)
21
+ json (1.8.1)
22
+ mime-types (2.4.3)
23
+ minitest (5.4.2)
24
+ netrc (0.9.0)
25
+ rake (10.4.2)
26
+ rest-client (1.7.2)
27
+ mime-types (>= 1.16, < 3.0)
28
+ netrc (~> 0.7)
29
+ rspec (3.1.0)
30
+ rspec-core (~> 3.1.0)
31
+ rspec-expectations (~> 3.1.0)
32
+ rspec-mocks (~> 3.1.0)
33
+ rspec-core (3.1.4)
34
+ rspec-support (~> 3.1.0)
35
+ rspec-expectations (3.1.1)
36
+ diff-lcs (>= 1.2.0, < 2.0)
37
+ rspec-support (~> 3.1.0)
38
+ rspec-mocks (3.1.1)
39
+ rspec-support (~> 3.1.0)
40
+ rspec-support (3.1.0)
41
+ thread_safe (0.3.4)
42
+ tzinfo (1.2.2)
43
+ thread_safe (~> 0.1)
44
+
45
+ PLATFORMS
46
+ ruby
47
+
48
+ DEPENDENCIES
49
+ faker
50
+ ga_collector_pusher!
51
+ rake
52
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Ģirts Ķesteris
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1 @@
1
+ TODO
@@ -0,0 +1,10 @@
1
+ require 'rake'
2
+ require 'rdoc/task'
3
+
4
+ require "bundler/gem_tasks"
5
+ require "rspec/core/rake_task"
6
+
7
+ RSpec::Core::RakeTask.new
8
+
9
+ task default: :spec
10
+ task test: :spec
@@ -0,0 +1,29 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "ga_collector_pusher/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "ga_collector_pusher"
7
+ s.version = GACollectorPusher::VERSION
8
+ s.author = "Girts Kesteris"
9
+ s.email = ["girts.kesteris@gmail.com"]
10
+ s.homepage = "https://github.com/Sacristan/ga_collector_pusher.git"
11
+ s.platform = Gem::Platform::RUBY
12
+ s.summary = "Push data to GoogleAnalytics via Ruby Backend "
13
+ s.require_path = "lib"
14
+ s.has_rdoc = false
15
+ s.extra_rdoc_files = ["README.rdoc"]
16
+
17
+ s.files = `git ls-files`.split("\n")
18
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
+ s.require_paths = ["lib"]
21
+ s.rubyforge_project = "ga_collector_pusher"
22
+
23
+ s.add_development_dependency 'rake'
24
+ s.add_development_dependency 'rspec'
25
+ s.add_development_dependency 'faker'
26
+
27
+ s.add_dependency "rest-client"
28
+ s.add_dependency "activesupport"
29
+ end
@@ -0,0 +1,9 @@
1
+ require 'rest-client'
2
+ require 'active_support/core_ext'
3
+ require 'ga_collector_pusher/instance'
4
+
5
+ module GACollectorPusher
6
+ def self.new
7
+ GACollectorPusher::Instance.new(cid: nil, backup_cid: nil, timeout: 10, open_timeout: 10)
8
+ end
9
+ end
@@ -0,0 +1,66 @@
1
+ module GACollectorPusher
2
+ class Instance
3
+ attr_accessor :cid, :timeout, :open_timeout
4
+
5
+ def initialize cid: nil, backup_cid: nil, timeout: 10, open_timeout: 10
6
+ self.cid = cid || backup_cid
7
+ self.timeout = timeout
8
+ self.open_timeout = open_timeout
9
+ end
10
+
11
+ def add_event category: nil, action: nil, label: nil, value: nil, utmni: false
12
+ @params = {
13
+ v: GOOGLE_ANALYTICS_SETTINGS[:version],
14
+ tid: GOOGLE_ANALYTICS_SETTINGS[:tracking_code],
15
+ cid: self.cid,
16
+ t: "event",
17
+ ec: category,
18
+ ea: action
19
+ }
20
+ send_to_ga
21
+ end
22
+
23
+ def add_transaction transaction_id: nil, total: nil, store_name: nil, tax: nil, shipping: nil, city: nil, region: nil, country: nil, currency: "EUR"
24
+ @params = {
25
+ v: GOOGLE_ANALYTICS_SETTINGS[:version],
26
+ tid: GOOGLE_ANALYTICS_SETTINGS[:tracking_code],
27
+ cid: self.cid,
28
+ t: "transaction",
29
+ ti: transaction_id,
30
+ tr: total.round(2),
31
+ cu: currency
32
+ }
33
+ send_to_ga
34
+ end
35
+
36
+ def add_item transaction_id: nil, item_sku: nil, price: nil, quantity: nil, name: nil, category: nil, currency: "EUR"
37
+ @params = {
38
+ v: GOOGLE_ANALYTICS_SETTINGS[:version],
39
+ tid: GOOGLE_ANALYTICS_SETTINGS[:tracking_code],
40
+ cid: self.cid,
41
+ t: "item",
42
+ ti: transaction_id,
43
+ in: name,
44
+ ip: price.round(2),
45
+ iq: quantity.to_i,
46
+ ic: item_sku,
47
+ iv: category,
48
+ cu: currency
49
+ }
50
+ send_to_ga
51
+ end
52
+
53
+ private
54
+ def send_to_ga
55
+ begin
56
+ response = RestClient.get 'http://www.google-analytics.com/collect', params: @params, timeout: self.timeout, open_timeout: self.open_timeout
57
+ status = "sent"
58
+ rescue => error
59
+ response = error.inspect
60
+ status = "error"
61
+ end
62
+
63
+ return {status: status, params: @params, response: response}
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ module GACollectorPusher
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ GOOGLE_ANALYTICS_SETTINGS = {
2
+ version: "1",
3
+ tracking_code: "UA-123456-1",
4
+ domain: "test@domain.com"
5
+ }
@@ -0,0 +1,10 @@
1
+ require 'bundler/setup'
2
+ Bundler.setup
3
+
4
+ require "faker"
5
+ require "config"
6
+ require "ga_collector_pusher"
7
+
8
+ RSpec.configure do |config|
9
+ # some (optional) config here
10
+ end
@@ -0,0 +1,52 @@
1
+ # rspec spec/tests/add_event_spec.rb
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "AddEventSpec" do
6
+ before :all do
7
+ @cid = "#{Faker::Number.number(10)}.#{Faker::Number.number(10)}"
8
+ @category = Faker::Lorem.word
9
+ @action = Faker::Lorem.word
10
+
11
+ @instance = GACollectorPusher::Instance.new cid: @cid
12
+ @result = @instance.add_event({
13
+ category: @category,
14
+ action: @action,
15
+ })
16
+ puts @result.inspect
17
+ end
18
+
19
+ it "status should be sent" do
20
+ expect(@result[:status]).to eq "sent"
21
+ end
22
+
23
+ it "should return GA GIF" do
24
+ expect(@result[:response]).not_to eq nil
25
+ end
26
+
27
+ context "fields" do
28
+ context "should be present" do
29
+ it "v" do
30
+ expect(@result[:params][:v]).to eq GOOGLE_ANALYTICS_SETTINGS[:version]
31
+ end
32
+ it "tid" do
33
+ expect(@result[:params][:tid]).to eq GOOGLE_ANALYTICS_SETTINGS[:tracking_code]
34
+ end
35
+ it "cid" do
36
+ expect(@result[:params][:cid]).to eq @cid
37
+ end
38
+ it "t" do
39
+ expect(@result[:params][:t]).to eq "event"
40
+ end
41
+ it "ec" do
42
+ expect(@result[:params][:ec]).to eq @category
43
+ end
44
+ it "ea" do
45
+ expect(@result[:params][:ea]).to eq @action
46
+ end
47
+ end
48
+ end
49
+
50
+
51
+
52
+ end
@@ -0,0 +1,69 @@
1
+ # rspec spec/tests/add_item_spec.rb
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "AddEventSpec" do
6
+ before :all do
7
+ @cid = "#{Faker::Number.number(10)}.#{Faker::Number.number(10)}"
8
+ @transaction_id = Faker::Number.number(8)
9
+ @item_sku = Faker::Commerce.department
10
+ @price = Faker::Commerce.price
11
+ @quantity = Faker::Number.number(2).to_i
12
+ @name = Faker::Commerce.product_name
13
+ @category = Faker::Lorem.word
14
+
15
+ @instance = GACollectorPusher::Instance.new cid: @cid
16
+ @result = @instance.add_item({
17
+ transaction_id: @transaction_id,
18
+ item_sku: @item_sku,
19
+ price: @price,
20
+ quantity: @quantity,
21
+ name: @name,
22
+ category: @category
23
+ })
24
+ puts @result.inspect
25
+ end
26
+
27
+ it "status should be sent" do
28
+ expect(@result[:status]).to eq "sent"
29
+ end
30
+
31
+ it "should return GA GIF" do
32
+ expect(@result[:response]).not_to eq nil
33
+ end
34
+
35
+ context "fields" do
36
+ context "should be present" do
37
+ it "v" do
38
+ expect(@result[:params][:v]).to eq GOOGLE_ANALYTICS_SETTINGS[:version]
39
+ end
40
+ it "tid" do
41
+ expect(@result[:params][:tid]).to eq GOOGLE_ANALYTICS_SETTINGS[:tracking_code]
42
+ end
43
+ it "cid" do
44
+ expect(@result[:params][:cid]).to eq @cid
45
+ end
46
+ it "t" do
47
+ expect(@result[:params][:t]).to eq "item"
48
+ end
49
+ it "ti" do
50
+ expect(@result[:params][:ti]).to eq @transaction_id
51
+ end
52
+ it "in" do
53
+ expect(@result[:params][:in]).to eq @name
54
+ end
55
+ it "ip" do
56
+ expect(@result[:params][:ip]).to eq @price
57
+ end
58
+ it "iq" do
59
+ expect(@result[:params][:iq]).to eq @quantity
60
+ end
61
+ it "ic" do
62
+ expect(@result[:params][:ic]).to eq @item_sku
63
+ end
64
+ it "iv" do
65
+ expect(@result[:params][:iv]).to eq @category
66
+ end
67
+ end
68
+ end
69
+ end
@@ -0,0 +1,63 @@
1
+ # rspec spec/tests/add_transaction_spec.rb
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "AddTransactionSpec" do
6
+ before :all do
7
+ @cid = "#{Faker::Number.number(10)}.#{Faker::Number.number(10)}"
8
+ @transaction_id = Faker::Number.number(8)
9
+ @total = Faker::Commerce.price
10
+ @store_name = Faker::Company.name
11
+ @tax = Faker::Number.number(2)
12
+ @shipping = Faker::Address.street_address
13
+ @city = Faker::Address.city
14
+ @region = Faker::Address.state
15
+ @country = Faker::Address.country
16
+
17
+ @instance = GACollectorPusher::Instance.new cid: @cid
18
+ @result = @instance.add_transaction ({
19
+ transaction_id: @transaction_id,
20
+ total: @total,
21
+ store_name: @store_name,
22
+ tax: @tax,
23
+ shipping: @shipping,
24
+ city: @city,
25
+ region: @region,
26
+ country: @country
27
+ })
28
+ puts @result
29
+ end
30
+
31
+ it "status should be sent" do
32
+ expect(@result[:status]).to eq "sent"
33
+ end
34
+
35
+ it "should return GA GIF" do
36
+ expect(@result[:response]).not_to eq nil
37
+ end
38
+
39
+ context "fields" do
40
+ context "should be present" do
41
+ it "v" do
42
+ expect(@result[:params][:v]).to eq GOOGLE_ANALYTICS_SETTINGS[:version]
43
+ end
44
+ it "tid" do
45
+ expect(@result[:params][:tid]).to eq GOOGLE_ANALYTICS_SETTINGS[:tracking_code]
46
+ end
47
+ it "cid" do
48
+ expect(@result[:params][:cid]).to eq @cid
49
+ end
50
+ it "t" do
51
+ expect(@result[:params][:t]).to eq "transaction"
52
+ end
53
+ it "ti" do
54
+ expect(@result[:params][:ti]).to eq @transaction_id
55
+ end
56
+ it "tr" do
57
+ expect(@result[:params][:tr]).to eq @total
58
+ end
59
+ end
60
+ end
61
+
62
+
63
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ga_collector_pusher
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Girts Kesteris
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rest-client
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: activesupport
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description:
84
+ email:
85
+ - girts.kesteris@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files:
89
+ - README.rdoc
90
+ files:
91
+ - .gitignore
92
+ - .rspec
93
+ - Gemfile
94
+ - Gemfile.lock
95
+ - LICENSE
96
+ - README.rdoc
97
+ - Rakefile
98
+ - ga_collector_pusher.gemspec
99
+ - lib/ga_collector_pusher.rb
100
+ - lib/ga_collector_pusher/instance.rb
101
+ - lib/ga_collector_pusher/version.rb
102
+ - spec/config.rb
103
+ - spec/spec_helper.rb
104
+ - spec/tests/add_event_spec.rb
105
+ - spec/tests/add_item_spec.rb
106
+ - spec/tests/add_transaction_spec.rb
107
+ homepage: https://github.com/Sacristan/ga_collector_pusher.git
108
+ licenses: []
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project: ga_collector_pusher
126
+ rubygems_version: 2.2.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Push data to GoogleAnalytics via Ruby Backend
130
+ test_files:
131
+ - spec/config.rb
132
+ - spec/spec_helper.rb
133
+ - spec/tests/add_event_spec.rb
134
+ - spec/tests/add_item_spec.rb
135
+ - spec/tests/add_transaction_spec.rb