diff --git a/plugins/piwik/lib/ext/environment.rb b/plugins/piwik/lib/ext/environment.rb
index 33157e1..cfca2c5 100644
--- a/plugins/piwik/lib/ext/environment.rb
+++ b/plugins/piwik/lib/ext/environment.rb
@@ -2,6 +2,7 @@ require_dependency 'environment'
class Environment
settings_items :piwik_domain
+ settings_items :piwik_path, :default => 'piwik'
settings_items :piwik_site_id
- attr_accessible :piwik_domain, :piwik_site_id
+ attr_accessible :piwik_domain, :piwik_site_id, :piwik_path
end
diff --git a/plugins/piwik/lib/piwik_plugin.rb b/plugins/piwik/lib/piwik_plugin.rb
index a7c3500..45b9cc9 100644
--- a/plugins/piwik/lib/piwik_plugin.rb
+++ b/plugins/piwik/lib/piwik_plugin.rb
@@ -17,7 +17,9 @@ class PiwikPlugin < Noosfero::Plugin
domain = context.environment.piwik_domain
site_id = context.environment.piwik_site_id
unless domain.blank? || site_id.blank?
- expanded_template('tracking-code.rhtml',{:domain => domain, :site_id => site_id})
+ piwik_url = "#{domain}/#{context.environment.piwik_path}"
+ piwik_url = "#{piwik_url}/" unless piwik_url.end_with?('/')
+ expanded_template('tracking-code.rhtml', {:site_id => site_id, :piwik_url => piwik_url})
end
end
diff --git a/plugins/piwik/test/functional/piwik_plugin_test.rb b/plugins/piwik/test/functional/piwik_plugin_test.rb
index 31cb232..c8af9ff 100644
--- a/plugins/piwik/test/functional/piwik_plugin_test.rb
+++ b/plugins/piwik/test/functional/piwik_plugin_test.rb
@@ -19,10 +19,12 @@ class PiwikPluginAdminControllerTest < ActionController::TestCase
should 'update piwik plugin settings' do
assert_nil @environment.reload.piwik_domain
+ assert_equal 'piwik', @environment.reload.piwik_path
assert_nil @environment.reload.piwik_site_id
- post :index, :environment => { :piwik_domain => 'http://something', :piwik_site_id => 10 }
- assert_not_nil @environment.reload.piwik_domain
- assert_not_nil @environment.reload.piwik_site_id
+ post :index, :environment => { :piwik_domain => 'something', :piwik_site_id => 10, :piwik_path => 'some_path' }
+ assert_equal 'something', @environment.reload.piwik_domain
+ assert_equal '10', @environment.reload.piwik_site_id
+ assert_equal 'some_path', @environment.reload.piwik_path
end
end
diff --git a/plugins/piwik/test/unit/piwik_plugin_test.rb b/plugins/piwik/test/unit/piwik_plugin_test.rb
index 17f9450..b4cc49e 100644
--- a/plugins/piwik/test/unit/piwik_plugin_test.rb
+++ b/plugins/piwik/test/unit/piwik_plugin_test.rb
@@ -39,4 +39,19 @@ class PiwikPluginTest < ActiveSupport::TestCase
assert_respond_to Environment.new, :piwik_site_id
end
+ should 'set default path to piwik' do
+ @environment.piwik_domain = 'piwik.domain.example.com'
+ @environment.piwik_site_id = 5
+ @plugin.expects(:expanded_template).with('tracking-code.rhtml', {:site_id => @environment.piwik_site_id, :piwik_url => "piwik.domain.example.com/piwik/"})
+ @plugin.body_ending
+ end
+
+ should 'allow empty path in piwik url' do
+ @environment.piwik_domain = 'piwik.domain.example.com'
+ @environment.piwik_path = ''
+ @environment.piwik_site_id = 5
+ @plugin.expects(:expanded_template).with('tracking-code.rhtml', {:site_id => @environment.piwik_site_id, :piwik_url => "piwik.domain.example.com/"})
+ @plugin.body_ending
+ end
+
end
diff --git a/plugins/piwik/views/piwik_plugin_admin/index.html.erb b/plugins/piwik/views/piwik_plugin_admin/index.html.erb
index 7d8c1bb..12d93a2 100644
--- a/plugins/piwik/views/piwik_plugin_admin/index.html.erb
+++ b/plugins/piwik/views/piwik_plugin_admin/index.html.erb
@@ -4,6 +4,8 @@
<%= labelled_form_field _('Piwik domain'), f.text_field(:piwik_domain) %>
+ <%= labelled_form_field _('Piwik path'), f.text_field(:piwik_path) %>
+
<%= labelled_form_field _('Piwik site id'), f.text_field(:piwik_site_id) %>
<% button_bar do %>
diff --git a/plugins/piwik/views/tracking-code.rhtml b/plugins/piwik/views/tracking-code.rhtml
index 0ff2fcb..b4dfd44 100644
--- a/plugins/piwik/views/tracking-code.rhtml
+++ b/plugins/piwik/views/tracking-code.rhtml
@@ -4,12 +4,12 @@
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
- var u=(("https:" == document.location.protocol) ? "https" : "http") + "://<%= escape_javascript locals[:domain] %>/piwik/";
+ var u=(("https:" == document.location.protocol) ? "https" : "http") + "://<%= escape_javascript locals[:piwik_url] %>";
_paq.push(['setTrackerUrl', u+'piwik.php']);
_paq.push(['setSiteId', <%= escape_javascript locals[:site_id] %>]);
var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
})();
-
+
--
libgit2 0.21.2