piwik_analytics 0.9

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ = PiwikAnalytics
2
+
3
+ This plugin enables support for Piwik in your Rails application. By default
4
+ it will output the synchronous piwik tracking code for every page automatically
5
+ (given that it is configured correctly). Configuring this plugin is easy:
6
+
7
+ PiwikAnalytics::Config.id_site = <Site ID>
8
+ PiwikAnalytics::Config.url = <Piwik-URL>
9
+
10
+ Where the <Site ID> the ID of your website inside Piwik. You can look it up
11
+ under Settings -> Websites. <Piwik-URL> must be replaced by the URL to your
12
+ Piwik installation.
13
+
14
+ If you want PiwikAnalytics to use the asynchronous tracking code which was
15
+ introduced in Piwik 1.1 you can add the folliwing line:
16
+
17
+ PiwikAnalytics::Config.use_async = true
18
+
19
+ If you want to disable the tracking code for particular controllers simply add
20
+ the following line to those controllers:
21
+
22
+ skip_after_filter :add_piwik_analytics_tracking
23
+
24
+ Enjoy :)
25
+
26
+
27
+ = Licence
28
+ Copyright(c) 2010-2011 Fabian Becker, released under MIT licence.
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the piwik_analytics plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the piwik_analytics plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'PiwikAnalytics'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
@@ -0,0 +1,79 @@
1
+ # PiwikAnalytics
2
+ require 'active_support'
3
+
4
+ module PiwikAnalytics
5
+ module PiwikAnalyticsMixin
6
+ def piwik_tracking_js
7
+ if Config.use_async
8
+ <<-code
9
+ <!-- Piwik -->
10
+ <script type="text/javascript">
11
+ var _paq = _paq || [];
12
+ (function(){
13
+ var u=(("https:" == document.location.protocol) ? "https://#{Config.url}" : "http://#{Config.url}");
14
+ _paq.push(['setSiteId', #{Config.id_site}]);
15
+ _paq.push(['setTrackerUrl', u+'piwik.php']);
16
+ _paq.push(['trackPageView']);
17
+ var d=document,
18
+ g=d.createElement('script'),
19
+ s=d.getElementsByTagName('script')[0];
20
+ g.type='text/javascript';
21
+ g.defer=true;
22
+ g.async=true;
23
+ g.src=u+'piwik.js';
24
+ s.parentNode.insertBefore(g,s);
25
+ })();
26
+ </script>
27
+ <!-- End Piwik Tag -->
28
+ code
29
+ else
30
+ <<-code
31
+ <!-- Piwik -->
32
+ <script type="text/javascript">
33
+ var pkBaseURL = (("https:" == document.location.protocol) ? "https://#{Config.url}" : "http://#{Config.url}");
34
+ document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
35
+ </script><script type="text/javascript">
36
+ try {
37
+ var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", #{Config.id_site});
38
+ piwikTracker.trackPageView();
39
+ piwikTracker.enableLinkTracking();
40
+ } catch( err ) {}
41
+ </script>
42
+ <!-- End Piwik Tag -->
43
+ code
44
+ end
45
+ end
46
+
47
+ def add_piwik_analytics_tracking
48
+ if Config.use_async
49
+ self.response.body= response.body.sub /<\/[hH][eE][aA][dD]>/, "#{piwik_tracking_js}</head>" if response.body.respond_to?(:sub!)
50
+ else
51
+ self.response.body= response.body.sub! /<\/[bB][oO][dD][yY]>/, "#{piwik_tracking_js}</body>" if response.body.respond_to?(:sub!)
52
+ end
53
+ end
54
+ end
55
+
56
+ class PiwikAnalyticsConfigurationError < StandardError; end
57
+
58
+ class Config
59
+ @@id_site = nil
60
+ cattr_accessor :id_site
61
+
62
+ @@url = nil
63
+ cattr_accessor :url
64
+
65
+ @@use_async = false
66
+ cattr_accessor :use_async
67
+
68
+ @@environments = ["production"]
69
+ cattr_accessor :environments
70
+
71
+ @@formats = [:html, :all]
72
+ cattr_accessor :formats
73
+
74
+ def self.enabled?(format)
75
+ raise PiwikAnalytics::PiwikAnalsyticsConfigurationError if id_site.blank? || url.blank?
76
+ environments.include?(Rails.env) && formats.include?(format.to_sym)
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class PiwikAnalyticsTest < ActiveSupport::TestCase
4
+ # Replace this with your real tests.
5
+ test "the truth" do
6
+ assert true
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'active_support'
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: piwik_analytics
3
+ version: !ruby/object:Gem::Version
4
+ hash: 25
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 9
9
+ version: "0.9"
10
+ platform: ruby
11
+ authors:
12
+ - Fabian Becker
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-30 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: actionpack
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ - !ruby/object:Gem::Dependency
35
+ name: activesupport
36
+ prerelease: false
37
+ requirement: &id002 !ruby/object:Gem::Requirement
38
+ none: false
39
+ requirements:
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ hash: 3
43
+ segments:
44
+ - 0
45
+ version: "0"
46
+ type: :runtime
47
+ version_requirements: *id002
48
+ description: |
49
+ By default this gem will output piwik analytics code forevery page automatically, if it's configured correctly.This is done by adding:
50
+ PiwikAnalytics.IdSite = 1
51
+ PiwikAnalytics.URL = <Piwik-URL>
52
+
53
+ email: halfdan@xnorfz.de
54
+ executables: []
55
+
56
+ extensions: []
57
+
58
+ extra_rdoc_files: []
59
+
60
+ files:
61
+ - MIT-LICENSE
62
+ - README.rdoc
63
+ - Rakefile
64
+ - test/piwik_analytics_test.rb
65
+ - test/test_helper.rb
66
+ - lib/piwik_analytics.rb
67
+ has_rdoc: true
68
+ homepage: https://github.com/halfdan/piwik_analytics/
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options: []
73
+
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.7
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: "[Rails] Easily enable Google Analytics support in your Rails application."
101
+ test_files: []
102
+