ga_collector_pusher 0.1 → 0.2

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: 142c35f3521dfa310afc55ddf9bda33e5a5556bd
4
- data.tar.gz: 6a67f795bb2d50963bf6d01a9194658479c8af8c
3
+ metadata.gz: ed661b238bc19b694a75e7496e7d8deccc05dbf3
4
+ data.tar.gz: 550294f0d3a0bb4836445d25ccd1459f1112fa55
5
5
  SHA512:
6
- metadata.gz: b13056ded8faf094b28a3cb2e7f600cefcc1140a817cd1d26d4c6bbb885c1388222bda5a551c74efc8b0563509a225a527493007c5b398801c5e70264337ba98
7
- data.tar.gz: 3b395e79db9902c16dc11d0822d4639057db00ffbadab9eb8fc96d53b5fe4a4b9eca0d8b563edbd9dd121d474eeeda1e87e7900703d6f6a9d622aa052575a572
6
+ metadata.gz: abb7239c176e48550be4fc329de6f79add58cb61100153df84f981001e2f0775d1dd770d886d41bfb16a6190fd10a920f73e5c55e975937cf2e4d918df52f0b1
7
+ data.tar.gz: 561988cc9db97ef3650bbf8d11d81e0bcea5afc23ad9cf81cd59c52b57b8aeb876cf129e741af902b07b3beeae2a9e7055b25a9b065f20c5ffef90554d4b860d
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  /pkg
2
- .DS_Store
2
+ .DS_Store
3
+ *.gem
data/Gemfile.lock CHANGED
@@ -1,29 +1,34 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ga_collector_pusher (0.1)
4
+ ga_collector_pusher (0.2)
5
5
  activesupport
6
6
  rest-client
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activesupport (4.1.6)
11
+ activesupport (4.1.10)
12
12
  i18n (~> 0.6, >= 0.6.9)
13
13
  json (~> 1.7, >= 1.7.7)
14
14
  minitest (~> 5.1)
15
15
  thread_safe (~> 0.1)
16
16
  tzinfo (~> 1.1)
17
17
  diff-lcs (1.2.5)
18
+ domain_name (0.5.23)
19
+ unf (>= 0.0.5, < 1.0.0)
18
20
  faker (1.4.3)
19
21
  i18n (~> 0.5)
22
+ http-cookie (1.0.2)
23
+ domain_name (~> 0.5)
20
24
  i18n (0.6.11)
21
- json (1.8.1)
25
+ json (1.8.3)
22
26
  mime-types (2.4.3)
23
- minitest (5.4.2)
24
- netrc (0.9.0)
27
+ minitest (5.7.0)
28
+ netrc (0.10.3)
25
29
  rake (10.4.2)
26
- rest-client (1.7.2)
30
+ rest-client (1.8.0)
31
+ http-cookie (>= 1.0.2, < 2.0)
27
32
  mime-types (>= 1.16, < 3.0)
28
33
  netrc (~> 0.7)
29
34
  rspec (3.1.0)
@@ -38,9 +43,12 @@ GEM
38
43
  rspec-mocks (3.1.1)
39
44
  rspec-support (~> 3.1.0)
40
45
  rspec-support (3.1.0)
41
- thread_safe (0.3.4)
46
+ thread_safe (0.3.5)
42
47
  tzinfo (1.2.2)
43
48
  thread_safe (~> 0.1)
49
+ unf (0.1.4)
50
+ unf_ext
51
+ unf_ext (0.0.6)
44
52
 
45
53
  PLATFORMS
46
54
  ruby
@@ -1,3 +1,7 @@
1
+ # GA Measurement protocol DOCS:
2
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
3
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide?hl=en#social
4
+
1
5
  module GACollectorPusher
2
6
  class Instance
3
7
  attr_accessor :cid, :timeout, :open_timeout
@@ -8,36 +12,40 @@ module GACollectorPusher
8
12
  self.open_timeout = open_timeout
9
13
  end
10
14
 
15
+ def add_page_view hostname: nil, page: nil, title: nil
16
+ @params = {
17
+ t: "pageview",
18
+ dh: hostname,
19
+ dp: page,
20
+ dt: title
21
+ }
22
+
23
+ send_to_ga
24
+ end
25
+
11
26
  def add_event category: nil, action: nil, label: nil, value: nil, utmni: false
12
27
  @params = {
13
- v: GOOGLE_ANALYTICS_SETTINGS[:version],
14
- tid: GOOGLE_ANALYTICS_SETTINGS[:tracking_code],
15
- cid: self.cid,
16
28
  t: "event",
17
29
  ec: category,
18
30
  ea: action
19
31
  }
32
+
20
33
  send_to_ga
21
34
  end
22
35
 
