simple_analytics_rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/standard.yml +1 -2
- data/CHANGELOG.md +6 -0
- data/README.md +28 -2
- data/lib/simple_analytics_rails.rb +4 -0
- data/lib/simple_analytics_rails/configuration.rb +31 -0
- data/lib/simple_analytics_rails/javascript_script.rb +15 -4
- data/lib/simple_analytics_rails/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24ecd59389ce5332d45f2595aaafd8d70680ad60df7462f6a9d8e8a55f2d825e
|
4
|
+
data.tar.gz: 2195b5ad58cfac26b7fc30afdfef271c85c412e2cb64f992af48f95a79a930d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf583a3cd589a8b2aba05ad95c7ccdf932ecb2db0ff307e816fbd48cdd35572176372fbbd95517c03cb61832bb3753a27da292d6f19864a36421428f72d23bb3
|
7
|
+
data.tar.gz: 4ca87c7c9046b3fb86a66ee163dc307d7824c567ecfb9470e441bbf29df17d65eb539ba3b37e08e0feb3bace42f4a4574ae810450509ca0c173ab23c94143579
|
data/CHANGELOG.md
CHANGED
@@ -4,8 +4,14 @@
|
|
4
4
|
|
5
5
|
[Full Changelog](https://github.com/simpleanalytics/rubyonrails-plugin/compare/v0.1.0...HEAD)
|
6
6
|
|
7
|
+
**Implemented enhancements:**
|
8
|
+
|
9
|
+
- Add more settings [\#10](https://github.com/simpleanalytics/rubyonrails-plugin/issues/10)
|
10
|
+
|
7
11
|
**Merged pull requests:**
|
8
12
|
|
13
|
+
- Adding new settings missed in 0.1.0 [\#11](https://github.com/simpleanalytics/rubyonrails-plugin/pull/11) ([MikeRogers0](https://github.com/MikeRogers0))
|
14
|
+
- Linking to Rubygems.org in Readme [\#9](https://github.com/simpleanalytics/rubyonrails-plugin/pull/9) ([MikeRogers0](https://github.com/MikeRogers0))
|
9
15
|
- Changing name of ENV used for RubyGems API key [\#8](https://github.com/simpleanalytics/rubyonrails-plugin/pull/8) ([MikeRogers0](https://github.com/MikeRogers0))
|
10
16
|
|
11
17
|
## [v0.1.0](https://github.com/simpleanalytics/rubyonrails-plugin/tree/v0.1.0) (2021-04-21)
|
data/README.md
CHANGED
@@ -7,7 +7,9 @@
|
|
7
7
|
<p align="center">
|
8
8
|
<h1 align="center">Simple Analytics Rails</h1>
|
9
9
|
<p align="center">
|
10
|
-
<
|
10
|
+
<a target="_blank" rel="noopener noreferrer" href="https://rubygems.org/gems/simple_analytics_rails">
|
11
|
+
<img src="https://img.shields.io/gem/v/simple_analytics_rails.svg?color=red" />
|
12
|
+
</a>
|
11
13
|
<a href="https://github.com/simpleanalytics/rubyonrails-plugin/blob/main/LICENSE">
|
12
14
|
<img alt="License: MIT" src="https://img.shields.io/badge/license-MIT-brightgreen.svg" target="_blank" />
|
13
15
|
</a>
|
@@ -25,7 +27,7 @@
|
|
25
27
|
|
26
28
|
[Simple Analytics](https://simpleanalytics.com/) is a privacy friendly analytics. No consent required from your visitors!
|
27
29
|
|
28
|
-
This gem adds the [JavaScript Tracking Script](https://docs.simpleanalytics.com/script) to the `<head>` tag of your Ruby on Rails applications.
|
30
|
+
This gem adds the [JavaScript Tracking Script](https://docs.simpleanalytics.com/script) to the `<head>` & `<body>` tag of your Ruby on Rails applications.
|
29
31
|
|
30
32
|
## 🚀 Installation
|
31
33
|
|
@@ -80,6 +82,30 @@ SimpleAnalyticsRails.configure do |configuration|
|
|
80
82
|
# Default is ""
|
81
83
|
configuration.ignore_pages = "/search/*,/account/*,/vouchers"
|
82
84
|
|
85
|
+
# ==> Override variable used for JavaScript Events
|
86
|
+
# https://docs.simpleanalytics.com/events#the-variable-sa_event-is-already-used
|
87
|
+
#
|
88
|
+
# Default is "sa_event"
|
89
|
+
configuration.sa_global = "sa_event"
|
90
|
+
|
91
|
+
# ==> Trigger custom page views
|
92
|
+
# https://docs.simpleanalytics.com/trigger-custom-page-views#use-custom-collection-anyway
|
93
|
+
#
|
94
|
+
# Default is true
|
95
|
+
configuration.auto_collect = true
|
96
|
+
|
97
|
+
# ==> Onload Callback
|
98
|
+
# https://docs.simpleanalytics.com/trigger-custom-page-views#use-custom-collection-anyway
|
99
|
+
#
|
100
|
+
# Default is ""
|
101
|
+
configuration.onload_callback = "onloadCallback()"
|
102
|
+
|
103
|
+
# ==> Custom Domain
|
104
|
+
# https://docs.simpleanalytics.com/bypass-ad-blockers
|
105
|
+
#
|
106
|
+
# Default is ""
|
107
|
+
configuration.custom_domain = "custom.domain.com"
|
108
|
+
|
83
109
|
# ==> Inject JavaScript To Head
|
84
110
|
# You can disable the automatic JavaScript injection if you'd like.
|
85
111
|
#
|
@@ -14,6 +14,10 @@ require_relative "simple_analytics_rails/railtie" if defined?(Rails)
|
|
14
14
|
# configuration.mode = "hash"
|
15
15
|
# configuration.collect_dnt = false
|
16
16
|
# configuration.ignore_pages = "/search/*,/account/*,/vouchers"
|
17
|
+
# configuration.sa_global = "sa_event"
|
18
|
+
# configuration.auto_collect = true
|
19
|
+
# configuration.onload_callback = "onloadCallback()"
|
20
|
+
# configuration.custom_domain = "custom.domain.com"
|
17
21
|
# configuration.enabled = Rails.env.production?
|
18
22
|
# end
|
19
23
|
#
|
@@ -6,11 +6,21 @@ module SimpleAnalyticsRails
|
|
6
6
|
@ignore_pages = ""
|
7
7
|
@collect_dnt = false
|
8
8
|
@enabled = true
|
9
|
+
@custom_domain = ""
|
10
|
+
@auto_collect = true
|
11
|
+
@sa_global = "sa_event"
|
12
|
+
@onload_callback = ""
|
9
13
|
end
|
10
14
|
|
11
15
|
attr_accessor :ignore_pages
|
12
16
|
attr_accessor :hostname
|
13
17
|
attr_accessor :mode
|
18
|
+
attr_accessor :sa_global
|
19
|
+
|
20
|
+
def custom_sa_global?
|
21
|
+
@sa_global != "sa_event"
|
22
|
+
end
|
23
|
+
|
14
24
|
attr_writer :collect_dnt
|
15
25
|
def collect_dnt?
|
16
26
|
@collect_dnt
|
@@ -21,8 +31,29 @@ module SimpleAnalyticsRails
|
|
21
31
|
@enabled
|
22
32
|
end
|
23
33
|
|
34
|
+
attr_writer :custom_domain
|
35
|
+
def script_domain
|
36
|
+
@custom_domain.present? ? @custom_domain : "scripts.simpleanalyticscdn.com"
|
37
|
+
end
|
38
|
+
|
39
|
+
def noscript_domain
|
40
|
+
@custom_domain.present? ? @custom_domain : "queue.simpleanalyticscdn.com"
|
41
|
+
end
|
42
|
+
|
43
|
+
attr_writer :auto_collect
|
44
|
+
def auto_collect?
|
45
|
+
@auto_collect
|
46
|
+
end
|
47
|
+
|
48
|
+
attr_accessor :onload_callback
|
49
|
+
def onload_callback?
|
50
|
+
@onload_callback.present?
|
51
|
+
end
|
52
|
+
|
24
53
|
def to_h
|
25
54
|
{
|
55
|
+
sa_global: custom_sa_global? ? sa_global : nil,
|
56
|
+
auto_collect: auto_collect? ? nil : "false",
|
26
57
|
hostname: @hostname,
|
27
58
|
mode: @mode,
|
28
59
|
collect_dnt: collect_dnt? ? "true" : nil,
|
@@ -9,7 +9,7 @@ module SimpleAnalyticsRails
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def body_html
|
12
|
-
'<noscript><img src="https://
|
12
|
+
'<noscript><img src="https://' + configuration.noscript_domain + '/noscript.gif" alt="" referrerpolicy="no-referrer-when-downgrade" /></noscript>'
|
13
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -17,7 +17,7 @@ module SimpleAnalyticsRails
|
|
17
17
|
def sa_event_script
|
18
18
|
[
|
19
19
|
"<script>",
|
20
|
-
"window.
|
20
|
+
"window.#{configuration.sa_global}=window.#{configuration.sa_global}||function(){a=[].slice.call(arguments);#{configuration.sa_global}.q?#{configuration.sa_global}.q.push(a):#{configuration.sa_global}.q=[a]};",
|
21
21
|
"</script>"
|
22
22
|
].join
|
23
23
|
end
|
@@ -26,16 +26,27 @@ module SimpleAnalyticsRails
|
|
26
26
|
[
|
27
27
|
"<script",
|
28
28
|
configuration_to_html_attributes,
|
29
|
-
|
29
|
+
onload_callback,
|
30
|
+
'async defer src="https://' + configuration.script_domain + '/latest.js"></script>'
|
30
31
|
].compact
|
31
32
|
.reject(&:blank?)
|
32
33
|
.join(" ")
|
33
34
|
end
|
34
35
|
|
36
|
+
def onload_callback
|
37
|
+
if configuration.onload_callback?
|
38
|
+
"onload=\"#{configuration.onload_callback}\""
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
35
42
|
def configuration_to_html_attributes
|
36
|
-
|
43
|
+
configuration.to_h.collect do |key, value|
|
37
44
|
"data-#{key.to_s.tr("_", "-")}=\"#{CGI.escapeHTML(value)}\""
|
38
45
|
end.join(" ")
|
39
46
|
end
|
47
|
+
|
48
|
+
def configuration
|
49
|
+
@configuration ||= SimpleAnalyticsRails.configuration
|
50
|
+
end
|
40
51
|
end
|
41
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_analytics_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Rogers
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: appraisal
|