Commit 7cdb2319 authored by Sam Figueroa's avatar Sam Figueroa

Add differentiation for tracking purchases

- The SubscriptionsController is used for SaaS subscriptions and add-ons
  as well. In order to be able to differentiate these in data analytics
  down the line we need to mark when an add-on was purchased and when it
  was a subscription.

- refs:
  https://gitlab.com/gitlab-data/product-analytics/-/issues/158
  https://gitlab.com/gitlab-data/product-analytics/-/issues/158#note_842168023
  https://gitlab.com/gitlab-org/gitlab/-/issues/342853
parent 7c4d094a
# frozen_string_literal: true # frozen_string_literal: true
class SubscriptionsController < ApplicationController class SubscriptionsController < ApplicationController
SUCCESS_SUBSCRIPTION = 'Success: subscription'
SUCCESS_ADDON = 'Success: add-on'
include InternalRedirect include InternalRedirect
include OneTrustCSP include OneTrustCSP
...@@ -103,7 +105,7 @@ class SubscriptionsController < ApplicationController ...@@ -103,7 +105,7 @@ class SubscriptionsController < ApplicationController
).execute ).execute
if response[:success] if response[:success]
track_purchase message: 'Success', namespace: group track_purchase message: track_success_message, namespace: group
response[:data] = { location: redirect_location(group) } response[:data] = { location: redirect_location(group) }
else else
track_purchase message: response.dig(:data, :errors), namespace: group track_purchase message: response.dig(:data, :errors), namespace: group
...@@ -123,6 +125,14 @@ class SubscriptionsController < ApplicationController ...@@ -123,6 +125,14 @@ class SubscriptionsController < ApplicationController
) )
end end
def track_success_message
addon? ? SUCCESS_ADDON : SUCCESS_SUBSCRIPTION
end
def addon?
Gitlab::Utils.to_boolean(subscription_params[:is_addon], default: false)
end
def redirect_location(group) def redirect_location(group)
return safe_redirect_path(params[:redirect_after_success]) if params[:redirect_after_success] return safe_redirect_path(params[:redirect_after_success]) if params[:redirect_after_success]
......
...@@ -451,7 +451,26 @@ RSpec.describe SubscriptionsController do ...@@ -451,7 +451,26 @@ RSpec.describe SubscriptionsController do
category: 'SubscriptionsController', category: 'SubscriptionsController',
label: 'confirm_purchase', label: 'confirm_purchase',
action: 'click_button', action: 'click_button',
property: 'Success', property: 'Success: subscription',
namespace: selected_group,
user: user
)
end
end
context 'purchasing an addon' do
before do
params[:subscription][:is_addon] = true
end
it 'tracks creation with add-on success message' do
subject
expect_snowplow_event(
category: 'SubscriptionsController',
label: 'confirm_purchase',
action: 'click_button',
property: 'Success: add-on',
namespace: selected_group, namespace: selected_group,
user: user user: user
) )
......
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