2022-03-17 11:07:44 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
module ProductAnalyticsTracking
|
|
|
|
include Gitlab::Tracking::Helpers
|
|
|
|
include RedisTracking
|
|
|
|
extend ActiveSupport::Concern
|
|
|
|
|
|
|
|
class_methods do
|
2022-11-06 22:07:49 -05:00
|
|
|
# TODO: Remove once all the events are migrated to #track_custom_event
|
|
|
|
# during https://gitlab.com/groups/gitlab-org/-/epics/8641
|
2022-03-17 11:07:44 -04:00
|
|
|
def track_event(*controller_actions, name:, conditions: nil, destinations: [:redis_hll], &block)
|
|
|
|
custom_conditions = [:trackable_html_request?, *conditions]
|
|
|
|
|
|
|
|
after_action only: controller_actions, if: custom_conditions do
|
|
|
|
route_events_to(destinations, name, &block)
|
|
|
|
end
|
|
|
|
end
|
2022-08-08 20:11:27 -04:00
|
|
|
|
|
|
|
def track_custom_event(*controller_actions, name:, conditions: nil, action:, label:, destinations: [:redis_hll], &block)
|
|
|
|
custom_conditions = [:trackable_html_request?, *conditions]
|
|
|
|
|
|
|
|
after_action only: controller_actions, if: custom_conditions do
|
|
|
|
route_custom_events_to(destinations, name, action, label, &block)
|
|
|
|
end
|
|
|
|
end
|
2022-03-17 11:07:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def route_events_to(destinations, name, &block)
|
|
|
|
track_unique_redis_hll_event(name, &block) if destinations.include?(:redis_hll)
|
|
|
|
|
2022-05-31 14:08:16 -04:00
|
|
|
if destinations.include?(:snowplow) && event_enabled?(name)
|
2022-10-12 23:09:36 -04:00
|
|
|
Gitlab::Tracking.event(
|
|
|
|
self.class.to_s,
|
|
|
|
name,
|
|
|
|
namespace: tracking_namespace_source,
|
|
|
|
user: current_user,
|
|
|
|
context: [Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, event: name).to_context]
|
|
|
|
)
|
2022-03-17 11:07:44 -04:00
|
|
|
end
|
|
|
|
end
|
2022-05-31 14:08:16 -04:00
|
|
|
|
2022-08-08 20:11:27 -04:00
|
|
|
def route_custom_events_to(destinations, name, action, label, &block)
|
|
|
|
track_unique_redis_hll_event(name, &block) if destinations.include?(:redis_hll)
|
|
|
|
|
|
|
|
return unless destinations.include?(:snowplow) && event_enabled?(name)
|
|
|
|
|
|
|
|
optional_arguments = {
|
2022-08-11 20:09:35 -04:00
|
|
|
namespace: tracking_namespace_source,
|
2022-08-08 20:11:27 -04:00
|
|
|
project: tracking_project_source
|
|
|
|
}.compact
|
|
|
|
|
|
|
|
Gitlab::Tracking.event(
|
|
|
|
self.class.to_s,
|
|
|
|
action,
|
|
|
|
user: current_user,
|
|
|
|
property: name,
|
|
|
|
label: label,
|
2022-10-12 23:09:36 -04:00
|
|
|
context: [Gitlab::Tracking::ServicePingContext.new(data_source: :redis_hll, event: name).to_context],
|
2022-08-08 20:11:27 -04:00
|
|
|
**optional_arguments
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
2022-05-31 14:08:16 -04:00
|
|
|
def event_enabled?(event)
|
|
|
|
events_to_ff = {
|
|
|
|
g_analytics_valuestream: :route_hll_to_snowplow,
|
2022-06-20 23:08:34 -04:00
|
|
|
|
|
|
|
i_search_paid: :route_hll_to_snowplow_phase2,
|
|
|
|
i_search_total: :route_hll_to_snowplow_phase2,
|
2022-08-08 20:11:27 -04:00
|
|
|
i_search_advanced: :route_hll_to_snowplow_phase2,
|
2022-08-11 20:09:35 -04:00
|
|
|
i_ecosystem_jira_service_list_issues: :route_hll_to_snowplow_phase2,
|
|
|
|
users_viewing_analytics_group_devops_adoption: :route_hll_to_snowplow_phase2,
|
|
|
|
i_analytics_dev_ops_adoption: :route_hll_to_snowplow_phase2,
|
|
|
|
i_analytics_dev_ops_score: :route_hll_to_snowplow_phase2,
|
|
|
|
p_analytics_merge_request: :route_hll_to_snowplow_phase2,
|
|
|
|
i_analytics_instance_statistics: :route_hll_to_snowplow_phase2,
|
2022-08-19 05:11:29 -04:00
|
|
|
g_analytics_contribution: :route_hll_to_snowplow_phase2,
|
|
|
|
p_analytics_pipelines: :route_hll_to_snowplow_phase2,
|
|
|
|
p_analytics_code_reviews: :route_hll_to_snowplow_phase2,
|
|
|
|
p_analytics_valuestream: :route_hll_to_snowplow_phase2,
|
|
|
|
p_analytics_insights: :route_hll_to_snowplow_phase2,
|
|
|
|
p_analytics_issues: :route_hll_to_snowplow_phase2,
|
2022-09-08 14:10:47 -04:00
|
|
|
p_analytics_repo: :route_hll_to_snowplow_phase2,
|
|
|
|
g_analytics_insights: :route_hll_to_snowplow_phase2,
|
|
|
|
g_analytics_issues: :route_hll_to_snowplow_phase2,
|
|
|
|
g_analytics_productivity: :route_hll_to_snowplow_phase2,
|
|
|
|
i_analytics_cohorts: :route_hll_to_snowplow_phase2
|
2022-05-31 14:08:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Feature.enabled?(events_to_ff[event.to_sym], tracking_namespace_source)
|
|
|
|
end
|
2022-03-17 11:07:44 -04:00
|
|
|
end
|