jekyll-analytics 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26b409ff39cfbd5b49df05e30ce2b0a7e928eaf5
4
- data.tar.gz: 2db63505cd4beef74da2141e440cd5f528c463bc
3
+ metadata.gz: fa278f726aee0536eacff0f2487449e187afe53b
4
+ data.tar.gz: b6ed0d3b81297098cf07da24450df5b588052f25
5
5
  SHA512:
6
- metadata.gz: 72c4284cf709792fe366982228c754febb2e9eddfdb260dd9e753e1e4d73fc56aa8e9954cc17fbab04a0ee4c022702192c9218403913f4c043e4c240796ede56
7
- data.tar.gz: a964c7e8f8bc0b37722f458220770a837d53cca1fbac3378752b6df2eb5a668efe153efbac5e7e0a6eb4f7baa143cad2920158babeb4ba21d18c37aff738e88d
6
+ metadata.gz: af81e55d2d2b3f57ba8d365bb04fc0f795c4407e480111f58ff2ca5ec82f6f63859176aa90ff9a9304cca39c012a4a4065a3c55bc818a8282c73353a21b3cefe
7
+ data.tar.gz: 0bd95ae21095cb470b5d52932c0acfa811605c40ee011c1954e367fbfeeb2cb5445974caf0a08ca7b4b3669c9c9f1f9fad46a7c27fa60740d2ad476d45460047
@@ -1,6 +1,4 @@
1
- require_relative 'Analytics'
2
-
3
- class GoogleAnalytics < Analytics
1
+ class GoogleAnalytics
4
2
  #source: https://developers.google.com/analytics/devguides/collection/analyticsjs/
5
3
  SETUP_CODE = """
6
4
  <!-- Google Analytics -->
@@ -15,31 +13,31 @@ class GoogleAnalytics < Analytics
15
13
  <!-- End Google Analytics -->
16
14
  """
17
15
 
18
- ID_REGEX = /^UA-\d+-\d+$/
16
+ ID_RE = /^UA-\d+-\d+$/
19
17
 
20
18
  INITIALIZE_CODE = "ga('create', '%s', 'auto');"
21
19
  PAGEVIEW_CODE = "ga('send', 'pageview');"
22
20
  ANONYMIZE_IP_CODE = "ga('set', 'anonymizeIp', %s);"
23
-
24
- @@commands = nil
25
-
26
- def initialize(config)
27
- if !(ID_REGEX.match(config["id"]))
21
+
22
+
23
+ def initialize(config)
24
+ if !(ID_RE.match(config["id"]))
28
25
  raise ArgumentError, 'Invalid Google analytics key. Id must look like UA-XXXXXX-Y'
29
26
  end
30
27
 
31
- @@commands = []
32
- @@commands.push(INITIALIZE_CODE % config["id"])
33
- @@commands.push(PAGEVIEW_CODE)
34
- self._get_other_commands(config)
28
+ @commands = []
29
+ @commands.push(INITIALIZE_CODE % config["id"])
30
+ @commands.push(PAGEVIEW_CODE)
31
+ _get_other_commands(config)
35
32
  end
36
33
 
37
34
  def render()
38
- return SETUP_CODE % @@commands.join("\n\t")
35
+ return SETUP_CODE % @commands.join("\n\t")
39
36
  end
40
37
 
38
+ private
39
+
41
40
  def _get_other_commands(config)
42
- @@commands.push(ANONYMIZE_IP_CODE % config.fetch(:anonymizeIp, false))
41
+ @commands.push(ANONYMIZE_IP_CODE % config.fetch(:anonymizeIp, false))
43
42
  end
44
-
45
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
@@ -1,14 +1,18 @@
1
- require_relative 'analytics/GoogleAnalytics'
1
+ Dir[File.dirname(__FILE__) + '/analytics/*.rb'].each {|file| require file[0..-4] }
2
+
3
+ CONFIG_KEY = "jekyll_analytics"
2
4
 
3
5
  def inject(site)
4
6
  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())
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
+ }
8
13
  end
9
14
  end
10
15
 
11
-
12
16
  Jekyll::Hooks.register :pages, :post_render do |page|
13
17
  inject(page)
14
18
  end
metadata CHANGED
@@ -1,23 +1,24 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-analytics
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hendrik Schneider
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-16 00:00:00.000000000 Z
11
+ date: 2017-04-17 00:00:00.000000000 Z
12
12
  dependencies: []
13
- description: Plugin to easily add web analytics to your jekyll site
13
+ description: Plugin to easily add web analytics to your jekyll site without modifying
14
+ your templates
14
15
  email: ''
15
16
  executables: []
16
17
  extensions: []
17
18
  extra_rdoc_files: []
18
19
  files:
19
- - lib/analytics/Analytics.rb
20
20
  - lib/analytics/GoogleAnalytics.rb
21
+ - lib/analytics/Piwik.rb
21
22
  - lib/jekyll-analytics.rb
22
23
  homepage: https://github.com/hendrik91/jekyll-analytics
23
24
  licenses:
@@ -1,9 +0,0 @@
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