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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e523230f45496a7bd32a3c62c07462367e12233f
4
- data.tar.gz: e3df85876a2a176efeccd1786a664b9f917a7dd9
3
+ metadata.gz: 725b1b06500554570c15423099e62fdb4d19eb12
4
+ data.tar.gz: 8c5456f2f8fc83b2f8c6c176b90e2cae3c327f51
5
5
  SHA512:
6
- metadata.gz: 9f42e64a7acf73c89c3e7cbbdd5cc338b0144a3607956a47052e0a69e481dafe6dac7a0f84e1ed99977c35bb8d9fa576fa9f5c6a08de542a89538109cf153527
7
- data.tar.gz: 7e0b058368e5dd442726f3cd94ac6deefc7bef8a8d7ea76603c3e0b38b736fb936a290a5f16d02c9e0c63fe657ef364f8683ae72ffdb1f2d2f375bc7ca96edef
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(GOOGLE_API_CLIENT_ID, "testcategory", "gaaction#{n}")
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.
@@ -1,31 +1,22 @@
1
1
  class GAEvents
2
2
  class Event
3
- attr_accessor :client, :category, :action, :label, :value
3
+ attr_accessor :params
4
4
 
5
- def initialize(client, category, action, label = nil, value = nil)
6
- @client = client
7
- @category = category
8
- @action = action
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
- def params(tid)
14
- params = {
15
- "v" => 1,
16
- "tid" => tid,
17
- "cid" => @client,
18
- "t" => "event",
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 params(tid)
19
+ URI.encode_www_form(@params.merge({"tid": tid}))
29
20
  end
30
21
  end
31
22
  end
@@ -1,3 +1,3 @@
1
1
  module Gaevents
2
- VERSION = "0.1.1"
2
+ VERSION = "1.0"
3
3
  end
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: 0.1.1
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-13 00:00:00.000000000 Z
11
+ date: 2017-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler