Commit 4898697d authored by Eugie Limpin's avatar Eugie Limpin Committed by Markus Koller

Track events for logged_out_marketing_header experiment

parent 95f81a81
......@@ -35,6 +35,7 @@ class RegistrationsController < Devise::RegistrationsController
persist_accepted_terms_if_required(new_user)
set_role_required(new_user)
track_experiment_event(new_user)
if pending_approval?
NotificationService.new.new_instance_access_request(new_user)
......@@ -223,6 +224,14 @@ class RegistrationsController < Devise::RegistrationsController
def context_user
current_user
end
def track_experiment_event(new_user)
# Track signed up event to relate it with click "Sign up" button events from
# the experimental logged out header with marketing links. This allows us to
# have a funnel of visitors clicking on the header and those visitors
# signing up and becoming users
experiment(:logged_out_marketing_header, actor: new_user).track(:signed_up) if new_user.persisted?
end
end
RegistrationsController.prepend_mod_with('RegistrationsController')
......@@ -61,6 +61,8 @@ module Groups
delay = Namespaces::InviteTeamEmailService::DELIVERY_DELAY_IN_MINUTES
Namespaces::InviteTeamEmailWorker.perform_in(delay, group.id, current_user.id)
end
track_experiment_event
end
def remove_unallowed_params
......@@ -112,6 +114,15 @@ module Groups
@group.shared_runners_enabled = @group.parent.shared_runners_enabled
@group.allow_descendants_override_disabled_shared_runners = @group.parent.allow_descendants_override_disabled_shared_runners
end
def track_experiment_event
return unless group.persisted?
# Track namespace created events to relate them with signed up events for
# the same experiment. This will let us associate created namespaces to
# users that signed up from the experimental logged out header.
experiment(:logged_out_marketing_header, actor: current_user).track(:namespace_created, namespace: group)
end
end
end
......
......@@ -139,15 +139,15 @@
- experiment(:logged_out_marketing_header, actor: nil) do |e|
- e.candidate do
%li.nav-item.gl-display-none.gl-sm-display-block
= link_to _('Sign up now'), new_user_registration_path, class: 'gl-button btn btn-default btn-sign-in'
= link_to _('Sign up now'), new_user_registration_path, class: 'gl-button btn btn-default btn-sign-in', data: { track_action: 'click_button', track_experiment: e.name, track_label: 'sign_up_now' }
%li.nav-item.gl-display-none.gl-sm-display-block
= link_to _('Login'), new_session_path(:user, redirect_to_referer: 'yes')
= render 'layouts/header/sign_in_register_button', class: 'gl-sm-display-none'
- e.try(:trial_focused) do
%li.nav-item.gl-display-none.gl-sm-display-block
= link_to _('Get a free trial'), 'https://about.gitlab.com/free-trial/', class: 'gl-button btn btn-default btn-sign-in'
= link_to _('Get a free trial'), 'https://about.gitlab.com/free-trial/', class: 'gl-button btn btn-default btn-sign-in', data: { track_action: 'click_button', track_experiment: e.name, track_label: 'get_a_free_trial' }
%li.nav-item.gl-display-none.gl-sm-display-block
= link_to _('Sign up'), new_user_registration_path
= link_to _('Sign up'), new_user_registration_path, data: { track_action: 'click_button', track_experiment: e.name, track_label: 'sign_up' }
%li.nav-item.gl-display-none.gl-sm-display-block
= link_to _('Login'), new_session_path(:user, redirect_to_referer: 'yes')
= render 'layouts/header/sign_in_register_button', class: 'gl-sm-display-none'
......
......@@ -456,6 +456,28 @@ RSpec.describe RegistrationsController do
subject
end
describe 'logged_out_marketing_header experiment', :experiment do
before do
stub_experiments(logged_out_marketing_header: :candidate)
end
it 'tracks signed_up event' do
expect(experiment(:logged_out_marketing_header)).to track(:signed_up).on_next_instance
subject
end
context 'when registration fails' do
let_it_be(:user_params) { { user: base_user_params.merge({ username: '' }) } }
it 'does not track signed_up event' do
expect(experiment(:logged_out_marketing_header)).not_to track(:signed_up)
subject
end
end
end
end
describe '#destroy' do
......
......@@ -289,4 +289,33 @@ RSpec.describe Groups::CreateService, '#execute' do
end
end
end
describe 'logged_out_marketing_header experiment', :experiment do
let(:service) { described_class.new(user, group_params) }
subject { service.execute }
before do
stub_experiments(logged_out_marketing_header: :candidate)
end
it 'tracks signed_up event' do
expect(experiment(:logged_out_marketing_header)).to track(
:namespace_created,
namespace: an_instance_of(Group)
).on_next_instance.with_context(actor: user)
subject
end
context 'when group has not been persisted' do
let(:service) { described_class.new(user, group_params.merge(name: '<script>alert("Attack!")</script>')) }
it 'does not track signed_up event' do
expect(experiment(:logged_out_marketing_header)).not_to track(:namespace_created)
subject
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