23
36
  def add_transaction transaction_id: nil, total: nil, store_name: nil, tax: nil, shipping: nil, city: nil, region: nil, country: nil, currency: "EUR"
24
37
  @params = {
25
- v: GOOGLE_ANALYTICS_SETTINGS[:version],
26
- tid: GOOGLE_ANALYTICS_SETTINGS[:tracking_code],
27
- cid: self.cid,
28
38
  t: "transaction",
29
39
  ti: transaction_id,
30
40
  tr: total.round(2),
31
41
  cu: currency
32
42
  }
43
+
33
44
  send_to_ga
34
45
  end
35
46
 
36
47
  def add_item transaction_id: nil, item_sku: nil, price: nil, quantity: nil, name: nil, category: nil, currency: "EUR"
37
48
  @params = {
38
- v: GOOGLE_ANALYTICS_SETTINGS[:version],
39
- tid: GOOGLE_ANALYTICS_SETTINGS[:tracking_code],
40
- cid: self.cid,
41
49
  t: "item",
42
50
  ti: transaction_id,
43
51
  in: name,
@@ -47,11 +55,47 @@ module GACollectorPusher
47
55
  iv: category,
48
56
  cu: currency
49
57
  }
58
+
59
+ send_to_ga
60
+ end
61
+
62
+ def add_social action: nil, network: nil, target: nil
63
+ @params = {
64
+ t: "social",
65
+ sa: action,
66
+ sn: network,
67
+ st: target
68
+ }
69
+
70
+ send_to_ga
71
+ end
72
+
73
+
74
+ #convert bool to integer
75
+ def add_exception description: nil, is_fatal: false
76
+ is_fatal_int = is_fatal ? 1 : 0
77
+
78
+ @params = {
79
+ t: "exception",
80
+ exd: description,
81
+ exf: is_fatal_int
82
+ }
83
+
50
84
  send_to_ga
51
85
  end
52
86
 
53
87
  private
88
+ def mandatory_fields
89
+ {
90
+ v: GOOGLE_ANALYTICS_SETTINGS[:version],
91
+ tid: GOOGLE_ANALYTICS_SETTINGS[:tracking_code],
92
+ cid: self.cid
93
+ }
94
+ end
95
+
54
96
  def send_to_ga
97
+ @params.merge! mandatory_fields
98
+
55
99
  begin
56
100
  response = RestClient.get 'http://www.google-analytics.com/collect', params: @params, timeout: self.timeout, open_timeout: self.open_timeout
57
101
  status = "sent"
@@ -1,3 +1,3 @@
1
1
  module GACollectorPusher
