autometal-piwik 0.3.1 → 0.4.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.
@@ -1,4 +1,4 @@
1
- Copyright (c) 2008 Riopro Informática Ltda
1
+ Copyright (c) 2011 Achillefs Charmpilas - Humbucker Ltd (http://humbuckercode.co.uk/licks)
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,4 +1,3 @@
1
- History.txt
2
1
  License.txt
3
2
  Manifest.txt
4
3
  PostInstall.txt
@@ -9,6 +8,7 @@ autometal-piwik.gemspec
9
8
  lib/piwik.rb
10
9
  lib/piwik/base.rb
11
10
  lib/piwik/site.rb
11
+ lib/piwik/trackable.rb
12
12
  lib/piwik/user.rb
13
13
  script/console
14
14
  script/destroy
@@ -1,6 +1,6 @@
1
1
  = autometal-piwik
2
2
 
3
- * http://github.com/riopro/Achillefs/tree/master
3
+ * http://github.com/Achillefs/tree/master
4
4
  * http://humbuckercode.co.uk/licks/gems/piwik
5
5
 
6
6
  == DESCRIPTION:
@@ -27,10 +27,8 @@ this API in a Ruby-friendly way. For example:
27
27
 
28
28
  user = Piwik::User.load(1, 'http://your.piwi.install', 'some_auth_key')
29
29
  => #<Piwik::User:0xb66bf544 @login="Example.com", @config={:auth_token=>"some_auth_key", :piwik_url=>"http://your.piwi.install"}, @id=1, @main_url="http://www.example.com", @created_at=Tue Jul 15 18:55:40 -0300 2008>
30
- site.pageviews(:month, Date.today)
31
- => 88
32
30
 
33
- Currently, only Piwik::Site simple new / create / save / update methods have been implemented.
31
+ Currently, only Piwik::Site and Piwik::User simple new / create / save / update methods have been implemented.
34
32
 
35
33
  For more information on Piwik and it's API, see the Piwik website (http://piwik.org)
36
34
  and the Piwik API reference (http://dev.piwik.org/trac/wiki/API/Reference).
@@ -48,6 +46,8 @@ RubyGems and the following gems (installed automatically if necessary):
48
46
  sudo gem install autometal-piwik --source=http://gemcutter.org
49
47
 
50
48
  == CHANGELOG:
49
+ * 0.4.0
50
+ Added Piwik::Trackable controller mixing, pretty much swiped off of halfdan's piwik analytics project (https://github.com/halfdan/piwik_analytics/). The version included in this plugin is not suitable for application tracking, and is instead geared towards tracking multiple websites stored as ActiveRecord models
51
51
  * 0.3.0
52
52
  UsersManager CRUD implementation, with tests
53
53
  * 0.2.3
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = %q{autometal-piwik}
5
- s.version = "0.3.1"
5
+ s.version = "0.4.0"
6
6
 
7
7
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
8
  s.authors = ["Achillefs Charmpilas"]
@@ -4,7 +4,7 @@ $:.unshift(File.dirname(__FILE__)) unless
4
4
  require 'piwik/base.rb'
5
5
  require 'piwik/site.rb'
6
6
  require 'piwik/user.rb'
7
-
7
+ require 'piwik/trackable.rb'
8
8
  module Piwik
9
- VERSION = "0.3.1"
9
+ VERSION = "0.4.0"
10
10
  end
@@ -0,0 +1,77 @@
1
+ module Piwik
2
+ module Trackable
3
+ def piwik_tracking_js
4
+ if Config.use_async
5
+ <<-code
6
+ <!-- Piwik -->
7
+ <script type="text/javascript">
8
+ var _paq = _paq || [];
9
+ (function(){
10
+ var u=(("https:" == document.location.protocol) ? "#{Config.url.sub("http:","https:")}/" : "#{Config.url}/");
11
+ _paq.push(['setSiteId', #{@site.piwik_id}]);
12
+ _paq.push(['setTrackerUrl', u+'piwik.php']);
13
+ _paq.push(['trackPageView']);
14
+ var d=document,
15
+ g=d.createElement('script'),
16
+ s=d.getElementsByTagName('script')[0];
17
+ g.type='text/javascript';
18
+ g.defer=true;
19
+ g.async=true;
20
+ g.src=u+'piwik.js';
21
+ s.parentNode.insertBefore(g,s);
22
+ })();
23
+ </script>
24
+ <!-- End Piwik Tag -->
25
+ code
26
+ else
27
+ <<-code
28
+ <!-- Piwik -->
29
+ <script type="text/javascript">
30
+ var pkBaseURL = (("https:" == document.location.protocol) ? "#{Config.url.sub("http:","https:")}/" : "#{Config.url}/");
31
+ document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
32
+ </script><script type="text/javascript">
33
+ try {
34
+ var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", #{@site.piwik_id});
35
+ piwikTracker.trackPageView();
36
+ piwikTracker.enableLinkTracking();
37
+ } catch( err ) {}
38
+ </script>
39
+ <!-- End Piwik Tag -->
40
+ code
41
+ end
42
+ end
43
+
44
+ def add_piwik_analytics_tracking
45
+ if Config.use_async
46
+ self.response.body = response.body.sub!(/<\/[hH][eE][aA][dD]>/, "#{piwik_tracking_js}</head>") if response.body.respond_to?(:sub!)
47
+ else
48
+ self.response.body = response.body.sub!(/<\/[bB][oO][dD][yY]>/, "#{piwik_tracking_js}</body>") if response.body.respond_to?(:sub!)
49
+ end
50
+ end
51
+ end
52
+
53
+ class Config
54
+
55
+ @@use_async = false
56
+ cattr_accessor :use_async
57
+
58
+ @@url = Piwik::Base.load_config_from_file[:piwik_url]
59
+ cattr_accessor :url
60
+
61
+ @@environments = ["production","development"]
62
+ cattr_accessor :environments
63
+
64
+ @@formats = [:html, :all]
65
+ cattr_accessor :formats
66
+
67
+ =begin rdoc
68
+ Checks whether the model can be tracked using piwik by checking for a piwik_id and domain fields.
69
+ This is a pretty specific use case, a more generic application tracking solution is available here:
70
+ https://github.com/Achillefs/piwik_analytics/ (this file is actually swiped from that plugin)
71
+ =end
72
+ def self.enabled?(format)
73
+ raise Piwik::MissingConfiguration if url.blank?
74
+ environments.include?(Rails.env) && formats.include?(format.to_sym)
75
+ end
76
+ end
77
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: autometal-piwik
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
4
+ hash: 15
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Achillefs Charmpilas
@@ -106,13 +106,11 @@ executables: []
106
106
  extensions: []
107
107
 
108
108
  extra_rdoc_files:
109
- - History.txt
110
109
  - License.txt
111
110
  - Manifest.txt
112
111
  - PostInstall.txt
113
112
  - Todo.txt
114
113
  files:
115
- - History.txt
116
114
  - License.txt
117
115
  - Manifest.txt
118
116
  - PostInstall.txt
@@ -123,6 +121,7 @@ files:
123
121
  - lib/piwik.rb
124
122
  - lib/piwik/base.rb
125
123
  - lib/piwik/site.rb
124
+ - lib/piwik/trackable.rb
126
125
  - lib/piwik/user.rb
127
126
  - script/console
128
127
  - script/destroy
@@ -133,7 +132,7 @@ files:
133
132
  - test/piwik_test.rb
134
133
  - test/test_helper.rb
135
134
  has_rdoc: true
136
- homepage: http://github.com/riopro/Achillefs/tree/master
135
+ homepage: http://github.com/Achillefs/tree/master
137
136
  licenses: []
138
137
 
139
138
  post_install_message: |+
@@ -1,9 +0,0 @@
1
- == 0.0.2 2008-07-22
2
-
3
- * Added specs for existing API methods
4
- * Created RubyForge project at http://rubyforge.org/projects/piwik/
5
-
6
- == 0.0.1 2008-07-21
7
-
8
- * 1 major enhancement:
9
- * Initial release