Commit bb172a60 authored by nicolasdular's avatar nicolasdular

Track events for paid signup flow

Adds tracking when starting and completing the new sign up flow
to snowplow.
parent db1ee8e8
...@@ -24,10 +24,12 @@ class SubscriptionsController < ApplicationController ...@@ -24,10 +24,12 @@ class SubscriptionsController < ApplicationController
def new def new
if experiment_enabled?(:paid_signup_flow) if experiment_enabled?(:paid_signup_flow)
return if current_user if current_user
track_paid_signup_flow_event('start')
else
store_location_for :user, request.fullpath store_location_for :user, request.fullpath
redirect_to new_user_registration_path redirect_to new_user_registration_path
end
else else
redirect_to customer_portal_new_subscription_url redirect_to customer_portal_new_subscription_url
end end
...@@ -57,12 +59,30 @@ class SubscriptionsController < ApplicationController ...@@ -57,12 +59,30 @@ class SubscriptionsController < ApplicationController
subscription_params: subscription_params subscription_params: subscription_params
).execute ).execute
response[:data] = { location: edit_subscriptions_group_path(group.path) } if response[:success] if response[:success]
response[:data] = { location: edit_subscriptions_group_path(group.path) }
track_paid_signup_flow_event(
'end',
label: subscription_params[:plan_id],
value: subscription_params[:quantity]
)
end
render json: response[:data] render json: response[:data]
end end
private private
def track_paid_signup_flow_event(action, label: nil, value: nil)
::Gitlab::Tracking.event(
'Growth::Acquisition::Experiment::PaidSignUpFlow',
action,
label: label,
value: value
)
end
def customer_params def customer_params
params.require(:customer).permit(:country, :address_1, :address_2, :city, :state, :zip_code, :company) params.require(:customer).permit(:country, :address_1, :address_2, :city, :state, :zip_code, :company)
end end
......
...@@ -32,6 +32,12 @@ describe SubscriptionsController do ...@@ -32,6 +32,12 @@ describe SubscriptionsController do
it { is_expected.to render_template 'layouts/checkout' } it { is_expected.to render_template 'layouts/checkout' }
it { is_expected.to render_template :new } it { is_expected.to render_template :new }
it 'tracks the event with the right parameters' do
expect(Gitlab::Tracking).to receive(:event).with('Growth::Acquisition::Experiment::PaidSignUpFlow', 'start', label: nil, value: nil)
subject
end
end end
end end
...@@ -96,12 +102,16 @@ describe SubscriptionsController do ...@@ -96,12 +102,16 @@ describe SubscriptionsController do
describe 'POST #create' do describe 'POST #create' do
subject do subject do
post :create, post :create,
params: { params: params,
as: :json
end
let(:params) do
{
setup_for_company: setup_for_company, setup_for_company: setup_for_company,
customer: { company: 'My company', country: 'NL' }, customer: { company: 'My company', country: 'NL' },
subscription: { plan_id: 'x' } subscription: { plan_id: 'x', quantity: 2 }
}, }
as: :json
end end
let(:setup_for_company) { true } let(:setup_for_company) { true }
...@@ -124,14 +134,44 @@ describe SubscriptionsController do ...@@ -124,14 +134,44 @@ describe SubscriptionsController do
it 'updates the setup_for_company attribute of the current user' do it 'updates the setup_for_company attribute of the current user' do
expect { subject }.to change { user.reload.setup_for_company }.from(nil).to(true) expect { subject }.to change { user.reload.setup_for_company }.from(nil).to(true)
end end
it 'tracks the event with the right parameters' do
expect(Gitlab::Tracking).to receive(:event).with(
'Growth::Acquisition::Experiment::PaidSignUpFlow',
'end',
label: 'x',
value: 2
)
subject
end
end end
context 'when not setting up for a company' do context 'when not setting up for a company' do
let(:params) do
{
setup_for_company: setup_for_company,
customer: { country: 'NL' },
subscription: { plan_id: 'x', quantity: 1 }
}
end
let(:setup_for_company) { false } let(:setup_for_company) { false }
it 'does not update the setup_for_company attribute of the current user' do it 'does not update the setup_for_company attribute of the current user' do
expect { subject }.not_to change { user.reload.setup_for_company } expect { subject }.not_to change { user.reload.setup_for_company }
end end
it 'tracks the event with the right parameters' do
expect(Gitlab::Tracking).to receive(:event).with(
'Growth::Acquisition::Experiment::PaidSignUpFlow',
'end',
label: 'x',
value: 1
)
subject
end
end end
it 'creates a group' do it 'creates a group' 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