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
def new
if experiment_enabled?(:paid_signup_flow)
return if current_user
store_location_for :user, request.fullpath
redirect_to new_user_registration_path
if current_user
track_paid_signup_flow_event('start')
else
store_location_for :user, request.fullpath
redirect_to new_user_registration_path
end
else
redirect_to customer_portal_new_subscription_url
end
......@@ -57,12 +59,30 @@ class SubscriptionsController < ApplicationController
subscription_params: subscription_params
).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]
end
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
params.require(:customer).permit(:country, :address_1, :address_2, :city, :state, :zip_code, :company)
end
......
......@@ -32,6 +32,12 @@ describe SubscriptionsController do
it { is_expected.to render_template 'layouts/checkout' }
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
......@@ -96,14 +102,18 @@ describe SubscriptionsController do
describe 'POST #create' do
subject do
post :create,
params: {
setup_for_company: setup_for_company,
customer: { company: 'My company', country: 'NL' },
subscription: { plan_id: 'x' }
},
params: params,
as: :json
end
let(:params) do
{
setup_for_company: setup_for_company,
customer: { company: 'My company', country: 'NL' },
subscription: { plan_id: 'x', quantity: 2 }
}
end
let(:setup_for_company) { true }
context 'with unauthorized user' do
......@@ -124,14 +134,44 @@ describe SubscriptionsController 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)
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
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 }
it 'does not update the setup_for_company attribute of the current user' do
expect { subject }.not_to change { user.reload.setup_for_company }
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
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