gaevents 0.1.1 → 1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -1
- data/lib/gaevents/event.rb +12 -21
- data/lib/gaevents/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 725b1b06500554570c15423099e62fdb4d19eb12
|
4
|
+
data.tar.gz: 8c5456f2f8fc83b2f8c6c176b90e2cae3c327f51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddc447cd347d0b7294b475581136d0fae6b1a2d5650c54260c8f25f6af9f640fc3b296b2539f367f717bef642ca86d010ba7847cb75b6d09f972ecda282e824e
|
7
|
+
data.tar.gz: ed4384d4bdced985112ae965585c401bf8e637679311bb8ccfd5f0e0109acef72c0391b5ec486bc3cfa3276dec0a54bb18f480d32a9f103b23708d69d1dbd093
|
data/README.md
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
[![Gem Version](https://badge.fury.io/rb/gaevents.svg)](https://badge.fury.io/rb/gaevents)
|
2
|
+
|
1
3
|
# Gaevents
|
2
4
|
|
3
5
|
This gem provides an integration for sending multiple events to Google Analytics. Events are sent in batches leveraging Measurement Protocol.
|
@@ -20,16 +22,33 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Usage
|
22
24
|
|
25
|
+
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.
|
26
|
+
|
27
|
+
The following parameters are required in each event:
|
28
|
+
`v`, `tid`, `cid` and `t`. This gem automatically injects `v` and `tid` therefore make sure all generated events have `cid` and `t` as parameters.
|
29
|
+
|
23
30
|
```
|
24
31
|
# configure your application's API key
|
25
32
|
GAEvents.api_key = "UA-XXXXX-Y"
|
26
33
|
|
27
34
|
events = []
|
28
35
|
10.times { |n|
|
29
|
-
events << GAEvents::Event.new(
|
36
|
+
events << GAEvents::Event.new({cid: "ci#{n}", t: 'event', ec: "video#{n}", ea: "abc#{n}", uid: "user#{n}"})
|
30
37
|
}
|
31
38
|
GAEvents.track(events)
|
32
39
|
```
|
40
|
+
|
41
|
+
## Migrating from 0.x to 1.x
|
42
|
+
|
43
|
+
In 0.x versions events were restricted to accepting only 5 parameters: `cid`, `ec`, `ea`, `el` and `ev` in the same order. Example:
|
44
|
+
```
|
45
|
+
GAEvents::Event.new(GOOGLE_API_CLIENT_ID, "testcategory", "gaaction")
|
46
|
+
```
|
47
|
+
1.x now accepts a hash that can have any number of acceptable parameters. The above line of code then becomes:
|
48
|
+
```
|
49
|
+
GAEvents::Event.new({cid: GOOGLE_API_CLIENT_ID, ec: "testcategory", ea: "gaaction"})
|
50
|
+
```
|
51
|
+
|
33
52
|
## Development
|
34
53
|
|
35
54
|
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/lib/gaevents/event.rb
CHANGED
@@ -1,31 +1,22 @@
|
|
1
1
|
class GAEvents
|
2
2
|
class Event
|
3
|
-
attr_accessor :
|
3
|
+
attr_accessor :params
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
@label = label
|
10
|
-
@value = value
|
11
|
-
end
|
5
|
+
# Initialize Events by passing a hash.
|
6
|
+
# Keys could be any GA allowed parameter.
|
7
|
+
# Please refer Measurement Protocol Parameter Reference for available options:
|
8
|
+
# https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters
|
12
9
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
"
|
19
|
-
"ec" => @category,
|
20
|
-
"ea" => @action,
|
21
|
-
"el" => @label,
|
22
|
-
"ev" => @value
|
23
|
-
}
|
24
|
-
params.reject! { |k,v| !v }
|
10
|
+
# As per Measurement Protocol, parameters: v, tid, cid and t should always be present.
|
11
|
+
# This gem automatically injects v and tid. Ensure you always pass cid and t when
|
12
|
+
# initializing events.
|
13
|
+
def initialize(hash = {})
|
14
|
+
@params = hash.reject { |k,v| !v }
|
15
|
+
@params["v"] = 1
|
25
16
|
end
|
26
17
|
|
27
18
|
def payload(tid)
|
28
|
-
URI.encode_www_form
|
19
|
+
URI.encode_www_form(@params.merge({"tid": tid}))
|
29
20
|
end
|
30
21
|
end
|
31
22
|
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.0'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- singhshivam
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|