jekyll-analytics-patch 0.1.0
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 +7 -0
- data/lib/analytics/GoogleAnalytics.rb +43 -0
- data/lib/analytics/MPulse.rb +63 -0
- data/lib/analytics/Matomo.rb +43 -0
- data/lib/analytics/Piwik.rb +43 -0
- data/lib/jekyll-analytics.rb +27 -0
- metadata +49 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f1bb4920ad8d9ad08acbd5a15a064e7abff06072
|
4
|
+
data.tar.gz: 37e9a33149822022b69fe1d9da6ff3941d973a55
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cd968ed437a495c6ce7fe97fc79d2e1a7a87324caeef9340eec8c6967423e33e58fa681ee43fbd1179b762e5e66bbb776809006b7659ca6dee959cd5c9c70d4c
|
7
|
+
data.tar.gz: 2f322dbbb7eeb02c99de48c343fe5876e29f30c206aec36851fd4c55c07aa725c8356dab20f73fb748f46225de02886b99f2470db8980d28147f978f000c8021
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class GoogleAnalytics
|
2
|
+
#source: https://developers.google.com/analytics/devguides/collection/analyticsjs/
|
3
|
+
SETUP_CODE = """
|
4
|
+
<!-- Google Analytics -->
|
5
|
+
<script>
|
6
|
+
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
7
|
+
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
8
|
+
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
9
|
+
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
10
|
+
|
11
|
+
%s
|
12
|
+
</script>
|
13
|
+
<!-- End Google Analytics -->
|
14
|
+
"""
|
15
|
+
|
16
|
+
ID_RE = /^UA-\d+-\d+$/
|
17
|
+
|
18
|
+
INITIALIZE_CODE = "ga('create', '%s', 'auto');"
|
19
|
+
PAGEVIEW_CODE = "ga('send', 'pageview', { 'page': location.pathname + location.search + location.hash});"
|
20
|
+
ANONYMIZE_IP_CODE = "ga('set', 'anonymizeIp', %s);"
|
21
|
+
|
22
|
+
|
23
|
+
def initialize(config)
|
24
|
+
if !(ID_RE.match(config["id"]))
|
25
|
+
raise ArgumentError, 'Invalid Google analytics key. Id must look like UA-XXXXXX-Y'
|
26
|
+
end
|
27
|
+
|
28
|
+
@commands = []
|
29
|
+
@commands.push(INITIALIZE_CODE % config["id"])
|
30
|
+
@commands.push(PAGEVIEW_CODE)
|
31
|
+
_get_other_commands(config)
|
32
|
+
end
|
33
|
+
|
34
|
+
def render()
|
35
|
+
return SETUP_CODE % @commands.join("\n\t")
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def _get_other_commands(config)
|
41
|
+
@commands.push(ANONYMIZE_IP_CODE % config.fetch(:anonymizeIp, false))
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
class MPulse
|
2
|
+
#source: https://docs.soasta.com/boomerang/#mpulse-loader-snippet
|
3
|
+
MPULSE_LOADER = """
|
4
|
+
<!-- mPulse -->
|
5
|
+
<script>
|
6
|
+
(function(API_KEY){
|
7
|
+
if (window.BOOMR && window.BOOMR.version) { return; }
|
8
|
+
var dom, doc, where, iframe = document.createElement(\"iframe\"), win = window;
|
9
|
+
|
10
|
+
function boomerangSaveLoadTime(e) {
|
11
|
+
win.BOOMR_onload=(e && e.timeStamp) || new Date().getTime();
|
12
|
+
}
|
13
|
+
|
14
|
+
if (win.addEventListener) {
|
15
|
+
win.addEventListener(\"load\", boomerangSaveLoadTime, false);
|
16
|
+
} else if (win.attachEvent) {
|
17
|
+
win.attachEvent(\"onload\", boomerangSaveLoadTime);
|
18
|
+
}
|
19
|
+
|
20
|
+
iframe.src = \"javascript:void(0)\";
|
21
|
+
iframe.title = \"\";
|
22
|
+
iframe.role = \"presentation\";
|
23
|
+
(iframe.frameElement || iframe).style.cssText = \"width:0;height:0;border:0;display:none;\";
|
24
|
+
where = document.getElementsByTagName(\"script\")[0];
|
25
|
+
where.parentNode.insertBefore(iframe, where);
|
26
|
+
|
27
|
+
try {
|
28
|
+
doc = iframe.contentWindow.document;
|
29
|
+
} catch(e) {
|
30
|
+
dom = document.domain;
|
31
|
+
iframe.src = \"javascript:var d=document.open();d.domain='\"+dom+\"';void(0);\";
|
32
|
+
doc = iframe.contentWindow.document;
|
33
|
+
}
|
34
|
+
|
35
|
+
doc.open()._l = function() {
|
36
|
+
var js = this.createElement(\"script\");
|
37
|
+
if (dom) { this.domain = dom; }
|
38
|
+
js.id = \"boomr-if-as\";
|
39
|
+
js.src = \"https://s.go-mpulse.net/boomerang/\" + API_KEY;
|
40
|
+
BOOMR_lstart = new Date().getTime();
|
41
|
+
this.body.appendChild(js);
|
42
|
+
};
|
43
|
+
doc.write('<body onload=\"document._l();\">');
|
44
|
+
doc.close();
|
45
|
+
})(\"%s\");
|
46
|
+
</script>
|
47
|
+
<!-- End mPulse -->
|
48
|
+
"""
|
49
|
+
|
50
|
+
APIKEY_RE = /^[a-zA-Z2-9]{5}-[a-zA-Z2-9]{5}-[a-zA-Z2-9]{5}-[a-zA-Z2-9]{5}-[a-zA-Z2-9]{5}$/
|
51
|
+
|
52
|
+
def initialize(config)
|
53
|
+
if !(APIKEY_RE.match(config["apikey"]))
|
54
|
+
raise ArgumentError, 'Invalid mPulse API key. Id must look like XXXXX-XXXXX-XXXXX-XXXXX-XXXXX'
|
55
|
+
end
|
56
|
+
|
57
|
+
@apikey = config["apikey"]
|
58
|
+
end
|
59
|
+
|
60
|
+
def render()
|
61
|
+
return MPULSE_LOADER % @apikey
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Matomo
|
2
|
+
SETUP_CODE = """
|
3
|
+
<!-- Matomo -->
|
4
|
+
<script type=\"text/javascript\">
|
5
|
+
var _paq = _paq || [];
|
6
|
+
_paq.push(['trackPageView']);
|
7
|
+
_paq.push(['enableLinkTracking']);
|
8
|
+
(function() {
|
9
|
+
var u='//'+\"%{url}\";
|
10
|
+
_paq.push(['setTrackerUrl', u+'piwik.php']);
|
11
|
+
_paq.push(['setSiteId', '%{siteId}']);
|
12
|
+
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
13
|
+
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
|
14
|
+
})();
|
15
|
+
</script>
|
16
|
+
<!-- End Matomo Code -->
|
17
|
+
"""
|
18
|
+
|
19
|
+
|
20
|
+
# domain name (characters separated by a dot), optional port, optional URI path, no slash
|
21
|
+
DOMAINPATH_RE = /^(([^.\/?#@:]+\.)*[^.\/?#@:]+)+(:[0-9]+)?(\/[^\/?#@:]+)*$/
|
22
|
+
|
23
|
+
# numeric ID
|
24
|
+
SITEID_RE = /^\d+$/
|
25
|
+
|
26
|
+
def initialize(config)
|
27
|
+
|
28
|
+
if !(DOMAINPATH_RE.match(config['url']))
|
29
|
+
raise ArgumentError, 'Invalid url. Must be a domain name, optionally followed by an URI path, no trailing slash (e.g. matomo.example.com or my.matomo.server/path)'
|
30
|
+
end
|
31
|
+
|
32
|
+
if !(SITEID_RE.match(config['siteId']))
|
33
|
+
raise ArgumentError, 'Invalid site id. Must be a number.'
|
34
|
+
end
|
35
|
+
|
36
|
+
@config = Hash[config.map{ |k, v| [k.to_sym, v.to_s] }]
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def render
|
41
|
+
return SETUP_CODE % @config
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
class Piwik
|
2
|
+
SETUP_CODE = """
|
3
|
+
<!-- Piwik -->
|
4
|
+
<script type=\"text/javascript\">
|
5
|
+
var _paq = _paq || [];
|
6
|
+
_paq.push(['trackPageView']);
|
7
|
+
_paq.push(['enableLinkTracking']);
|
8
|
+
(function() {
|
9
|
+
var u='//'+\"%{url}\";
|
10
|
+
_paq.push(['setTrackerUrl', u+'/piwik.php']);
|
11
|
+
_paq.push(['setSiteId', '%{siteId}']);
|
12
|
+
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
|
13
|
+
g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'/piwik.js'; s.parentNode.insertBefore(g,s);
|
14
|
+
})();
|
15
|
+
</script>
|
16
|
+
<!-- End Piwik Code -->
|
17
|
+
"""
|
18
|
+
|
19
|
+
|
20
|
+
# domain name (characters separated by a dot), optional port, optional URI path, no slash
|
21
|
+
DOMAINPATH_RE = /^(([^.\/?#@:]+\.)*[^.\/?#@:]+)+(:[0-9]+)?(\/[^\/?#@:]+)*$/
|
22
|
+
|
23
|
+
# numeric ID
|
24
|
+
SITEID_RE = /^\d+$/
|
25
|
+
|
26
|
+
def initialize(config)
|
27
|
+
|
28
|
+
if !(DOMAINPATH_RE.match(config['url']))
|
29
|
+
raise ArgumentError, 'Invalid url. Must be a domain name, optionally followed by an URI path, no trailing slash (e.g. piwik.example.com or my.piwik.server/path)'
|
30
|
+
end
|
31
|
+
|
32
|
+
if !(SITEID_RE.match(config['siteId']))
|
33
|
+
raise ArgumentError, 'Invalid site id. Must be a number.'
|
34
|
+
end
|
35
|
+
|
36
|
+
@config = Hash[config.map{ |k, v| [k.to_sym, v.to_s] }]
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def render
|
41
|
+
return SETUP_CODE % @config
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) + '/analytics/*.rb'].each {|file| require file[0..-4] }
|
2
|
+
|
3
|
+
CONFIG_KEY = "jekyll_analytics"
|
4
|
+
|
5
|
+
def inject(site)
|
6
|
+
if ENV['JEKYLL_ENV']
|
7
|
+
site.site.config[CONFIG_KEY].keys().each{ |a|
|
8
|
+
analyzerClass = Module.const_get(a)
|
9
|
+
config = site.site.config[CONFIG_KEY][a]
|
10
|
+
analytics_object = analyzerClass.new(config)
|
11
|
+
site.output = site.output.gsub(/(?=<\/head>)/i, analytics_object.render())
|
12
|
+
}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Jekyll::Hooks.register :pages, :post_render do |page|
|
17
|
+
inject(page)
|
18
|
+
end
|
19
|
+
|
20
|
+
Jekyll::Hooks.register :posts, :post_render do |post|
|
21
|
+
inject(post)
|
22
|
+
end
|
23
|
+
|
24
|
+
Jekyll::Hooks.register :site, :post_render do |site|
|
25
|
+
#puts site.config
|
26
|
+
#inject(site)
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jekyll-analytics-patch
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jam Risser
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-21 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: 'Plugin to easily add web analytics to your jekyll site without modifying
|
14
|
+
your templates. Supported are: Google Analytics, Piwik, Matomo, MPulse'
|
15
|
+
email: ''
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- lib/analytics/GoogleAnalytics.rb
|
21
|
+
- lib/analytics/MPulse.rb
|
22
|
+
- lib/analytics/Matomo.rb
|
23
|
+
- lib/analytics/Piwik.rb
|
24
|
+
- lib/jekyll-analytics.rb
|
25
|
+
homepage: https://github.com/jamrizzi/jekyll-analytics-patch
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.6.14
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Jekyll plugin
|
49
|
+
test_files: []
|