Commit 14694fe00d37c1a47c6671f928e2d1d9e035ff8e
Committed by
Daniela Feitosa
1 parent
d74fdaec
Exists in
master
and in
29 other branches
Google Analytics Plugin
- Added 2 new HOTSPOT: profile_data_extras and head_ending (ActionItem2208)
Showing
23 changed files
with
171 additions
and
0 deletions
Show diff stats
app/views/layouts/application-ng.rhtml
| ... | ... | @@ -27,6 +27,11 @@ |
| 27 | 27 | <%= javascript_src_tag plugin.class.public_path(js_file), {} %> |
| 28 | 28 | <% end %> |
| 29 | 29 | <% end %> |
| 30 | + <%= | |
| 31 | + @plugins.map(:head_ending).collect do |content| | |
| 32 | + content.respond_to?(:call) ? content.call : content | |
| 33 | + end.join('\n') | |
| 34 | + %> | |
| 30 | 35 | </head> |
| 31 | 36 | <body class="<%= |
| 32 | 37 | # Identify the current controller and action for the CSS: | ... | ... |
app/views/profile_editor/edit.rhtml
| ... | ... | @@ -75,6 +75,12 @@ |
| 75 | 75 | |
| 76 | 76 | <%= select_categories(:profile_data, _('Select the categories of your interest'), 2) %> |
| 77 | 77 | |
| 78 | + <%= | |
| 79 | + @plugins.map(:profile_editor_extras).each do |content| | |
| 80 | + content.respond_to?(:call) ? content.call : content | |
| 81 | + end.join("\n") | |
| 82 | + %> | |
| 83 | + | |
| 78 | 84 | <% button_bar do %> |
| 79 | 85 | <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> |
| 80 | 86 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> | ... | ... |
lib/noosfero/plugin.rb
| ... | ... | @@ -108,6 +108,12 @@ class Noosfero::Plugin |
| 108 | 108 | nil |
| 109 | 109 | end |
| 110 | 110 | |
| 111 | + # -> Adds content to profile editor info and settings | |
| 112 | + # returns = lambda block that creates html code or raw rhtml/html.erb | |
| 113 | + def profile_editor_extras | |
| 114 | + nil | |
| 115 | + end | |
| 116 | + | |
| 111 | 117 | # -> Adds content to calalog list item |
| 112 | 118 | # returns = lambda block that creates a html code |
| 113 | 119 | def catalog_list_item_extras(item) |
| ... | ... | @@ -140,6 +146,12 @@ class Noosfero::Plugin |
| 140 | 146 | nil |
| 141 | 147 | end |
| 142 | 148 | |
| 149 | + # -> Adds content to the ending of the page head | |
| 150 | + # returns = lambda block that creates html code or raw rhtml/html.erb | |
| 151 | + def head_ending | |
| 152 | + nil | |
| 153 | + end | |
| 154 | + | |
| 143 | 155 | # -> Adds plugins' javascript files to application |
| 144 | 156 | # returns = ['example1.js', 'javascripts/example2.js', 'example3.js'] |
| 145 | 157 | def js_files | ... | ... |
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +h1. Google Analytics | |
| 2 | + | |
| 3 | +Tracking and web analytics to people and communities. | |
| 4 | + | |
| 5 | +h2. Usage | |
| 6 | + | |
| 7 | +* Create a "Google Analytics":http://www.google.com/analytics/ account | |
| 8 | +* Configure your Google Analytics account following these steps | |
| 9 | + | |
| 10 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step1.en.png(Google Setup - Step 1)! | |
| 11 | + | |
| 12 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step2.en.png(Google Setup - Step 2)! | |
| 13 | + | |
| 14 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step3.en.png(Google Setup - Step 3)! | |
| 15 | + | |
| 16 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step4.en.png(Google Setup - Step 4)! | |
| 17 | + | |
| 18 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step5.en.png(Google Setup - Step 5)! | |
| 19 | + | |
| 20 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step6.en.png(Google Setup - Step 6)! | |
| 21 | + | |
| 22 | +* Take note of your Google Analytics Profile ID | |
| 23 | +* Login to Noosfero and go to your control panel | |
| 24 | +* Follow Profile Info and Settings and fill in Google Analytics Profile ID | |
| 25 | + | |
| 26 | +h2. Info | |
| 27 | + | |
| 28 | +* "Google Analytics Support":http://support.google.com/analytics | ... | ... |
| ... | ... | @@ -0,0 +1,31 @@ |
| 1 | +require_dependency 'ext/profile' | |
| 2 | + | |
| 3 | +class GoogleAnalyticsPlugin < Noosfero::Plugin | |
| 4 | + | |
| 5 | + include ActionView::Helpers::JavaScriptHelper | |
| 6 | + include ActionView::Helpers::FormHelper | |
| 7 | + include ApplicationHelper | |
| 8 | + | |
| 9 | + def self.plugin_name | |
| 10 | + "Google Analytics" | |
| 11 | + end | |
| 12 | + | |
| 13 | + def self.plugin_description | |
| 14 | + _("Tracking and web analytics to people and communities") | |
| 15 | + end | |
| 16 | + | |
| 17 | + def profile_id | |
| 18 | + context.profile && context.profile.data[:google_analytics_profile_id] | |
| 19 | + end | |
| 20 | + | |
| 21 | + def head_ending | |
| 22 | + unless profile_id.blank? | |
| 23 | + expanded_template('tracking-code.rhtml',{:profile_id => profile_id}) | |
| 24 | + end | |
| 25 | + end | |
| 26 | + | |
| 27 | + def profile_editor_extras | |
| 28 | + labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => context.profile.google_analytics_profile_id)) | |
| 29 | + end | |
| 30 | + | |
| 31 | +end | ... | ... |
plugins/google_analytics/public/images/doc/google-analytics-setup-step1.en.png
0 → 100644
107 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step1.pt.png
0 → 100644
116 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step2.en.png
0 → 100644
65.5 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step2.pt.png
0 → 100644
86.2 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step3.en.png
0 → 100644
38.7 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step3.pt.png
0 → 100644
56 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step4.en.png
0 → 100644
116 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step4.pt.png
0 → 100644
119 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step5.en.png
0 → 100644
75.4 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step5.pt.png
0 → 100644
83.2 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step6.en.png
0 → 100644
74.6 KB
plugins/google_analytics/test/unit/google_analytics_plugin_test.rb
0 → 100644
| ... | ... | @@ -0,0 +1,38 @@ |
| 1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
| 2 | + | |
| 3 | +class GoogleAnalyticsPluginTest < Test::Unit::TestCase | |
| 4 | + | |
| 5 | + def setup | |
| 6 | + @plugin = GoogleAnalyticsPlugin.new | |
| 7 | + @context = mock() | |
| 8 | + @profile = mock() | |
| 9 | + @profile.stubs(:data).returns({:google_analytics_profile_id => 10}) | |
| 10 | + @profile.stubs(:google_analytics_profile_id).returns(10) | |
| 11 | + @plugin.context = @context | |
| 12 | + @context.stubs(:profile).returns(@profile) | |
| 13 | + end | |
| 14 | + | |
| 15 | + should 'return profile_id nil if not in profile context' do | |
| 16 | + @context.stubs(:profile).returns(nil) | |
| 17 | + assert_nil @plugin.profile_id | |
| 18 | + end | |
| 19 | + | |
| 20 | + should 'return profile_id if in profile context' do | |
| 21 | + assert_not_nil @plugin.profile_id | |
| 22 | + assert_equal 10, @plugin.profile_id | |
| 23 | + end | |
| 24 | + | |
| 25 | + should 'add content at HTML head if profile_id not nil' do | |
| 26 | + @plugin.expects(:expanded_template).once.returns('content') | |
| 27 | + assert_equal 'content', @plugin.head_ending | |
| 28 | + end | |
| 29 | + | |
| 30 | + should 'add extra fields to profile editor info and settings' do | |
| 31 | + assert_tag_in_string @plugin.profile_editor_extras, | |
| 32 | + :tag => 'input', :attributes => {:id => 'profile_data_google_analytics_profile_id', :value => 10} | |
| 33 | + end | |
| 34 | + | |
| 35 | + should 'extends Profile with attr google_analytics_profile_id' do | |
| 36 | + assert_respond_to Profile.new, :google_analytics_profile_id | |
| 37 | + end | |
| 38 | +end | ... | ... |
| ... | ... | @@ -0,0 +1,10 @@ |
| 1 | +<script type="text/javascript"> | |
| 2 | + var _gaq = _gaq || []; | |
| 3 | + _gaq.push(['_setAccount', '<%= escape_javascript locals[:profile_id] %>']); | |
| 4 | + _gaq.push(['_trackPageview']); | |
| 5 | + (function() { | |
| 6 | + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
| 7 | + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
| 8 | + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
| 9 | + })(); | |
| 10 | +</script> | ... | ... |
test/functional/admin_panel_controller_test.rb
| ... | ... | @@ -350,6 +350,7 @@ class AdminPanelControllerTest < Test::Unit::TestCase |
| 350 | 350 | plugins.stubs(:map).with(:admin_panel_links).returns(links) |
| 351 | 351 | plugins.stubs(:enabled_plugins).returns([]) |
| 352 | 352 | plugins.stubs(:map).with(:body_beginning).returns([]) |
| 353 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
| 353 | 354 | Noosfero::Plugin::Manager.stubs(:new).returns(plugins) |
| 354 | 355 | |
| 355 | 356 | get :index | ... | ... |
test/functional/application_controller_test.rb
| ... | ... | @@ -507,6 +507,7 @@ class ApplicationControllerTest < Test::Unit::TestCase |
| 507 | 507 | plugins = mock() |
| 508 | 508 | plugins.stubs(:enabled_plugins).returns([]) |
| 509 | 509 | plugins.stubs(:map).with(:body_beginning).returns(contents) |
| 510 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
| 510 | 511 | Noosfero::Plugin::Manager.stubs(:new).returns(plugins) |
| 511 | 512 | |
| 512 | 513 | get :index |
| ... | ... | @@ -515,6 +516,24 @@ class ApplicationControllerTest < Test::Unit::TestCase |
| 515 | 516 | assert_tag :tag => 'span', :content => 'This is Plugin2 speaking!', :attributes => {:id => 'plugin2'} |
| 516 | 517 | end |
| 517 | 518 | |
| 519 | + should 'include content in the ending of head supplied by plugins regardless it is a block or html code' do | |
| 520 | + plugin1_local_variable = "Plugin1" | |
| 521 | + plugin1_content = lambda {"<script>alert('This is #{plugin1_local_variable} speaking!')</script>"} | |
| 522 | + plugin2_content = "<style>This is Plugin2 speaking!</style>" | |
| 523 | + contents = [plugin1_content, plugin2_content] | |
| 524 | + | |
| 525 | + plugins = mock() | |
| 526 | + plugins.stubs(:enabled_plugins).returns([]) | |
| 527 | + plugins.stubs(:map).with(:head_ending).returns(contents) | |
| 528 | + plugins.stubs(:map).with(:body_beginning).returns([]) | |
| 529 | + Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
| 530 | + | |
| 531 | + get :index | |
| 532 | + | |
| 533 | + assert_tag :tag => 'script', :content => "alert('This is #{plugin1_local_variable} speaking!')" | |
| 534 | + assert_tag :tag => 'style', :content => 'This is Plugin2 speaking!' | |
| 535 | + end | |
| 536 | + | |
| 518 | 537 | if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' |
| 519 | 538 | |
| 520 | 539 | should 'change postgresql schema' do | ... | ... |
test/functional/manage_products_controller_test.rb
| ... | ... | @@ -447,6 +447,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
| 447 | 447 | plugins = mock() |
| 448 | 448 | plugins.stubs(:enabled_plugins).returns([]) |
| 449 | 449 | plugins.stubs(:map).with(:body_beginning).returns([]) |
| 450 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
| 450 | 451 | plugins.stubs(:map).with(:product_info_extras, product).returns(contents) |
| 451 | 452 | Noosfero::Plugin::Manager.stubs(:new).returns(plugins) |
| 452 | 453 | ... | ... |
test/functional/profile_editor_controller_test.rb
| ... | ... | @@ -870,6 +870,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
| 870 | 870 | plugins.stubs(:map).with(:control_panel_buttons).returns(buttons) |
| 871 | 871 | plugins.stubs(:enabled_plugins).returns([]) |
| 872 | 872 | plugins.stubs(:map).with(:body_beginning).returns([]) |
| 873 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
| 873 | 874 | Noosfero::Plugin::Manager.stubs(:new).returns(plugins) |
| 874 | 875 | |
| 875 | 876 | get :index, :profile => profile.identifier |
| ... | ... | @@ -878,4 +879,18 @@ class ProfileEditorControllerTest < Test::Unit::TestCase |
| 878 | 879 | assert_tag :tag => 'a', :content => plugin2_button[:title], :attributes => {:class => /#{plugin2_button[:icon]}/, :href => /#{plugin2_button[:url]}/} |
| 879 | 880 | end |
| 880 | 881 | |
| 882 | + should 'add extra content provided by plugins on edit' do | |
| 883 | + plugin1_content = "<input id='field_added_by_plugin' value='value_of_field_added_by_plugin'/>" | |
| 884 | + plugins = mock() | |
| 885 | + plugins.stubs(:enabled_plugins).returns([]) | |
| 886 | + plugins.stubs(:map).with(:profile_editor_extras).returns([plugin1_content]) | |
| 887 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
| 888 | + plugins.stubs(:map).with(:body_beginning).returns([]) | |
| 889 | + Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
| 890 | + | |
| 891 | + get :edit, :profile => profile.identifier | |
| 892 | + | |
| 893 | + assert_tag :tag => 'input', :attributes => {:id => 'field_added_by_plugin', :value => 'value_of_field_added_by_plugin'} | |
| 894 | + end | |
| 895 | + | |
| 881 | 896 | end | ... | ... |