rack-piwik 0.1.3 → 0.2.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.
- data/README.md +1 -0
- data/lib/rack/piwik.rb +2 -2
- data/lib/rack/templates/async.erb +22 -14
- data/lib/rack/templates/sync.erb +26 -0
- metadata +5 -5
data/README.md
CHANGED
data/lib/rack/piwik.rb
CHANGED
@@ -8,7 +8,7 @@ module Rack
|
|
8
8
|
|
9
9
|
def initialize(app, options = {})
|
10
10
|
raise ArgumentError, "piwik_url must be present" unless options[:piwik_url] and !options[:piwik_url].empty?
|
11
|
-
raise ArgumentError, "piwik_id must be present" unless options[:piwik_id] and !options[:piwik_id].empty?
|
11
|
+
raise ArgumentError, "piwik_id must be present" unless options[:piwik_id] and !options[:piwik_id].to_s.empty?
|
12
12
|
@app, @options = app, DEFAULT.merge(options)
|
13
13
|
end
|
14
14
|
|
@@ -27,7 +27,7 @@ module Rack
|
|
27
27
|
def html?; @headers['Content-Type'] =~ /html/; end
|
28
28
|
|
29
29
|
def inject(response)
|
30
|
-
file = 'async'
|
30
|
+
file = 'async'
|
31
31
|
@template ||= ::ERB.new ::File.read ::File.expand_path("../templates/#{file}.erb",__FILE__)
|
32
32
|
response.gsub(%r{</body>}, @template.result(binding) + "</body>")
|
33
33
|
end
|
@@ -1,21 +1,29 @@
|
|
1
1
|
<!-- Piwik -->
|
2
2
|
<script type="text/javascript">
|
3
|
-
var
|
4
|
-
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
|
5
|
-
</script><script type="text/javascript">
|
6
|
-
try {
|
7
|
-
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", <%= @options[:piwik_id]%>);
|
3
|
+
var _paq = _paq || [];
|
8
4
|
|
9
|
-
<%# If this is a 404 page, provide additional information to Piwik %>
|
5
|
+
<%# If this is a 404 page, provide additional information to Piwik - see http://piwik.org/faq/how-to/#faq_60 %>
|
10
6
|
<% if @status.equal?(404) %>
|
11
|
-
|
12
|
-
String(document.location.pathname
|
13
|
-
'/From = ' + String(document.referrer).replace(/\//g,"%2f"));
|
7
|
+
_paq.push(['setDocumentTitle', '404/URL = ' +
|
8
|
+
String(document.location.pathname+document.location.search).replace(/\//g,"%2f") +
|
9
|
+
'/From = ' + String(document.referrer).replace(/\//g,"%2f")]);
|
14
10
|
<% end %>
|
15
11
|
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
_paq.push(["trackPageView"]);
|
13
|
+
_paq.push(["enableLinkTracking"]);
|
14
|
+
|
15
|
+
(function() {
|
16
|
+
var u=(("https:" == document.location.protocol) ? "https" : "http") + "://<%= @options[:piwik_url] %>/";
|
17
|
+
_paq.push(["setTrackerUrl", u+"piwik.php"]);
|
18
|
+
_paq.push(["setSiteId", "<%= @options[:piwik_id] %>"]);
|
19
|
+
var d=document, g=d.createElement("script"), s=d.getElementsByTagName("script")[0]; g.type="text/javascript";
|
20
|
+
g.defer=true; g.async=true; g.src=u+"piwik.js"; s.parentNode.insertBefore(g,s);
|
21
|
+
})();
|
19
22
|
</script>
|
20
|
-
|
21
|
-
<!--
|
23
|
+
|
24
|
+
<!-- Image Tracker -->
|
25
|
+
<noscript>
|
26
|
+
<%# TODO set protocol (HTTP or HTTPS) based on the current protocol according to rack logic %>
|
27
|
+
<img src="http://<%= @options[:piwik_url] %>/piwik.php?idsite=<%= @options[:piwik_id] %>&rec=1" style="border:0" alt="" />
|
28
|
+
</noscript>
|
29
|
+
<!-- End Piwik -->
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<!-- Piwik -->
|
2
|
+
<script type="text/javascript">
|
3
|
+
var pkBaseURL = (("https:" == document.location.protocol) ? "https://<%= @options[:piwik_url]%>/" : "http://<%= @options[:piwik_url]%>/");
|
4
|
+
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
|
5
|
+
</script><script type="text/javascript">
|
6
|
+
try {
|
7
|
+
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", <%= @options[:piwik_id]%>);
|
8
|
+
|
9
|
+
<%# If this is a 404 page, provide additional information to Piwik %>
|
10
|
+
<% if @status.equal?(404) %>
|
11
|
+
piwikTracker.setDocumentTitle('404/URL = ' +
|
12
|
+
String(document.location.pathname + document.location.search).replace(/\//g,"%2f") +
|
13
|
+
'/From = ' + String(document.referrer).replace(/\//g,"%2f"));
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
piwikTracker.trackPageView();
|
17
|
+
piwikTracker.enableLinkTracking();
|
18
|
+
} catch( err ) {}
|
19
|
+
</script>
|
20
|
+
|
21
|
+
<!-- Image Tracker -->
|
22
|
+
<noscript>
|
23
|
+
<%# TODO set protocol (HTTP or HTTPS) based on the current protocol according to rack logic %>
|
24
|
+
<img src="http://<%= @options[:piwik_url] %>/piwik.php?idsite=<%= @options[:piwik_id] %>&rec=1" style="border:0" alt="" />
|
25
|
+
</noscript>
|
26
|
+
<!-- End Piwik -->
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rack-piwik
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,9 +9,9 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-03-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
|
-
description: Simple Rack middleware for implementing
|
14
|
+
description: Simple Rack middleware for implementing Piwik Analytics tracking in your
|
15
15
|
Ruby-Rack based project.
|
16
16
|
email:
|
17
17
|
- maxwell@joindiaspora.com
|
@@ -20,6 +20,7 @@ extensions: []
|
|
20
20
|
extra_rdoc_files: []
|
21
21
|
files:
|
22
22
|
- lib/rack/piwik.rb
|
23
|
+
- lib/rack/templates/sync.erb
|
23
24
|
- lib/rack/templates/async.erb
|
24
25
|
- README.md
|
25
26
|
- LICENSE
|
@@ -43,10 +44,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
44
|
version: '0'
|
44
45
|
requirements: []
|
45
46
|
rubyforge_project:
|
46
|
-
rubygems_version: 1.8.
|
47
|
+
rubygems_version: 1.8.24
|
47
48
|
signing_key:
|
48
49
|
specification_version: 3
|
49
50
|
summary: Rack middleware to inject the Piwik tracking code into outgoing responses.
|
50
51
|
Adapted from rack-google-analytics
|
51
52
|
test_files: []
|
52
|
-
has_rdoc:
|