woopra_track 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +134 -2
- data/lib/woopra_track/tracker.rb +12 -10
- data/lib/woopra_track/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f086eb67b919daf6479b17a3681ace3acde785d9
|
4
|
+
data.tar.gz: e842a3d273e3a99e2d10117149f4a4a0212d26af
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b5ad5ce7ed87604e4da354f683d200da0989c99fd011fa44efee45e3bb48ae71864d61f365b801a9a84e26e91d3313261d5152be16a4f068b17052acde8d1fca
|
7
|
+
data.tar.gz: 588c1a8d06f2987c99e51eb2fb400c7d67df369593798129e8b2f8e96e6a2aa4eb6947ff9d4a4aa9fbb532278cbd3b20ac2e91f2064498604c7aad8eed1ad1d9
|
data/README.md
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
# WoopraTrack
|
2
2
|
|
3
|
-
Tracking library for woopra.com. Woopra analytics client-side and server-side tracking helper.
|
3
|
+
Tracking library for [woopra.com](https://www.woopra.com). Woopra analytics client-side and server-side tracking helper.
|
4
|
+
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/woopra_track.svg)](https://badge.fury.io/rb/woopra_track)
|
6
|
+
[![Build Status](https://travis-ci.org/hardpixel/woopra-track.svg?branch=master)](https://travis-ci.org/hardpixel/woopra-track)
|
7
|
+
[![Code Climate](https://codeclimate.com/github/hardpixel/woopra-track/badges/gpa.png)](https://codeclimate.com/github/hardpixel/woopra-track)
|
4
8
|
|
5
9
|
## Installation
|
6
10
|
|
@@ -20,7 +24,135 @@ Or install it yourself as:
|
|
20
24
|
|
21
25
|
## Usage
|
22
26
|
|
23
|
-
|
27
|
+
To enable tracker in a ActionController controller, include the `WoopraTrack` concern in your class:
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
class PagesController < ApplicationController
|
31
|
+
include WoopraTrack
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
You can then configure the tracker in your controller. For example, if you want to set up tracking with Woopra on your homepage, the controller should look like and then you will have the `@woopra` instance variable available:
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
class PagesController < ApplicationController
|
39
|
+
def home
|
40
|
+
config = { domain: 'website.com' }
|
41
|
+
woopra(request, config)
|
42
|
+
|
43
|
+
# Your code here...
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
You can also customize all the properties of the woopra during that step by adding them to the `config_hash`. For example, to also update your idle timeout (default: 30 seconds):
|
49
|
+
|
50
|
+
```ruby
|
51
|
+
# Using woopra function
|
52
|
+
config = { domain: 'website.com', idle_timeout: 15000 }
|
53
|
+
woopra(request, config)
|
54
|
+
|
55
|
+
# Using @woopra instance variable
|
56
|
+
@woopra.config({ idle_timeout: 15000 })
|
57
|
+
```
|
58
|
+
|
59
|
+
To add custom visitor properties, you should use the `identify` function:
|
60
|
+
|
61
|
+
```ruby
|
62
|
+
@woopra.identify({
|
63
|
+
email: 'johndoe@website.com',
|
64
|
+
name: 'John Doe',
|
65
|
+
company: 'Business'
|
66
|
+
})
|
67
|
+
```
|
68
|
+
|
69
|
+
If you wish to identify a user without any tracking event, don't forget to `push` the update to woopra:
|
70
|
+
|
71
|
+
```ruby
|
72
|
+
# Push through front-end
|
73
|
+
@woopra.identify(user_hash)
|
74
|
+
@woopra.push
|
75
|
+
|
76
|
+
# Push through back-end
|
77
|
+
@woopra.identify(user_hash)
|
78
|
+
@woopra.push(true)
|
79
|
+
```
|
80
|
+
|
81
|
+
If you wish to track page views, just call `track`:
|
82
|
+
|
83
|
+
``` ruby
|
84
|
+
# Front-end tracking:
|
85
|
+
@woopra.track
|
86
|
+
|
87
|
+
# Back-end tracking:
|
88
|
+
@woopra.track(true)
|
89
|
+
```
|
90
|
+
|
91
|
+
You can also track custom events through the front-end or the back-end. With all the previous steps done at once, your controller should look like:
|
92
|
+
|
93
|
+
``` ruby
|
94
|
+
class PagesController < ApplicationController
|
95
|
+
include WoopraTrack
|
96
|
+
|
97
|
+
def home
|
98
|
+
# Initialize and configure woopra tracker
|
99
|
+
config = { domain: 'website.com', idle_timeout: 15000 }
|
100
|
+
woopra(request, config)
|
101
|
+
|
102
|
+
# Identify user
|
103
|
+
@woopra.identify({
|
104
|
+
email: 'johndoe@website.com',
|
105
|
+
name: 'John Doe',
|
106
|
+
company: 'Business'
|
107
|
+
})
|
108
|
+
|
109
|
+
# Track a custom event through the front end...
|
110
|
+
@woopra.track('play', {
|
111
|
+
artist: 'Dave Brubeck',
|
112
|
+
song: 'Take Five',
|
113
|
+
genre: 'Jazz'
|
114
|
+
})
|
115
|
+
|
116
|
+
# ... and through the back end by passing the optional argument `true`
|
117
|
+
@woopra.track('signup', {
|
118
|
+
company: 'Business',
|
119
|
+
username: 'johndoe',
|
120
|
+
plan: 'Gold'
|
121
|
+
}, true)
|
122
|
+
|
123
|
+
# Enable front-end tracking
|
124
|
+
@woopra.track
|
125
|
+
|
126
|
+
# Your code here...
|
127
|
+
end
|
128
|
+
end
|
129
|
+
```
|
130
|
+
|
131
|
+
and add the code in your template's header (here `home.html.erb`)
|
132
|
+
|
133
|
+
```erb
|
134
|
+
<!DOCTYPE html>
|
135
|
+
<html>
|
136
|
+
<head>
|
137
|
+
<!-- Your header here... -->
|
138
|
+
<%= woopra_javascript_tag %>
|
139
|
+
</head>
|
140
|
+
<body>
|
141
|
+
<!-- Your body here... -->
|
142
|
+
</body>
|
143
|
+
</html>
|
144
|
+
```
|
145
|
+
|
146
|
+
Finally, if you wish to track your users only through the back-end, you should set the cookie on your user's browser. However, if you are planning to also use front-end tracking, don't even bother with that step, the JavaScript tracker will handle it for you.
|
147
|
+
|
148
|
+
``` ruby
|
149
|
+
# During initialization
|
150
|
+
config = { domain: 'website.com', idle_timeout: 15000 }
|
151
|
+
woopra(request, config, cookies)
|
152
|
+
|
153
|
+
# Using set cookie function
|
154
|
+
@woopra.set_cookie(cookies)
|
155
|
+
```
|
24
156
|
|
25
157
|
## Development
|
26
158
|
|
data/lib/woopra_track/tracker.rb
CHANGED
@@ -141,16 +141,18 @@ module WoopraTrack
|
|
141
141
|
request_headers = { 'User-Agent' => @request.env['HTTP_USER_AGENT'] }
|
142
142
|
request_response = Typhoeus.get(request_url, headers: request_headers)
|
143
143
|
|
144
|
-
if @logger
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
144
|
+
log_request(request_response) if @logger
|
145
|
+
end
|
146
|
+
|
147
|
+
def log_request(response)
|
148
|
+
if response.success?
|
149
|
+
@logger.info("Woopra") { "Success: #{request_url}" }
|
150
|
+
elsif response.timed_out?
|
151
|
+
@logger.warn("Woopra") { "Timeout: #{request_url}" }
|
152
|
+
elsif response.code == 0
|
153
|
+
@logger.error("Woopra") { "#{response.return_message}, #{request_url}" }
|
154
|
+
else
|
155
|
+
@logger.error("Woopra") { "WOOPRA Failed: #{response.code}, #{request_url}" }
|
154
156
|
end
|
155
157
|
end
|
156
158
|
|
data/lib/woopra_track/version.rb
CHANGED