2
- VERSION = "0.1"
3
- end
2
+ VERSION = "0.2"
3
+ end
@@ -0,0 +1,52 @@
1
+ # rspec spec/tests/add_exception_spec.rb
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "AddExceptionSpec" do
6
+ before :all do
7
+ @cid = "#{Faker::Number.number(10)}.#{Faker::Number.number(10)}"
8
+
9
+ @description = Faker::Lorem.word
10
+ @is_fatal = [true, false].sample
11
+
12
+ @instance = GACollectorPusher::Instance.new cid: @cid
13
+ @result = @instance.add_exception({
14
+ description: @description,
15
+ is_fatal: @is_fatal
16
+ })
17
+ puts @result.inspect
18
+ end
19
+
20
+ it "status should be sent" do
21
+ expect(@result[:status]).to eq "sent"
22
+ end
23
+
24
+ it "should return GA GIF" do
25
+ expect(@result[:response]).not_to eq nil
26
+ end
27
+
28
+ context "fields" do
29
+ context "should be present" do
30
+ it "v" do
31
+ expect(@result[:params][:v]).to eq GOOGLE_ANALYTICS_SETTINGS[:version]
32
+ end
33
+ it "tid" do
34
+ expect(@result[:params][:tid]).to eq GOOGLE_ANALYTICS_SETTINGS[:tracking_code]
35
+ end
36
+ it "cid" do
37
+ expect(@result[:params][:cid]).to eq @cid
38
+ end
39
+ it "t" do
40
+ expect(@result[:params][:t]).to eq "exception"
41
+ end
42
+ it "exd" do
43
+ expect(@result[:params][:exd]).to eq @description
44
+ end
45
+ it "exf" do
46
+ expect(@result[:params][:exf]).to eq (@is_fatal ? 1 : 0)
47
+ end
48
+
49
+ end
50
+ end
51
+
52
+ end
@@ -0,0 +1,57 @@
1
+ # rspec spec/tests/add_page_view_spec.rb
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "AddPageViewSpec" do
6
+ before :all do
7
+ @cid = "#{Faker::Number.number(10)}.#{Faker::Number.number(10)}"
8
+
9
+ @hostname = Faker::Lorem.word
10
+ @page = Faker::Lorem.word
11
+ @title = Faker::Lorem.word
12
+
13
+ @instance = GACollectorPusher::Instance.new cid: @cid
14
+ @result = @instance.add_page_view({
15
+ hostname: @hostname,
16
+ page: @page,
17
+ title: @title
18
+ })
19
+ puts @result.inspect
20
+ end
21
+
22
+ it "status should be sent" do
23
+ expect(@result[:status]).to eq "sent"
24
+ end
25
+
26
+ it "should return GA GIF" do
27
+ expect(@result[:response]).not_to eq nil
28
+ end
29
+
30
+ context "fields" do
31
+ context "should be present" do
32
+ it "v" do
33
+ expect(@result[:params][:v]).to eq GOOGLE_ANALYTICS_SETTINGS[:version]
34
+ end
35
+ it "tid" do
36
+ expect(@result[:params][:tid]).to eq GOOGLE_ANALYTICS_SETTINGS[:tracking_code]
37
+ end
38
+ it "cid" do
39
+ expect(@result[:params][:cid]).to eq @cid
40
+ end
41
+ it "t" do
42
+ expect(@result[:params][:t]).to eq "pageview"
43
+ end
44
+ it "dh" do
45
+ expect(@result[:params][:dh]).to eq @hostname
46
+ end
47
+ it "dp" do
48
+ expect(@result[:params][:dp]).to eq @page
49
+ end
50
+ it "dt" do
51
+ expect(@result[:params][:dt]).to eq @title
52
+ end
53
+
54
+ end
55
+ end
56
+
57
+ end
@@ -0,0 +1,57 @@
1
+ # rspec spec/tests/add_social_spec.rb
2
+
3
+ require 'spec_helper'
4
+
5
+ describe "AddSocialSpec" do
6
+ before :all do
7
+ @cid = "#{Faker::Number.number(10)}.#{Faker::Number.number(10)}"
8
+
9
+ @action = Faker::Lorem.word
10
+ @network = Faker::Lorem.word
11
+ @target = Faker::Lorem.word
12
+
13
+ @instance = GACollectorPusher::Instance.new cid: @cid
14
+ @result = @instance.add_social({
15
+ action: @action,
16
+ network: @network,
17
+ target: @target
18
+ })
19
+ puts @result.inspect
20
+ end
21
+
22
+ it "status should be sent" do
23
+ expect(@result[:status]).to eq "sent"
24
+ end
25
+
26
+ it "should return GA GIF" do
27
+ expect(@result[:response]).not_to eq nil
28
+ end
29
+
30
+ context "fields" do
31
+ context "should be present" do
32
+ it "v" do
33
+ expect(@result[:params][:v]).to eq GOOGLE_ANALYTICS_SETTINGS[:version]
34
+ end
35
+ it "tid" do
36
+ expect(@result[:params][:tid]).to eq GOOGLE_ANALYTICS_SETTINGS[:tracking_code]
37
+ end
38
+ it "cid" do
39
+ expect(@result[:params][:cid]).to eq @cid
40
+ end
41
+ it "t" do
42
+ expect(@result[:params][:t]).to eq "social"
43
+ end
44
+ it "sa" do
45
+ expect(@result[:params][:sa]).to eq @action
46
+ end
47
+ it "sn" do
48
+ expect(@result[:params][:sn]).to eq @network
49
+ end
50
+ it "st" do
51
+ expect(@result[:params][:st]).to eq @target
52
+ end
53
+
54
+ end
55
+ end
56
+
57
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ga_collector_pusher
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.1'
4
+ version: '0.2'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Girts Kesteris
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-14 00:00:00.000000000 Z
11
+ date: 2015-08-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -102,7 +102,10 @@ files:
102
102
  - spec/config.rb
103
103
  - spec/spec_helper.rb
104
104
  - spec/tests/add_event_spec.rb
105
+ - spec/tests/add_exception_spec.rb
105
106
  - spec/tests/add_item_spec.rb
107
+ - spec/tests/add_page_view_spec.rb
108
+ - spec/tests/add_social_spec.rb
106
109
  - spec/tests/add_transaction_spec.rb
107
110
  homepage: https://github.com/Sacristan/ga_collector_pusher.git
108
111
  licenses: []
@@ -131,5 +134,8 @@ test_files:
131
134
  - spec/config.rb
132
135
  - spec/spec_helper.rb
133
136
  - spec/tests/add_event_spec.rb
137
+ - spec/tests/add_exception_spec.rb
134
138
  - spec/tests/add_item_spec.rb
139
+ - spec/tests/add_page_view_spec.rb
140
+ - spec/tests/add_social_spec.rb
135
141
  - spec/tests/add_transaction_spec.rb