insights 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 596dc0e0949da344da61b0d339001672d66a835d
4
- data.tar.gz: 43741b49b3b56e4ac0b50eb2ba5d1116c9df68c7
3
+ metadata.gz: 3e157384ea53918045d4a122d411d80eae632f1d
4
+ data.tar.gz: 79699e98e830986860a612c413aae5718ec513d1
5
5
  SHA512:
6
- metadata.gz: bffb4aa492c6e78c04c7ab8f61edeec41649fb93c883744468ea2dc199b0f7a55687ab5cb1ed94909c4eafc3ccc50166d0db05041e951c92c8965c3829211615
7
- data.tar.gz: 41e1839edca3aee5648fe7e4e76f3761473c95b21ac6ee6b8dc2505c60564128ea4de2372eb2cf6e9806a5f8844375f0f0d23618e8625f069c7c479e4e4bc0df
6
+ metadata.gz: 5bf87ffc08da3025210dd7d06ceb30977f038a5521e5bd07efa88949cd569213f8ac8250894a1adb15a15a64202bae711994ec387fd3fc1c4c30183cabad8f08
7
+ data.tar.gz: 9c94c117fcd1dfc5b9210830e6787d2fd64978a8a3d1c53f23e65526a565e5fd79a1aaf00a7eacc7acf28cba4e394f69cf023682d12cbe2222b269f8fe98105c
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
- .DS_Store
1
+ .DS_Store
2
+ pkg
data/Gemfile.lock ADDED
@@ -0,0 +1,72 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ insights (0.1.1)
5
+ google-api-client
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ activesupport (4.2.5)
11
+ i18n (~> 0.7)
12
+ json (~> 1.7, >= 1.7.7)
13
+ minitest (~> 5.1)
14
+ thread_safe (~> 0.3, >= 0.3.4)
15
+ tzinfo (~> 1.1)
16
+ addressable (2.4.0)
17
+ autoparse (0.3.3)
18
+ addressable (>= 2.3.1)
19
+ extlib (>= 0.9.15)
20
+ multi_json (>= 1.0.0)
21
+ extlib (0.9.16)
22
+ faraday (0.9.2)
23
+ multipart-post (>= 1.2, < 3)
24
+ google-api-client (0.8.6)
25
+ activesupport (>= 3.2)
26
+ addressable (~> 2.3)
27
+ autoparse (~> 0.3)
28
+ extlib (~> 0.9)
29
+ faraday (~> 0.9)
30
+ googleauth (~> 0.3)
31
+ launchy (~> 2.4)
32
+ multi_json (~> 1.10)
33
+ retriable (~> 1.4)
34
+ signet (~> 0.6)
35
+ googleauth (0.4.2)
36
+ faraday (~> 0.9)
37
+ jwt (~> 1.4)
38
+ logging (~> 2.0)
39
+ memoist (~> 0.12)
40
+ multi_json (~> 1.11)
41
+ signet (~> 0.6)
42
+ i18n (0.7.0)
43
+ json (1.8.3)
44
+ jwt (1.5.2)
45
+ launchy (2.4.3)
46
+ addressable (~> 2.3)
47
+ little-plugger (1.1.4)
48
+ logging (2.0.0)
49
+ little-plugger (~> 1.1)
50
+ multi_json (~> 1.10)
51
+ memoist (0.13.0)
52
+ minitest (5.8.3)
53
+ multi_json (1.11.2)
54
+ multipart-post (2.0.0)
55
+ retriable (1.4.1)
56
+ signet (0.7.0)
57
+ addressable (~> 2.3)
58
+ faraday (~> 0.9)
59
+ jwt (~> 1.5)
60
+ multi_json (~> 1.10)
61
+ thread_safe (0.3.5)
62
+ tzinfo (1.2.2)
63
+ thread_safe (~> 0.1)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ insights!
70
+
71
+ BUNDLED WITH
72
+ 1.10.6
@@ -0,0 +1,49 @@
1
+ require "net/http"
2
+
3
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
4
+ # v=1 // Version.
5
+ # &tid=UA-XXXXX-Y // Tracking ID / Property ID.
6
+ # &cid=555 // Anonymous Client ID.
7
+ # &t=event // Event hit type
8
+ # &ec=video // Event Category. Required.
9
+ # &ea=play // Event Action. Required.
10
+ # &el=holiday // Event label.
11
+ # &ev=300 // Event value.
12
+
13
+ class GoogleAnalyticsEventsService
14
+ def self.send_event(params={})
15
+ params["v"] = 1
16
+ params["tid"] = Rails.application.secrets.ga_id
17
+ params["aip"] = 1
18
+ params["t"] = "event"
19
+
20
+ uri = URI.parse("http://www.google-analytics.com/collect")
21
+ res = Net::HTTP.post_form(uri, params)
22
+ end
23
+ end
24
+
25
+ class SendGoogleAnalyticsEventJob
26
+ @queue = :ga_events
27
+
28
+ def self.perform(data)
29
+ (1..5).each do
30
+ data_sent = try_to_send(data)
31
+ if data_sent
32
+ return
33
+
34
+ else
35
+ sleep 0.25
36
+
37
+ end
38
+ end
39
+ end
40
+
41
+ def self.try_to_send(data)
42
+ GoogleAnalyticsEventsService.send_event(data)
43
+ return true
44
+
45
+ rescue
46
+ return false
47
+
48
+ end
49
+ end
@@ -0,0 +1,24 @@
1
+ require "google/api_client"
2
+
3
+ class GoogleService
4
+ def initialize
5
+ name = Rails.application.class.to_s
6
+ version = "1"
7
+ issuer = Rails.application.secrets.ga_client_email
8
+ key_path = Rails.root.join("config", "google_service_key.p12").to_s
9
+ passphrase = Rails.application.secrets.ga_passphrase
10
+ scope = ["https://www.googleapis.com/auth/analytics.readonly"]
11
+
12
+ @client = Google::APIClient.new(application_name: name,
13
+ application_version: version)
14
+
15
+ key = Google::APIClient::PKCS12.load_key(key_path, passphrase)
16
+ service_account = Google::APIClient::JWTAsserter.new(issuer, scope, key)
17
+ @client.authorization = service_account.authorize
18
+ end
19
+
20
+ def access_token
21
+ response = @client.authorization.fetch_access_token!
22
+ response["access_token"]
23
+ end
24
+ end
@@ -1,3 +1,3 @@
1
1
  module Insights
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: insights
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Kravets
@@ -33,6 +33,7 @@ extra_rdoc_files: []
33
33
  files:
34
34
  - ".gitignore"
35
35
  - Gemfile
36
+ - Gemfile.lock
36
37
  - LICENSE.md
37
38
  - README.md
38
39
  - Rakefile
@@ -42,6 +43,8 @@ files:
42
43
  - app/assets/javascripts/insights.coffee
43
44
  - app/assets/stylesheets/insights.scss
44
45
  - app/helpers/insights_helper.rb
46
+ - app/services/google_analytics_events_service.rb
47
+ - app/services/google_service.rb
45
48
  - insights.gemspec
46
49
  - lib/insights.rb
47
50
  - lib/insights/engine.rb