gosquared 2.0.2 → 2.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.
- checksums.yaml +4 -4
- data/README.md +18 -17
- data/lib/tracker_inject/injector.rb +40 -34
- data/spec/tracker_inject_spec.rb +65 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 53c41a7e343c373266553d6661997c9717ee2d9f
|
4
|
+
data.tar.gz: d071c532ded3028809e16bdc80ee4b4a475c746e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bbf374a4591cc1180fe06ef14a7e68ecc47190affb728e69f6d59d8f73a904baefeb8c1c2cee57213fbbc1b329e82ab73920167fd3f2cedaad4d6088477ef800
|
7
|
+
data.tar.gz: c933d841cf339acb7ea5b19401956ada2fd993a3e18e1e2aae638d7061c25155460a92bcac9c2e4d6d92324b55157b2d4961e8738435e988bda3fc9981e7a6b5
|
data/README.md
CHANGED
@@ -23,23 +23,6 @@ Then require GoSquared in your application
|
|
23
23
|
require 'gosquared'
|
24
24
|
```
|
25
25
|
|
26
|
-
### Quickly install Analytics and Chat
|
27
|
-
|
28
|
-
GoSquared uses a javascript code snippet to track pageviews and optionally load the GoSquared Live Chat widget.
|
29
|
-
If you want to, you can quickly add the the code to all of your Rails’ views by running this:
|
30
|
-
|
31
|
-
```ruby
|
32
|
-
rails generate gosquared:config 'your_project_token'
|
33
|
-
```
|
34
|
-
|
35
|
-
This will insert a `<script>` tag automatically before the closing `</body>` tag on each view rendered.
|
36
|
-
|
37
|
-
After generating your config file, if there are any controllers you would prefer not to have the tracking code automatically inserted in, you'll just need to add the following to that specific controller:
|
38
|
-
|
39
|
-
```ruby
|
40
|
-
skip_after_action :add_script
|
41
|
-
```
|
42
|
-
|
43
26
|
#Tracking API
|
44
27
|
This is for sending data to GoSquared. It allows you to track:
|
45
28
|
* Events
|
@@ -212,6 +195,24 @@ gs.account.sites.fetch
|
|
212
195
|
```
|
213
196
|
|
214
197
|
|
198
|
+
### Optional install of Analytics and Chat
|
199
|
+
|
200
|
+
While it is not required to make use of our library to interact with our Tracking and Reporting API's, you can also quickly install GoSquared's tracking code on your app. GoSquared uses a javascript code snippet to track pageviews and optionally load the GoSquared Live Chat widget.
|
201
|
+
|
202
|
+
If you don't currently have a GoSquared tracking code on your site, you can quickly add the the code to all of your Rails’ views by running this:
|
203
|
+
|
204
|
+
```ruby
|
205
|
+
rails generate gosquared:config 'your_project_token'
|
206
|
+
```
|
207
|
+
|
208
|
+
This will insert a `<script>` tag automatically before the closing `</body>` tag on each view rendered.
|
209
|
+
|
210
|
+
After generating your config file, if there are any controllers you would prefer not to have the tracking code automatically inserted in, you'll just need to add the following to that specific controller:
|
211
|
+
|
212
|
+
```ruby
|
213
|
+
skip_after_action :add_gosquared_script
|
214
|
+
```
|
215
|
+
|
215
216
|
#Tests
|
216
217
|
|
217
218
|
```ruby
|
@@ -1,39 +1,45 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
1
|
+
class Injector
|
2
|
+
module Filter
|
3
|
+
extend ActiveSupport::Concern
|
4
|
+
included do
|
5
|
+
append_after_filter :add_gosquared_script, :if => :html_response?
|
6
|
+
|
7
|
+
CLOSING_HEAD_TAG = %r{</body>}
|
8
|
+
|
9
|
+
def add_gosquared_script
|
10
|
+
response.body = response.body.gsub(CLOSING_HEAD_TAG, "<script type='text/javascript' async='true'>
|
11
|
+
var trackingCode = function(){
|
12
|
+
!function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(
|
13
|
+
arguments)};d=s.createElement(q);q=s.getElementsByTagName(q)[0];
|
14
|
+
d.src='//d1l6p2sc9645hc.cloudfront.net/tracker.js';q.parentNode.
|
15
|
+
insertBefore(d,q)}(window,document,'script','_gs');
|
16
|
+
_gs('GSN-589158-M'); _gs('set', 'trackLocal', true);
|
17
|
+
_gs('event', '#{request.headers["PATH_INFO"]}', {
|
18
|
+
extra: 'event',
|
19
|
+
details: true
|
20
|
+
});
|
21
|
+
};
|
22
|
+
|
23
|
+
var loadTracker;
|
24
|
+
loadTracker=function(){
|
25
|
+
if(!window._gs) {
|
26
|
+
trackingCode();
|
27
|
+
} else {
|
28
|
+
delete _gs;
|
24
29
|
trackingCode();
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
</script>" + "\n </body>")
|
33
|
-
|
34
|
-
end
|
30
|
+
}
|
31
|
+
};
|
32
|
+
$(document).on('page:load', loadTracker)
|
33
|
+
$(document).on('turbolinks:load', loadTracker);
|
34
|
+
</script>" + "\n </body>"
|
35
|
+
)
|
36
|
+
end
|
35
37
|
|
38
|
+
def html_response?
|
39
|
+
response.content_type == "text/html"
|
36
40
|
end
|
37
|
-
end
|
38
41
|
|
42
|
+
end
|
39
43
|
end
|
44
|
+
|
45
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
if defined?(Rails)
|
4
|
+
|
5
|
+
class ApplicationController < ActionController::Base
|
6
|
+
|
7
|
+
after_filter :add_gosquared_script, :if => :html_response?
|
8
|
+
|
9
|
+
def add_gosquared_script
|
10
|
+
response.body = response.body.gsub(CLOSING_HEAD_TAG, "<script type='text/javascript' async='true'>
|
11
|
+
var trackingCode = function(){
|
12
|
+
!function(g,s,q,r,d){r=g[r]=g[r]||function(){(r.q=r.q||[]).push(
|
13
|
+
arguments)};d=s.createElement(q);q=s.getElementsByTagName(q)[0];
|
14
|
+
d.src='//d1l6p2sc9645hc.cloudfront.net/tracker.js';q.parentNode.
|
15
|
+
insertBefore(d,q)}(window,document,'script','_gs');
|
16
|
+
_gs('GSN-589158-M'); _gs('set', 'trackLocal', true);
|
17
|
+
_gs('event', '#{request.headers["PATH_INFO"]}', {
|
18
|
+
extra: 'event',
|
19
|
+
details: true
|
20
|
+
});
|
21
|
+
};
|
22
|
+
|
23
|
+
var loadTracker;
|
24
|
+
loadTracker=function(){
|
25
|
+
if(!window._gs) {
|
26
|
+
trackingCode();
|
27
|
+
} else {
|
28
|
+
delete _gs;
|
29
|
+
trackingCode();
|
30
|
+
}
|
31
|
+
};
|
32
|
+
$(document).on('page:load', loadTracker)
|
33
|
+
$(document).on('turbolinks:load', loadTracker);
|
34
|
+
</script>" + "\n </body>"
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
def html_response?
|
39
|
+
response.content_type == "text/html"
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe ApplicationController, :type => :controller do
|
44
|
+
controller do
|
45
|
+
def index
|
46
|
+
render :html => true
|
47
|
+
end
|
48
|
+
|
49
|
+
def new
|
50
|
+
render :json => true
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it "adds the GoSquared tracking code if response HTML" do
|
55
|
+
expect(controller).to receive(:add_gosquared_script)
|
56
|
+
get :index
|
57
|
+
end
|
58
|
+
|
59
|
+
it "does not add the GoSquared tracking code if response not HTML" do
|
60
|
+
expect(controller).not_to receive(:add_gosquared_script)
|
61
|
+
get :new
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gosquared
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Russell Vaughan
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- spec/now_spec.rb
|
69
69
|
- spec/people_spec.rb
|
70
70
|
- spec/spec_helper.rb
|
71
|
+
- spec/tracker_inject_spec.rb
|
71
72
|
- spec/tracking_spec.rb
|
72
73
|
- spec/trends_spec.rb
|
73
74
|
homepage: https://github.com/gosquared/ruby-client
|
@@ -90,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
91
|
version: '0'
|
91
92
|
requirements: []
|
92
93
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.
|
94
|
+
rubygems_version: 2.6.6
|
94
95
|
signing_key:
|
95
96
|
specification_version: 4
|
96
97
|
summary: GoSquared Ruby Library
|
@@ -100,5 +101,6 @@ test_files:
|
|
100
101
|
- spec/now_spec.rb
|
101
102
|
- spec/people_spec.rb
|
102
103
|
- spec/spec_helper.rb
|
104
|
+
- spec/tracker_inject_spec.rb
|
103
105
|
- spec/tracking_spec.rb
|
104
106
|
- spec/trends_spec.rb
|