jekyll-rushed-analytics 0.1.11

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 12b46c7f4802d6f6de914dc1fa1bc85d8ca0b6e290e5efb7252549dda03afe11
4
+ data.tar.gz: a102175943a3d5a65747c6aa2f3f45cba9ba3789c29dfd63f9c5b32b3a9f1f40
5
+ SHA512:
6
+ metadata.gz: c41e91e83bc017813388b7720d2539b8c52b50d55dbc1fae57cacc7714e21c5c582665e06e9a12e7ccdc99924e298964dc05775b072e0f16007bf53f40c53622
7
+ data.tar.gz: 4d9e1b0f3a2f841faea8bad882fdc3545068369183e348c4c9d6bab4278736d9ad55af5b5e8112732f25a8ab266c30ca9bbd474eb79474d3b4479a2fab5f6129
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'jekyll-rushed-analytics'
3
+ s.version = '0.1.11'
4
+ s.date = '2021-06-07'
5
+ s.summary = "Jekyll plugin that handle analytic like google analytic, mpuls, piwik etc"
6
+ s.description = "Plugin to easily add web analytics to your jekyll site without modifying your templates. Supported are: Google Analytics, Piwik, Matomo, MPulse"
7
+ s.authors = ["Hendrik Schneider", "Adi Prasetyo"]
8
+ s.email = 'monetize.your.times@gmail.com'
9
+ s.files = ["jekyll-rushed-analytics.gemspec", "lib/analytics/GoogleAnalytics.rb",
10
+ "lib/jekyll-rushed-analytics.rb", "lib/analytics/Piwik.rb", "lib/analytics/Matomo.rb",
11
+ "lib/analytics/MPulse.rb"]
12
+ s.homepage = 'https://github.com/ap-automator/jekyll-rushed-analytics'
13
+ s.license = 'MIT'
14
+ s.metadata = { "source_code_uri" => "https://github.com/ap-automator/jekyll-rushed-analytics" }
15
+ end
@@ -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,51 @@
1
+ class Matomo
2
+ SETUP_CODE = """
3
+ <!-- Matomo -->
4
+
5
+ <!-- Matomo Image Tracker -->
6
+ <noscript>
7
+ <img src=\"//%{url}?idsite=%{siteId}&amp;rec=1\" style=\"border:0\" alt=\"\" />
8
+ </noscript>
9
+ <!-- End Matomo -->
10
+
11
+
12
+ <script type=\"text/javascript\">
13
+ var _paq = _paq || [];
14
+ _paq.push(['trackPageView']);
15
+ _paq.push(['enableLinkTracking']);
16
+ (function() {
17
+ var u='//'+\"%{url}\";
18
+ _paq.push(['setTrackerUrl', u+'/piwik.php']);
19
+ _paq.push(['setSiteId', '%{siteId}']);
20
+ var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
21
+ g.type='text/javascript'; g.async=true; g.defer=true; g.src=u+'/piwik.js'; s.parentNode.insertBefore(g,s);
22
+ })();
23
+ </script>
24
+ <!-- End Matomo Code -->
25
+ """
26
+
27
+
28
+ # domain name (characters separated by a dot), optional port, optional URI path, no slash
29
+ DOMAINPATH_RE = /^(([^.\/?#@:]+\.)*[^.\/?#@:]+)+(:[0-9]+)?(\/[^\/?#@:]+)*$/
30
+
31
+ # numeric ID
32
+ SITEID_RE = /^\d+$/
33
+
34
+ def initialize(config)
35
+
36
+ if !(DOMAINPATH_RE.match(config['url']))
37
+ 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)'
38
+ end
39
+
40
+ if !(SITEID_RE.match(config['siteId']))
41
+ raise ArgumentError, 'Invalid site id. Must be a number.'
42
+ end
43
+
44
+ @config = Hash[config.map{ |k, v| [k.to_sym, v.to_s] }]
45
+
46
+ end
47
+
48
+ def render
49
+ return SETUP_CODE % @config
50
+ end
51
+ 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_rushed_analytics"
4
+
5
+ def inject(site)
6
+ if ENV['JEKYLL_ENV'] and site.site.config.has_key? CONFIG_KEY
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,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-rushed-analytics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.11
5
+ platform: ruby
6
+ authors:
7
+ - Hendrik Schneider
8
+ - Adi Prasetyo
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2021-06-07 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: 'Plugin to easily add web analytics to your jekyll site without modifying
15
+ your templates. Supported are: Google Analytics, Piwik, Matomo, MPulse'
16
+ email: monetize.your.times@gmail.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - jekyll-rushed-analytics.gemspec
22
+ - lib/analytics/GoogleAnalytics.rb
23
+ - lib/analytics/MPulse.rb
24
+ - lib/analytics/Matomo.rb
25
+ - lib/analytics/Piwik.rb
26
+ - lib/jekyll-rushed-analytics.rb
27
+ homepage: https://github.com/ap-automator/jekyll-rushed-analytics
28
+ licenses:
29
+ - MIT
30
+ metadata:
31
+ source_code_uri: https://github.com/ap-automator/jekyll-rushed-analytics
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.2.15
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: Jekyll plugin that handle analytic like google analytic, mpuls, piwik etc
51
+ test_files: []