ga_collect 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bf5907829af46de04e773e9c922dbea14155f52e
4
+ data.tar.gz: 5db8c408e45bb6fca4d5b3e3242c7fa8528db786
5
+ SHA512:
6
+ metadata.gz: 423f342bceb51c14402012ce4f847108a16e6d773a687c0edcf32de646799a4d96ed22bf2eed297628fececcb0c1770aff8e95e4c8fe3d814f85aafe96b9eb84
7
+ data.tar.gz: 8de3155cb3e886f674e1af77b7dd5f4109745709f9171506114a082d4fa1416476c73866ad5beaac8f935dbe0bb312145a5e35b0db8a62bf1b15bad512197b36
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ga_collect.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # GaCollect
2
+
3
+ GaCollect is a simple Ruby library which collects metrics on the server side and sends them to google analytics using its measurement protocol https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#usertiming
4
+
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'ga_collect'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install ga_collect
21
+
22
+ ## Usage
23
+ All parameters are the same than the official measurement protocol https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide
24
+
25
+ First get the tracker
26
+ ```ruby
27
+ @tracker = GaCollect.tracker('test_tracker_id')
28
+ ```
29
+ And then use the measurements available
30
+ ```ruby
31
+ # Pageview
32
+ @tracker.pageview(dh: 'jsanroman.net', dp: '/', dt: 'Javi Sanromán')
33
+
34
+ # Event
35
+ @tracker.event(ec: 'ga_collect', ea: 'test2', ev: 1)
36
+
37
+ # Exception
38
+ @tracker.exception(exd: 'IOException', exf: '1')
39
+
40
+ # Item
41
+ @tracker.item(ti: 123, in: 'test', ip: '10', iq: 2, ic: '12345', iv: 'ga_collect')
42
+
43
+ # Screenview
44
+ @tracker.screenview(an: 'funTimes', av: '4.2.0', aid: 'com.foo.App', aiid: 'com.android.vending', cd: 'Home')
45
+
46
+ # Social
47
+ @tracker.social(sa: 'like', sn: 'facebook', st: '/home')
48
+
49
+ # Timing
50
+ @tracker.timing(utc: 'jsonLoader', utv: 'load', utt: 5000, utl: 'jQuery', dns: 100, pdt: 20, rrt: 32, tcp: 56, srt: 12)
51
+
52
+ # Transaction
53
+ @tracker.transaction(ti: 123, ta: '', tr: 10, ts: 0, tt: 0c)
54
+ ```
55
+
56
+
57
+ ## Contributing
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ga_collect"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ga_collect/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = 'ga_collect'
8
+ spec.version = GaCollect::VERSION
9
+ spec.licenses = ["MIT"]
10
+ spec.authors = ["Javi Sanromán"]
11
+ spec.email = ["javisanroman@gmail.com"]
12
+
13
+ spec.summary = %q{GaCollect is a simple Ruby library which collects metrics on the server side and sends them to google analytics using its measurement protocol}
14
+ spec.description = %q{GaCollect is a simple Ruby library which collects metrics on the server side and sends them to google analytics using its measurement protocol https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#usertiming}
15
+ spec.homepage = "https://github.com/jsanroman/ga_collect"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.9"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'net/http'
2
+
3
+ module GaCollect
4
+ module HTTP
5
+
6
+ def self.get(params)
7
+ uri = URI('http://www.google-analytics.com/collect')
8
+ uri.query = URI.encode_www_form(params)
9
+
10
+ Net::HTTP.get_response(uri)
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module GaCollect
2
+ module Measure
3
+
4
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#event
5
+ def self.event(options={})
6
+ raise ArgumentError, 'category is required' if options[:ec].nil? || options[:ec].empty?
7
+ raise ArgumentError, 'action is required' if options[:ea].nil? || options[:ea].empty?
8
+
9
+ params = {ec: '', ea: '', el: '', ev: ''}.merge(options)
10
+ params.merge!({t: :event})
11
+
12
+ GaCollect::HTTP.get(params)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module GaCollect
2
+ module Measure
3
+
4
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#exception
5
+ def self.exception(options={})
6
+ params = {exd: '', exf: ''}.merge(options)
7
+
8
+ GaCollect::HTTP.get(params)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module GaCollect
2
+ module Measure
3
+
4
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#ecom
5
+ def self.item(options={})
6
+ raise ArgumentError, 'transaction_id is required' if options[:ti].nil? || options[:ti].to_s.empty?
7
+
8
+ params = {ti: '', in: '', ip: 0, iq: 1, ic: '', iv: '', cu: 'EUR'}.merge(options)
9
+
10
+ GaCollect::HTTP.get(params)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ module GaCollect
2
+ module Measure
3
+
4
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#page
5
+ def self.pageview(options={})
6
+ params = {dh: '', dp: '', dt: ''}.merge(options)
7
+
8
+ GaCollect::HTTP.get(params)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module GaCollect
2
+ module Measure
3
+
4
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#screenView
5
+ def self.screenview(options={})
6
+ params = {an: '', av: '', aid: '', aiid: '', cd: ''}.merge(options)
7
+
8
+ GaCollect::HTTP.get(params)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,15 @@
1
+ module GaCollect
2
+ module Measure
3
+
4
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#social
5
+ def self.social(options={})
6
+ raise ArgumentError, 'social_action is required' if options[:sa].nil? || options[:sa].empty?
7
+ raise ArgumentError, 'social_network is required' if options[:sn].nil? || options[:sn].empty?
8
+ raise ArgumentError, 'social_target is required' if options[:st].nil? || options[:st].empty?
9
+
10
+ params = {sa: '', sn: '', st: ''}.merge(options)
11
+
12
+ GaCollect::HTTP.get(params)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,11 @@
1
+ module GaCollect
2
+ module Measure
3
+
4
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#usertiming
5
+ def self.timing(options={})
6
+ params = {utc: '', utv: '', utt: 0, utl: '', dns: 0, pdt: 0, rrt: 0, tcp: 0, srt: 0}.merge(options)
7
+
8
+ GaCollect::HTTP.get(params)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ module GaCollect
2
+ module Measure
3
+
4
+ # https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#ecom
5
+ def self.transaction(options={})
6
+ raise ArgumentError, 'transaction_id is required' if options[:ti].nil? || options[:ti].to_s.empty?
7
+
8
+ params = {ti: '', ta: '', tr: 0, ts: 0, tt: 0, cu: 'EUR'}.merge(options)
9
+
10
+ GaCollect::HTTP.get(params)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,3 @@
1
+ module GaCollect
2
+ VERSION = "0.1.0"
3
+ end
data/lib/ga_collect.rb ADDED
@@ -0,0 +1,33 @@
1
+ require "ga_collect/version"
2
+
3
+ module GaCollect
4
+ MEASURES = [:pageview, :event, :transaction, :item, :social, :exception, :timing, :screenview]
5
+
6
+ def self.tracker(tracking_id = nil)
7
+ raise ArgumentError, 'tracking_id is required' if tracking_id.empty?
8
+ GaCollect::Tracker.new(tracking_id)
9
+ end
10
+
11
+ class Tracker
12
+ def initialize(tracking_id, client_id=555, version=1)
13
+ @tracking_id = tracking_id
14
+ @client_id = client_id
15
+ @version = version
16
+ end
17
+
18
+
19
+ GaCollect::MEASURES.each do |method|
20
+ define_method(method) do |argument|
21
+ options = argument.merge({v: @version, tid: @tracking_id, cid: @client_id, t: method})
22
+
23
+ GaCollect::Measure.send(method, options)
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+
30
+ require 'ga_collect/http'
31
+ GaCollect::MEASURES.each do |measure|
32
+ require "ga_collect/measure/#{measure}"
33
+ end
metadata ADDED
@@ -0,0 +1,94 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ga_collect
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Javi Sanromán
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-11-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: GaCollect is a simple Ruby library which collects metrics on the server
42
+ side and sends them to google analytics using its measurement protocol https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#usertiming
43
+ email:
44
+ - javisanroman@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - .rspec
51
+ - .travis.yml
52
+ - Gemfile
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - ga_collect.gemspec
58
+ - lib/ga_collect.rb
59
+ - lib/ga_collect/http.rb
60
+ - lib/ga_collect/measure/event.rb
61
+ - lib/ga_collect/measure/exception.rb
62
+ - lib/ga_collect/measure/item.rb
63
+ - lib/ga_collect/measure/pageview.rb
64
+ - lib/ga_collect/measure/screenview.rb
65
+ - lib/ga_collect/measure/social.rb
66
+ - lib/ga_collect/measure/timing.rb
67
+ - lib/ga_collect/measure/transaction.rb
68
+ - lib/ga_collect/version.rb
69
+ homepage: https://github.com/jsanroman/ga_collect
70
+ licenses:
71
+ - MIT
72
+ metadata: {}
73
+ post_install_message:
74
+ rdoc_options: []
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - '>='
80
+ - !ruby/object:Gem::Version
81
+ version: '0'
82
+ required_rubygems_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ requirements: []
88
+ rubyforge_project:
89
+ rubygems_version: 2.0.14
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: GaCollect is a simple Ruby library which collects metrics on the server side
93
+ and sends them to google analytics using its measurement protocol
94
+ test_files: []