Class: Trackguard::AnalyticsQuery
- Inherits:
-
ApplicationService
- Object
- ApplicationService
- Trackguard::AnalyticsQuery
- Defined in:
- app/services/trackguard/analytics_query.rb
Instance Attribute Summary collapse
-
#recent ⇒ Object
readonly
Returns the value of attribute recent.
-
#top_pages ⇒ Object
readonly
Returns the value of attribute top_pages.
-
#top_referrers ⇒ Object
readonly
Returns the value of attribute top_referrers.
-
#top_sources ⇒ Object
readonly
Returns the value of attribute top_sources.
-
#totals ⇒ Object
readonly
Returns the value of attribute totals.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(scope:, time_scope:, limit:) ⇒ AnalyticsQuery
constructor
A new instance of AnalyticsQuery.
Methods inherited from ApplicationService
Constructor Details
#initialize(scope:, time_scope:, limit:) ⇒ AnalyticsQuery
Returns a new instance of AnalyticsQuery.
5 6 7 8 9 |
# File 'app/services/trackguard/analytics_query.rb', line 5 def initialize(scope:, time_scope:, limit:) @scope = scope @time_scope = time_scope @limit = limit end |
Instance Attribute Details
#recent ⇒ Object (readonly)
Returns the value of attribute recent.
3 4 5 |
# File 'app/services/trackguard/analytics_query.rb', line 3 def recent @recent end |
#top_pages ⇒ Object (readonly)
Returns the value of attribute top_pages.
3 4 5 |
# File 'app/services/trackguard/analytics_query.rb', line 3 def top_pages @top_pages end |
#top_referrers ⇒ Object (readonly)
Returns the value of attribute top_referrers.
3 4 5 |
# File 'app/services/trackguard/analytics_query.rb', line 3 def top_referrers @top_referrers end |
#top_sources ⇒ Object (readonly)
Returns the value of attribute top_sources.
3 4 5 |
# File 'app/services/trackguard/analytics_query.rb', line 3 def top_sources @top_sources end |
#totals ⇒ Object (readonly)
Returns the value of attribute totals.
3 4 5 |
# File 'app/services/trackguard/analytics_query.rb', line 3 def totals @totals end |
Instance Method Details
#call ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/services/trackguard/analytics_query.rb', line 11 def call @totals = { today: @scope.today.count, week: @scope.this_week.count, month: @scope.this_month.count } @top_pages = @time_scope.group(:path).order("count_all DESC").limit(@limit).count @top_referrers = @time_scope.with_referrer.group(:referer).order("count_all DESC").limit(@limit).count @top_sources = @time_scope.with_source.group(:source).order("count_all DESC").limit(@limit).count @recent = @scope.order(created_at: :desc).limit(20).includes(visitor: :whitelisted_ip) self end |