gabba-gmp 0.0.2 → 0.0.3

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.
data/.gitignore CHANGED
@@ -35,4 +35,5 @@ Icon
35
35
  .Spotlight-V100
36
36
  .Trashes
37
37
 
38
- *.project
38
+ *.project
39
+ *.gem
data/Readme.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Gabba-GMP
2
2
 
3
-
3
+ [![Gem Version](https://badge.fury.io/rb/gabba-gmp.svg)](http://badge.fury.io/rb/gabba-gmp)
4
4
 
5
5
  Simple class to send custom server-side events to Google Analytics via Google Measurement Protocol
6
6
  https://developers.google.com/analytics/devguides/collection/protocol/v1/
@@ -13,22 +13,28 @@ Refactored from the [gabba](https://github.com/hybridgroup/gabba) project.
13
13
  ### Track page views
14
14
 
15
15
  ```ruby
16
- google_tracker_id = "UT-1234"
17
- host = "#{request.host}"
18
- cookies[:utm_visitor_uuid] = { value: "#{SecureRandom.uuid}", expires: 1.year.from_now} if !cookies[:utm_visitor_uuid].present?
19
- visitor_id = "#{cookies[:utm_visitor_uuid]}"
20
- client_ip = "#{request.remote_ip}"
21
- user_agent = "#{request.env["HTTP_USER_AGENT"]}"
16
+ gabba = GabbaGMP::GabbaGMP.new("UT-1234", request, cookies)
17
+
18
+ gabba.page_view(request)
19
+
20
+ ```
22
21
 
23
- gabba = GabbaGMP::GabbaGMP.new(google_tracker_id, host, visitor_id, client_ip, user_agent)
22
+ You can also include the page title:
23
+ ```ruby
24
+ gabba.page_view(request, "Page Title")
25
+
26
+ ```
27
+
28
+ Or if you want to get really fancy you can update the parameters for the page view only..
29
+ ```ruby
30
+ gabba.page_view(request, "Page Title", document_path: "/manually/fiddled/url")
24
31
 
25
- gabba.page_view("page title", "page/1.html")
26
32
  ```
27
33
 
28
34
  ### Track custom events
29
35
 
30
36
  ```ruby
31
- gabba = GabbaGMP::GabbaGMP.new(google_tracker_id, host, visitor_id, client_ip, user_agent)
37
+ gabba = GabbaGMP::GabbaGMP.new("UT-1234", request, cookies)
32
38
 
33
39
  gabba.event("Videos", "Play", "ID", "123")
34
40
  ```
@@ -36,14 +42,10 @@ gabba.event("Videos", "Play", "ID", "123")
36
42
  ### Setting custom vars
37
43
 
38
44
  ```ruby
39
- # Index: 1 through 50
45
+ # Index: 1 through 200 (for pro or 20 for free)
40
46
  index = 1
41
47
 
42
- # Scope: VISITOR, SESSION or PAGE
43
- scope = GabbaGMP::GabbaGMP::VISITOR
44
-
45
- # Set var
46
- gabba.set_custom_var(index, 'Name', 'Value', scope)
48
+ gabba.set_custom_var(index, 'Name', 'Value')
47
49
 
48
50
  # Track the event (all vars will be included)
49
51
  gabba.event(...)
@@ -52,6 +54,44 @@ gabba.event(...)
52
54
  gabba.page_view(...)
53
55
  ```
54
56
 
57
+ ### Campaigns
58
+
59
+ It's easy to track campaigns! You can either use the GabbaGMP campaign object or your own(assuming it has the magic fields)!
60
+
61
+ Note that you can also send in `nil` into campaigns, and it will still work... one less check to do!
62
+
63
+ ```ruby
64
+
65
+ campaign = GabbaGMP::Campaign()
66
+
67
+ campaign.name = "GabbaCMP"
68
+ campaign.source = "gemfile"
69
+ campaign.medium = "email"
70
+ campaign.keyword = nil
71
+ campaign.content = "gems"
72
+
73
+ gabba.campaign = campaign
74
+
75
+ ```
76
+
77
+ ### Manually setting parameters
78
+
79
+ If you find that you absolutely must override variables that are used internally then you can override the session parameters:
80
+
81
+ ```ruby
82
+ gabba = GabbaGMP::GabbaGMP.new("UT-1234", request, cookies)
83
+
84
+ #Manually override the user agent so that we can detect local calls in GA!
85
+ gabba.add_options(user_agent: "LocalUse") if request.remote_ip == "127.0.0.1"
86
+
87
+ #This pageview has the new user agent! (if you are accessing from localhost)
88
+ gabba.page_view(request)
89
+
90
+ #This event also has the user agent! Easy as!
91
+ gabba.event("Videos", "Play", "ID", "123")
92
+
93
+ ```
94
+
55
95
  ### License
56
96
 
57
97
  Gabba is released under the [MIT License](http://opensource.org/licenses/MIT).
@@ -37,12 +37,12 @@ module GabbaGMP
37
37
 
38
38
  # Public: Initialize Gabba Google Analytics Tracking Object.
39
39
  #
40
- # ga_acct - A String containing your Google Analytics account id.
41
- # domain - A String containing which domain you want the tracking data to be logged from.
42
- # visitor_uuid - a uuid to uniquely identify the user - use SecureRandom.uuid to generate
43
- # client_ip - The IP address of the connected client
44
- # agent - A String containing the user agent you want the tracking to appear to be coming from.
45
- # Defaults to "Gabba 0.2 Agent" or whatever the correct version is.
40
+ # ga_tracking_id - A String containing your Google Analytics account id.
41
+ # request - The request this tracker relates to.
42
+ # cookies - The cookies object for this request. Will be updated with the client_id cookie
43
+ # options - Allows for:
44
+ # -client_id_cookie_expiry = Set the expiry of the visitor cookie manually
45
+ # -client_id_cookie_sym = The symbol to store the visitor id cookie under
46
46
  # Example:
47
47
  #
48
48
  # g = GabbaGMP::GabbaGMP.new("UT-1234", "mydomain.com")
@@ -61,11 +61,20 @@ module GabbaGMP
61
61
  document_host: request.host,
62
62
  client_id: cookies[client_id_cookie],
63
63
  user_ip_address: request.remote_ip,
64
- user_agent: request.env["HTTP_USER_AGENT"]}
64
+ user_agent: request.user_agent,
65
+ user_language: preferred_language(request.accept_language)}
66
+
67
+ @sessionopts[:document_referrer] = request.referrer if request.referrer.present?
65
68
 
66
69
  debug = false
67
70
  end
68
71
 
72
+ def preferred_language(language)
73
+ return "" unless language.present?
74
+
75
+ language_arr = language.split(",").map {|lang_pref| lang_pref.split(";")}
76
+ language_arr[0][0] #just get the first language. Will probably be correct.
77
+ end
69
78
 
70
79
  # Public: Set the session's parameters. This will be added to all actions that are sent to analytics.
71
80
  #
@@ -6,9 +6,14 @@ module GabbaGMP
6
6
  protocol_version: :v,
7
7
  tracking_id: :tid,
8
8
 
9
- user_ip_address: :uip,
10
9
  client_id: :cid,
10
+ user_id: :uid, #currently untested
11
+ user_ip_address: :uip,
11
12
  user_agent: :ua,
13
+ user_language: :ul,
14
+ user_screen_resolution: :sr, #currently untested
15
+ user_viewport_size: :vp, #currently untested
16
+ user_screen_colors: :sd, #currently untested
12
17
 
13
18
  hit_type: :t,
14
19
 
@@ -1,5 +1,5 @@
1
1
  module GabbaGMP
2
2
  unless const_defined?('VERSION')
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gabba-gmp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2014-09-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: net-http-persistent
16
- requirement: &23922576 !ruby/object:Gem::Requirement
16
+ requirement: &26367252 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.9'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *23922576
24
+ version_requirements: *26367252
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &23922276 !ruby/object:Gem::Requirement
27
+ requirement: &26366952 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: 10.1.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *23922276
35
+ version_requirements: *26366952
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &23922000 !ruby/object:Gem::Requirement
38
+ requirement: &26366676 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ~>
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.14.1
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *23922000
46
+ version_requirements: *26366676
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: webmock
49
- requirement: &23921724 !ruby/object:Gem::Requirement
49
+ requirement: &26366400 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ~>
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: 1.13.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *23921724
57
+ version_requirements: *26366400
58
58
  description: Google Measurement Protocol rewite of the Gabba library
59
59
  email:
60
60
  - julz dot west at gmail dot com