debian-mirror-gitlab/lib/gitlab/analytics/unique_visits.rb

40 lines
1.4 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
module Gitlab
module Analytics
class UniqueVisits
2021-04-29 21:17:54 +05:30
def track_visit(*args, **kwargs)
Gitlab::UsageDataCounters::HLLRedisCounter.track_event(*args, **kwargs)
2020-07-28 23:09:34 +05:30
end
2020-10-24 23:57:45 +05:30
# Returns number of unique visitors for given targets in given time frame
#
# @param [String, Array[<String>]] targets ids of targets to count visits on. Special case for :any
# @param [ActiveSupport::TimeWithZone] start_date start of time frame
# @param [ActiveSupport::TimeWithZone] end_date end of time frame
# @return [Integer] number of unique visitors
def unique_visits_for(targets:, start_date: 7.days.ago, end_date: start_date + 1.week)
2020-11-24 15:15:51 +05:30
events = if targets == :analytics
self.class.analytics_events
elsif targets == :compliance
self.class.compliance_events
else
Array(targets)
end
2020-10-24 23:57:45 +05:30
2020-11-24 15:15:51 +05:30
Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: events, start_date: start_date, end_date: end_date)
2020-07-28 23:09:34 +05:30
end
2020-10-24 23:57:45 +05:30
class << self
2020-11-24 15:15:51 +05:30
def analytics_events
2020-10-24 23:57:45 +05:30
Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('analytics')
2020-07-28 23:09:34 +05:30
end
2020-11-24 15:15:51 +05:30
def compliance_events
2020-10-24 23:57:45 +05:30
Gitlab::UsageDataCounters::HLLRedisCounter.events_for_category('compliance')
end
2020-07-28 23:09:34 +05:30
end
end
end
end