Commit e96846a5 authored by Dallas Reedy's avatar Dallas Reedy Committed by Doug Stull

Add tracking events for trial reassurance experiment

parent c581d371
......@@ -15,6 +15,11 @@ module EE
:trial_getting_started,
:trial_onboarding_board
]
before_action only: :show do
experiment(:trial_registration_with_reassurance, actor: current_user)
.track(:render, label: 'registrations:welcome:show', user: current_user)
end
end
def trial_getting_started
......
......@@ -17,6 +17,18 @@ class TrialRegistrationsController < RegistrationsController
private
# This is called from within the RegistrationsController#create action and is
# given the newly created user.
def after_request_hook(user)
super
return unless user.persisted?
e = experiment(:trial_registration_with_reassurance, actor: user)
e.track(:create_user, label: 'trial_registrations:create', user: user)
e.publish_to_database
end
def set_redirect_url
target_url = new_trial_url(params: request.query_parameters)
......
......@@ -16,10 +16,14 @@ class TrialsController < ApplicationController
feature_category :purchase
def new
experiment(:trial_registration_with_reassurance, actor: current_user)
.track(:render, label: 'trials:new', user: current_user)
record_experiment_user(:remove_known_trial_form_fields_welcoming, remove_known_trial_form_fields_context)
end
def select
experiment(:trial_registration_with_reassurance, actor: current_user)
.track(:render, label: 'trials:select', user: current_user)
end
def create_lead
......@@ -44,6 +48,8 @@ class TrialsController < ApplicationController
record_experiment_user(:remove_known_trial_form_fields_welcoming, namespace_id: @namespace.id)
record_experiment_conversion_event(:remove_known_trial_form_fields_welcoming)
experiment(:trial_registration_with_reassurance, actor: current_user)
.track(:apply_trial, label: 'trials:apply', namespace: @namespace, user: current_user)
experiment(:force_company_trial, user: current_user).track(:create_trial, namespace: @namespace, user: current_user, label: 'trials_controller') if @namespace.created_at > 24.hours.ago
if discover_group_security_flow?
......
......@@ -15,7 +15,10 @@
= render 'devise/shared/sign_in_link'
.row
- experiment(:trial_registration_with_reassurance) do |e|
- experiment(:trial_registration_with_reassurance, actor: current_user) do |e|
- if e.should_track?
%span{ data: { track_action: :render, track_experiment: :trial_registration_with_reassurance } }
- e.use do
.col-md-6.offset-md-3
%h2.gl-text-center.gl-pb-5.gl-my-0
......
......@@ -7,6 +7,25 @@ RSpec.describe Registrations::WelcomeController do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project) }
describe '#show' do
context 'when the trial_registration_with_reassurance experiment is active', :experiment do
before do
sign_in(user)
stub_experiments(trial_registration_with_reassurance: :control)
end
it 'tracks a "render" event' do
expect(experiment(:trial_registration_with_reassurance)).to track(
:render,
user: user,
label: 'registrations:welcome:show'
).with_context(actor: user).on_next_instance
get :show
end
end
end
describe '#continuous_onboarding_getting_started' do
let_it_be(:project) { create(:project, group: group) }
......
......@@ -66,20 +66,40 @@ RSpec.describe TrialRegistrationsController do
before do
stub_application_setting(send_user_confirmation_email: true)
post :create, params: { user: user_params }
end
subject(:post_create) { post :create, params: { user: user_params } }
it_behaves_like 'a dot-com only feature' do
let(:success_status) { :found }
subject { response }
end
it 'marks the account as unconfirmed' do
post_create
expect(User.last).not_to be_confirmed
end
context 'when the trial_registration_with_reassurance experiment is active', :experiment do
before do
stub_experiments(trial_registration_with_reassurance: :control)
end
it 'tracks a "create_user" event & records the actor to the database', :aggregate_failures do
expect(experiment(:trial_registration_with_reassurance)).to track(
:create_user,
user: an_instance_of(User),
label: 'trial_registrations:create'
).with_context(actor: an_instance_of(User)).on_next_instance
expect { post_create }.to change { ExperimentSubject.count }
end
end
context 'derivation of name' do
it 'sets name from first and last name' do
post_create
expect(User.last.name).to eq("#{user_params[:first_name]} #{user_params[:last_name]}")
end
end
......
......@@ -50,15 +50,31 @@ RSpec.describe TrialsController do
end
describe '#new' do
subject do
subject(:get_new) do
get :new
response
end
context 'when the trial_registration_with_reassurance experiment is active', :experiment do
before do
stub_experiments(trial_registration_with_reassurance: :control)
end
it 'tracks a "render" event' do
expect(experiment(:trial_registration_with_reassurance)).to track(
:render,
user: user,
label: 'trials:new'
).with_context(actor: user).on_next_instance
get_new
end
end
it 'calls record_experiment_user for the experiments' do
expect(controller).to receive(:record_experiment_user).with(:remove_known_trial_form_fields_welcoming, remove_known_trial_form_fields_context)
subject
get_new
end
it_behaves_like 'an authenticated endpoint'
......@@ -142,13 +158,29 @@ RSpec.describe TrialsController do
end
describe '#select' do
subject do
subject(:get_select) do
get :select
response
end
it_behaves_like 'an authenticated endpoint'
it_behaves_like 'a dot-com only feature'
context 'when the trial_registration_with_reassurance experiment is active', :experiment do
before do
stub_experiments(trial_registration_with_reassurance: :control)
end
it 'tracks a "render" event' do
expect(experiment(:trial_registration_with_reassurance)).to track(
:render,
user: user,
label: 'trials:select'
).with_context(actor: user).on_next_instance
get_select
end
end
end
describe '#apply' do
......@@ -163,9 +195,10 @@ RSpec.describe TrialsController do
allow_next_instance_of(GitlabSubscriptions::ApplyTrialService) do |service|
allow(service).to receive(:execute).and_return({ success: apply_trial_result })
end
allow(controller).to receive(:experiment).and_call_original
end
subject do
subject(:post_apply) do
post :apply, params: post_params
response
end
......@@ -177,12 +210,30 @@ RSpec.describe TrialsController do
let(:apply_trial_result) { true }
it { is_expected.to redirect_to("/#{namespace.path}?trial=true") }
it 'calls the record conversion method for the experiments' do
expect(controller).to receive(:record_experiment_user).with(:remove_known_trial_form_fields_welcoming, namespace_id: namespace.id)
expect(controller).to receive(:record_experiment_conversion_event).with(:remove_known_trial_form_fields_welcoming)
expect(experiment(:force_company_trial)).to track(:create_trial, namespace: namespace, user: user, label: 'trials_controller').with_context(user: user).on_next_instance
subject
post_apply
end
context 'when the trial_registration_with_reassurance experiment is active', :experiment do
before do
stub_experiments(trial_registration_with_reassurance: :control)
end
it 'tracks an "apply_trial" event' do
expect(experiment(:trial_registration_with_reassurance)).to track(
:apply_trial,
user: user,
namespace: namespace,
label: 'trials:apply'
).with_context(actor: user).on_next_instance
post_apply
end
end
context 'redirect trial user to feature' do
......@@ -210,7 +261,7 @@ RSpec.describe TrialsController do
it 'records the subject' do
expect(Experiment).to receive(:add_subject).with('redirect_trial_user_to_feature', variant: variant, subject: namespace)
subject
post_apply
end
end
end
......@@ -219,7 +270,7 @@ RSpec.describe TrialsController do
let(:post_params) { { new_group_name: 'GitLab' } }
it 'creates the Group' do
expect { subject }.to change { Group.count }.by(1)
expect { post_apply }.to change { Group.count }.by(1)
end
end
......@@ -229,7 +280,7 @@ RSpec.describe TrialsController do
expect(controller).not_to receive(:experiment).with(:force_company_trial, user: user)
subject
post_apply
end
end
end
......@@ -241,7 +292,7 @@ RSpec.describe TrialsController do
it 'does not call the record conversion method for the experiments' do
expect(controller).not_to receive(:record_experiment_conversion_event).with(:remove_known_trial_form_fields_welcoming)
subject
post_apply
end
context 'with a new Group' do
......@@ -250,7 +301,7 @@ RSpec.describe TrialsController do
it { is_expected.to render_template(:select) }
it 'does not create the Group' do
expect { subject }.not_to change { Group.count }
expect { post_apply }.not_to change { Group.count }
end
end
end
......
......@@ -12,27 +12,47 @@ RSpec.describe 'trial_registrations/new.html.haml' do
subject { render && rendered }
describe 'trial_registration_with_reassurance experiment' do
before do
stub_experiments(trial_registration_with_reassurance: trial_registration_with_reassurance_variant)
describe 'trial_registration_with_reassurance experiment', :experiment do
context 'when the experiment is enabled' do
let(:variant) { :control }
before do
stub_experiments(trial_registration_with_reassurance: variant)
end
context 'when in the control' do
it { is_expected.to have_content('Start a Free Ultimate Trial') }
it { is_expected.not_to have_content('Free 30-day trial') }
it { is_expected.not_to have_content('No credit card required.') }
it { is_expected.not_to have_selector('img[alt$=" logo"]') }
end
context 'when in the candidate' do
let(:variant) { :candidate }
it { is_expected.not_to have_content('Start a Free Ultimate Trial') }
it { is_expected.to have_content('Free 30-day trial') }
it { is_expected.to have_content('No credit card required.') }
it { is_expected.to have_selector('img[alt$=" logo"]') }
end
end
context 'when in the control' do
let_it_be(:trial_registration_with_reassurance_variant) { :control }
describe 'tracking page-render using a frontend event' do
context 'when the experiment should be tracked, like when it is enabled' do
before do
stub_experiments(trial_registration_with_reassurance: :control)
end
it { is_expected.to have_content('Start a Free Ultimate Trial') }
it { is_expected.not_to have_content('Free 30-day trial') }
it { is_expected.not_to have_content('No credit card required.') }
it { is_expected.not_to have_selector('img[alt$=" logo"]') }
end
it { is_expected.to have_selector('span[data-track-action="render"]') }
end
context 'when in the candidate' do
let_it_be(:trial_registration_with_reassurance_variant) { :candidate }
context 'when the experiment should not be tracked, like when it is disabled' do
before do
stub_feature_flags(trial_registration_with_reassurance: false)
end
it { is_expected.not_to have_content('Start a Free Ultimate Trial') }
it { is_expected.to have_content('Free 30-day trial') }
it { is_expected.to have_content('No credit card required.') }
it { is_expected.to have_selector('img[alt$=" logo"]') }
it { is_expected.not_to have_selector('span[data-track-action="render"]') }
end
end
end
end
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