base.rb
1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class AnalyticsPlugin::Base < Noosfero::Plugin
def body_ending
return unless profile and profile.analytics_enabled?
lambda do
render 'analytics_plugin/body_ending'
end
end
def js_files
['analytics'].map{ |j| "javascripts/#{j}" }
end
def application_controller_filters
[{
type: 'around_filter', options: {}, block: -> &block do
request_started_at = Time.now
block.call
request_finished_at = Time.now
return if @analytics_skip_page_view
return unless profile and profile.analytics_enabled?
Noosfero::Scheduler::Defer.later 'analytics: register page view' do
page_view = profile.page_views.build request: request, profile_id: profile,
request_started_at: request_started_at, request_finished_at: request_finished_at
unless profile.analytics_anonymous?
session_id = session.id
page_view.user = user
page_view.session_id = session_id
end
page_view.save!
end
end,
}]
end
def control_panel_buttons
{
title: I18n.t('analytics_plugin.lib.plugin.panel_button'),
icon: 'analytics-access',
url: {controller: 'analytics_plugin/stats', action: :index}
}
end
end