Commit 647862e0 authored by Kamil Trzciński's avatar Kamil Trzciński

Merge branch '219944-track-clicks-of-contact-sales-buttons' into 'master'

Track clicks of the “Contact sales” & “Upgrade” buttons

See merge request gitlab-org/gitlab!38846
parents 847ae015 091de7cb
...@@ -31,6 +31,18 @@ module BillingPlansHelper ...@@ -31,6 +31,18 @@ module BillingPlansHelper
purchase_link_action == 'upgrade' purchase_link_action == 'upgrade'
end end
def experiment_tracking_data_for_button_click(button_label)
return {} unless Gitlab::Experimentation.enabled?(:contact_sales_btn_in_app)
{
track: {
event: 'click_button',
label: button_label,
property: experiment_tracking_category_and_group(:contact_sales_btn_in_app)
}
}
end
def plan_feature_short_list(plan) def plan_feature_short_list(plan)
return [] unless plan.features return [] unless plan.features
......
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
.card-footer.p-3 .card-footer.p-3
.float-right{ class: ("invisible" unless purchase_link.action == 'upgrade' || is_current_plan) } .float-right{ class: ("invisible" unless purchase_link.action == 'upgrade' || is_current_plan) }
- if show_contact_sales_button?(purchase_link.action) - if show_contact_sales_button?(purchase_link.action)
= link_to s_('BillingPlan|Contact sales'), "#{contact_sales_url}?test=inappcontactsales#{plan.code}", class: "btn btn-success btn-inverted" = link_to s_('BillingPlan|Contact sales'), "#{contact_sales_url}?test=inappcontactsales#{plan.code}", class: "btn btn-success btn-inverted", data: { **experiment_tracking_data_for_button_click('contact_sales') }
- upgrade_button_class = "disabled" if is_current_plan && !namespace.trial_active? - upgrade_button_class = "disabled" if is_current_plan && !namespace.trial_active?
- cta_class = '-new' if use_new_purchase_flow?(namespace) - cta_class = '-new' if use_new_purchase_flow?(namespace)
= link_to s_('BillingPlan|Upgrade'), plan_purchase_or_upgrade_url(namespace, plan, current_plan), class: "btn btn-success #{upgrade_button_class} billing-cta-purchase#{cta_class}" = link_to s_('BillingPlan|Upgrade'), plan_purchase_or_upgrade_url(namespace, plan, current_plan), class: "btn btn-success #{upgrade_button_class} billing-cta-purchase#{cta_class}", data: { **experiment_tracking_data_for_button_click('upgrade') }
...@@ -94,4 +94,37 @@ RSpec.describe BillingPlansHelper do ...@@ -94,4 +94,37 @@ RSpec.describe BillingPlansHelper do
it { is_expected.to eq(result) } it { is_expected.to eq(result) }
end end
end end
describe '#experiment_tracking_data_for_button_click' do
let(:button_label) { 'some_label' }
let(:experiment_enabled) { false }
subject { helper.experiment_tracking_data_for_button_click(button_label) }
before do
stub_experiment(contact_sales_btn_in_app: experiment_enabled)
end
context 'when the experiment is not enabled' do
it { is_expected.to eq({}) }
end
context 'when the experiment is enabled' do
let(:experiment_enabled) { true }
before do
allow(helper).to receive(:experiment_tracking_category_and_group).with(:contact_sales_btn_in_app).and_return("Category:control_group")
end
it 'returns a hash to be used as data-attributes in a view' do
is_expected.to eq({
track: {
event: 'click_button',
label: button_label,
property: 'Category:control_group'
}
})
end
end
end
end end
...@@ -78,7 +78,7 @@ module Gitlab ...@@ -78,7 +78,7 @@ module Gitlab
included do included do
before_action :set_experimentation_subject_id_cookie, unless: :dnt_enabled? before_action :set_experimentation_subject_id_cookie, unless: :dnt_enabled?
helper_method :experiment_enabled? helper_method :experiment_enabled?, :experiment_tracking_category_and_group
end end
def set_experimentation_subject_id_cookie def set_experimentation_subject_id_cookie
...@@ -118,6 +118,10 @@ module Gitlab ...@@ -118,6 +118,10 @@ module Gitlab
::Experiment.add_user(experiment_key, tracking_group(experiment_key), current_user) ::Experiment.add_user(experiment_key, tracking_group(experiment_key), current_user)
end end
def experiment_tracking_category_and_group(experiment_key)
"#{tracking_category(experiment_key)}:#{tracking_group(experiment_key, '_group')}"
end
private private
def dnt_enabled? def dnt_enabled?
...@@ -144,7 +148,7 @@ module Gitlab ...@@ -144,7 +148,7 @@ module Gitlab
{ {
category: tracking_category(experiment_key), category: tracking_category(experiment_key),
action: action, action: action,
property: "#{tracking_group(experiment_key)}_group", property: tracking_group(experiment_key, "_group"),
label: experimentation_subject_id, label: experimentation_subject_id,
value: value value: value
}.compact }.compact
...@@ -154,10 +158,12 @@ module Gitlab ...@@ -154,10 +158,12 @@ module Gitlab
Experimentation.experiment(experiment_key).tracking_category Experimentation.experiment(experiment_key).tracking_category
end end
def tracking_group(experiment_key) def tracking_group(experiment_key, suffix = nil)
return unless Experimentation.enabled?(experiment_key) return unless Experimentation.enabled?(experiment_key)
experiment_enabled?(experiment_key) ? GROUP_EXPERIMENTAL : GROUP_CONTROL group = experiment_enabled?(experiment_key) ? GROUP_EXPERIMENTAL : GROUP_CONTROL
suffix ? "#{group}#{suffix}" : group
end end
def forced_enabled?(experiment_key) def forced_enabled?(experiment_key)
......
...@@ -295,6 +295,19 @@ RSpec.describe Gitlab::Experimentation do ...@@ -295,6 +295,19 @@ RSpec.describe Gitlab::Experimentation do
end end
end end
end end
describe '#experiment_tracking_category_and_group' do
let_it_be(:experiment_key) { :test_something }
subject { controller.experiment_tracking_category_and_group(experiment_key) }
it 'returns a string with the experiment tracking category & group joined with a ":"' do
expect(controller).to receive(:tracking_category).with(experiment_key).and_return('Experiment::Category')
expect(controller).to receive(:tracking_group).with(experiment_key, '_group').and_return('experimental_group')
expect(subject).to eq('Experiment::Category:experimental_group')
end
end
end end
describe '.enabled?' do describe '.enabled?' do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment