jekyll-analytics 0.1.2

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
+ SHA1:
3
+ metadata.gz: 26b409ff39cfbd5b49df05e30ce2b0a7e928eaf5
4
+ data.tar.gz: 2db63505cd4beef74da2141e440cd5f528c463bc
5
+ SHA512:
6
+ metadata.gz: 72c4284cf709792fe366982228c754febb2e9eddfdb260dd9e753e1e4d73fc56aa8e9954cc17fbab04a0ee4c022702192c9218403913f4c043e4c240796ede56
7
+ data.tar.gz: a964c7e8f8bc0b37722f458220770a837d53cca1fbac3378752b6df2eb5a668efe153efbac5e7e0a6eb4f7baa143cad2920158babeb4ba21d18c37aff738e88d
@@ -0,0 +1,9 @@
1
+ class Analytics
2
+ def initialize(config)
3
+ raise NotImplementedError, "Implement this method in a child class"
4
+ end
5
+
6
+ def render()
7
+ raise NotImplementedError, "Implement this method in a child class"
8
+ end
9
+ end
@@ -0,0 +1,45 @@
1
+ require_relative 'Analytics'
2
+
3
+ class GoogleAnalytics < Analytics
4
+ #source: https://developers.google.com/analytics/devguides/collection/analyticsjs/
5
+ SETUP_CODE = """
6
+ <!-- Google Analytics -->
7
+ <script>
8
+ (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
9
+ (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
10
+ m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
11
+ })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
12
+
13
+ %s
14
+ </script>
15
+ <!-- End Google Analytics -->
16
+ """
17
+
18
+ ID_REGEX = /^UA-\d+-\d+$/
19
+
20
+ INITIALIZE_CODE = "ga('create', '%s', 'auto');"
21
+ PAGEVIEW_CODE = "ga('send', 'pageview');"
22
+ ANONYMIZE_IP_CODE = "ga('set', 'anonymizeIp', %s);"
23
+
24
+ @@commands = nil
25
+
26
+ def initialize(config)
27
+ if !(ID_REGEX.match(config["id"]))
28
+ raise ArgumentError, 'Invalid Google analytics key. Id must look like UA-XXXXXX-Y'
29
+ end
30
+
31
+ @@commands = []
32
+ @@commands.push(INITIALIZE_CODE % config["id"])
33
+ @@commands.push(PAGEVIEW_CODE)
34
+ self._get_other_commands(config)
35
+ end
36
+
37
+ def render()
38
+ return SETUP_CODE % @@commands.join("\n\t")
39
+ end
40
+
41
+ def _get_other_commands(config)
42
+ @@commands.push(ANONYMIZE_IP_CODE % config.fetch(:anonymizeIp, false))
43
+ end
44
+
45
+ end
@@ -0,0 +1,23 @@
1
+ require_relative 'analytics/GoogleAnalytics'
2
+
3
+ def inject(site)
4
+ if ENV['JEKYLL_ENV']
5
+ config = site.site.config["jekyll_analytics"]["ga"]
6
+ analytics_object = GoogleAnalytics.new(config)
7
+ site.output = site.output.gsub(/(?=<\/head>)/i, analytics_object.render())
8
+ end
9
+ end
10
+
11
+
12
+ Jekyll::Hooks.register :pages, :post_render do |page|
13
+ inject(page)
14
+ end
15
+
16
+ Jekyll::Hooks.register :post, :post_render do |post|
17
+ inject(post)
18
+ end
19
+
20
+ Jekyll::Hooks.register :site, :post_render do |site|
21
+ #puts site.config
22
+ #inject(site)
23
+ end
metadata ADDED
@@ -0,0 +1,46 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-analytics
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Hendrik Schneider
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-04-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Plugin to easily add web analytics to your jekyll site
14
+ email: ''
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/analytics/Analytics.rb
20
+ - lib/analytics/GoogleAnalytics.rb
21
+ - lib/jekyll-analytics.rb
22
+ homepage: https://github.com/hendrik91/jekyll-analytics
23
+ licenses:
24
+ - MIT
25
+ metadata: {}
26
+ post_install_message:
27
+ rdoc_options: []
28
+ require_paths:
29
+ - lib
30
+ required_ruby_version: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - ">="
33
+ - !ruby/object:Gem::Version
34
+ version: '0'
35
+ required_rubygems_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '0'
40
+ requirements: []
41
+ rubyforge_project:
42
+ rubygems_version: 2.5.1
43
+ signing_key:
44
+ specification_version: 4
45
+ summary: Jekyll plugin
46
+ test_files: []