gaevents 0.1.1 → 1.04
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rspec +2 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +1 -0
- data/Gemfile +4 -0
- data/README.md +22 -5
- data/Rakefile +2 -2
- data/bin/console +3 -3
- data/gaevents.gemspec +18 -13
- data/lib/gaevents.rb +27 -25
- data/lib/gaevents/event.rb +21 -26
- data/lib/gaevents/version.rb +1 -1
- metadata +41 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 31e17368516bd792f7be1a798d4b467705b64f7414bcaf424714f7b406f66ef5
|
4
|
+
data.tar.gz: 061faad9641e410ec34a94ecbf8c2fdb25c34959f9dcd206d0e43a4f5ae1181e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 29516d500929862fcb097832654f679441c37e4a15b05ab8d727d229657ecd44188952e065e94dbd32ab8b3886ced7c96d9c99cb5a8019bbfe3dd0ae627eaf9a
|
7
|
+
data.tar.gz: 07d1c6503ee27ed09e229edcb01fef99ab94b04445e0a7395cc05f423952ff4ce85cc8c40b4caa136ab4a1c1da5385307f23b152bf0259a5585b530b75853c57
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
data/.travis.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
language: ruby
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/gaevents.svg)](https://badge.fury.io/rb/gaevents)
|
2
|
+
[![Build Status](https://travis-ci.com/singhshivam/gaevents.svg?branch=master)](https://travis-ci.com/singhshivam/gaevents)
|
3
|
+
|
1
4
|
# Gaevents
|
2
5
|
|
3
|
-
This gem
|
6
|
+
This gem allows you to update multiple background events in one go (via batches). Unlike other gems you do not need to load a js file to send events. Gaevents leverage GA's Measurement Protocol to send the events.
|
4
7
|
|
5
8
|
## Installation
|
6
9
|
|
@@ -20,16 +23,30 @@ Or install it yourself as:
|
|
20
23
|
|
21
24
|
## Usage
|
22
25
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
+
Please refer [Measurement Protocol Parameter Reference](https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters) for the list of all parameters accepted by the Protocol.
|
27
|
+
|
28
|
+
The following parameters are required in each event:
|
29
|
+
`v`, `tid`, `cid` and `t`. This gem automatically injects `v`, make sure all events have `tid`, `cid` and `t` as parameters.
|
26
30
|
|
31
|
+
```
|
27
32
|
events = []
|
28
33
|
10.times { |n|
|
29
|
-
events << GAEvents::Event.new(
|
34
|
+
events << GAEvents::Event.new({tid: GATRACKINGID, cid: "ci#{n}", t: 'event', ec: "video#{n}", ea: "abc#{n}", uid: "user#{n}"})
|
30
35
|
}
|
31
36
|
GAEvents.track(events)
|
32
37
|
```
|
38
|
+
|
39
|
+
## Migrating from 0.x to 1.x
|
40
|
+
|
41
|
+
In 0.x versions events were restricted to accepting only 5 parameters: `cid`, `ec`, `ea`, `el` and `ev` in the same order. Example:
|
42
|
+
```
|
43
|
+
GAEvents::Event.new(GOOGLE_API_CLIENT_ID, "testcategory", "gaaction")
|
44
|
+
```
|
45
|
+
1.x now accepts a hash that can have any number of acceptable parameters. The above line of code then becomes:
|
46
|
+
```
|
47
|
+
GAEvents::Event.new({tid: GATRACKINGID, cid: GOOGLE_API_CLIENT_ID, ec: "testcategory", ea: "gaaction"})
|
48
|
+
```
|
49
|
+
|
33
50
|
## Development
|
34
51
|
|
35
52
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/Rakefile
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
require
|
2
|
-
task :
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
task default: :spec
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'gaevents'
|
5
5
|
|
6
6
|
# You can add fixtures and/or initialization code here to make experimenting
|
7
7
|
# with your gem easier. You can also use a different console, if you like.
|
@@ -10,5 +10,5 @@ require "gaevents"
|
|
10
10
|
# require "pry"
|
11
11
|
# Pry.start
|
12
12
|
|
13
|
-
require
|
13
|
+
require 'irb'
|
14
14
|
IRB.start(__FILE__)
|
data/gaevents.gemspec
CHANGED
@@ -1,27 +1,32 @@
|
|
1
|
-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
1
|
+
lib = File.expand_path('lib', __dir__)
|
3
2
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
3
|
require 'gaevents/version'
|
5
4
|
|
6
5
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
6
|
+
spec.name = 'gaevents'
|
8
7
|
spec.version = Gaevents::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
8
|
+
spec.authors = ['singhshivam']
|
9
|
+
spec.email = ['shivam@blogvault.net']
|
11
10
|
|
12
|
-
spec.
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
spec.description = 'Provides an integration for sending multiple events to Google Analytics'
|
12
|
+
spec.summary = 'This gem allows you to update multiple background events ' \
|
13
|
+
'in one go (via batches). Unlike other gems ' \
|
14
|
+
'you dont need to load a js file to send events. ' \
|
15
|
+
'Gaevents leverage GA\'s Measurement Protocol.'
|
16
|
+
|
17
|
+
spec.homepage = 'https://github.com/singhshivam/gaevents'
|
18
|
+
spec.license = 'MIT'
|
16
19
|
|
17
20
|
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
21
|
f.match(%r{^(test|spec|features)/})
|
19
22
|
end
|
20
|
-
spec.bindir =
|
23
|
+
spec.bindir = 'exe'
|
21
24
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
-
spec.require_paths = [
|
25
|
+
spec.require_paths = ['lib']
|
23
26
|
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.14'
|
28
|
+
spec.add_development_dependency 'pry'
|
29
|
+
spec.add_development_dependency "rake", ">= 12.3.3"
|
30
|
+
spec.add_development_dependency 'rspec'
|
26
31
|
spec.add_runtime_dependency 'rest-client', '~> 2.0', '>= 2.0.2'
|
27
32
|
end
|
data/lib/gaevents.rb
CHANGED
@@ -1,32 +1,34 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require_relative
|
1
|
+
require 'gaevents/version'
|
2
|
+
require 'rest-client'
|
3
|
+
require_relative 'gaevents/event'
|
4
4
|
|
5
|
+
# collection of events
|
5
6
|
class GAEvents
|
6
|
-
|
7
|
-
|
7
|
+
BULK_URI = 'https://www.google-analytics.com/batch'.freeze
|
8
|
+
COLLECT_URI = 'https://www.google-analytics.com/collect'.freeze
|
8
9
|
|
9
|
-
|
10
|
-
|
10
|
+
class << self
|
11
|
+
attr_accessor :api_key
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
def send_event(event)
|
14
|
+
resource = RestClient::Resource.new COLLECT_URI
|
15
|
+
resource.post(track_body([event]), content_type: 'text/plain')
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
18
|
+
# takes Array of Event as parameter
|
19
|
+
def track(events)
|
20
|
+
# as per GA: A maximum of 20 hits can be specified per request
|
21
|
+
# https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide#batch
|
22
|
+
res = []
|
23
|
+
events.each_slice(20) do |events_slice|
|
24
|
+
resource = RestClient::Resource.new BULK_URI
|
25
|
+
res << resource.post(track_body(events_slice.compact), content_type: 'text/plain')
|
26
|
+
end
|
27
|
+
res
|
28
|
+
end
|
27
29
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
30
|
+
def track_body(*events)
|
31
|
+
events.flatten.map(&:payload).join("\n")
|
32
|
+
end
|
33
|
+
end
|
32
34
|
end
|
data/lib/gaevents/event.rb
CHANGED
@@ -1,31 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class GAEvents
|
2
|
-
|
3
|
-
|
4
|
+
# Class to define analytical events
|
5
|
+
# expected attributes: tid, cid and t
|
6
|
+
class Event
|
7
|
+
attr_accessor :params
|
4
8
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@label = label
|
10
|
-
@value = value
|
11
|
-
end
|
9
|
+
# Initialize Events by passing a hash.
|
10
|
+
# Keys could be any GA allowed parameter.
|
11
|
+
# Please refer Measurement Protocol Parameter Reference for available options:
|
12
|
+
# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"ea" => @action,
|
21
|
-
"el" => @label,
|
22
|
-
"ev" => @value
|
23
|
-
}
|
24
|
-
params.reject! { |k,v| !v }
|
25
|
-
end
|
14
|
+
# As per Measurement Protocol, parameters: v, tid, cid and t should always be present.
|
15
|
+
# This gem automatically injects v. Ensure you always pass tid, cid and t while
|
16
|
+
# initializing events.
|
17
|
+
def initialize(hash = {})
|
18
|
+
@params = hash.select { |_k, v| v }
|
19
|
+
@params['v'] = 1
|
20
|
+
end
|
26
21
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
22
|
+
def payload
|
23
|
+
URI.encode_www_form(@params)
|
24
|
+
end
|
25
|
+
end
|
31
26
|
end
|
data/lib/gaevents/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gaevents
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: '1.04'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- singhshivam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -24,20 +24,48 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.14'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pry
|
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'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: rake
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
30
44
|
requirements:
|
31
|
-
- - "
|
45
|
+
- - ">="
|
32
46
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
47
|
+
version: 12.3.3
|
34
48
|
type: :development
|
35
49
|
prerelease: false
|
36
50
|
version_requirements: !ruby/object:Gem::Requirement
|
37
51
|
requirements:
|
38
|
-
- - "
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 12.3.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
39
67
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
68
|
+
version: '0'
|
41
69
|
- !ruby/object:Gem::Dependency
|
42
70
|
name: rest-client
|
43
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -66,6 +94,9 @@ extensions: []
|
|
66
94
|
extra_rdoc_files: []
|
67
95
|
files:
|
68
96
|
- ".gitignore"
|
97
|
+
- ".rspec"
|
98
|
+
- ".rubocop.yml"
|
99
|
+
- ".travis.yml"
|
69
100
|
- CODE_OF_CONDUCT.md
|
70
101
|
- Gemfile
|
71
102
|
- LICENSE.txt
|
@@ -96,9 +127,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
127
|
- !ruby/object:Gem::Version
|
97
128
|
version: '0'
|
98
129
|
requirements: []
|
99
|
-
|
100
|
-
rubygems_version: 2.5.2
|
130
|
+
rubygems_version: 3.0.3
|
101
131
|
signing_key:
|
102
132
|
specification_version: 4
|
103
|
-
summary:
|
133
|
+
summary: This gem allows you to update multiple background events in one go (via batches).
|
134
|
+
Unlike other gems you dont need to load a js file to send events. Gaevents leverage
|
135
|
+
GA's Measurement Protocol.
|
104
136
|
test_files: []
|