Commit bf1b79e9 authored by Alex Buijs's avatar Alex Buijs

Add in-product marketing emails

By default in-product marketing emails are enabled for
GitLab.com and for unpaid self-managed instances.

Changelog: added
parent c991fc6f
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
module Namespaces module Namespaces
class InProductMarketingEmailsService class InProductMarketingEmailsService
include Gitlab::Experimentation::GroupTypes
TRACKS = { TRACKS = {
create: { create: {
interval_days: [1, 5, 10], interval_days: [1, 5, 10],
...@@ -61,12 +59,6 @@ module Namespaces ...@@ -61,12 +59,6 @@ module Namespaces
attr_reader :track, :interval, :in_product_marketing_email_records attr_reader :track, :interval, :in_product_marketing_email_records
def send_email_for_group(group) def send_email_for_group(group)
if Gitlab.com?
experiment_enabled_for_group = experiment_enabled_for_group?(group)
experiment_add_group(group, experiment_enabled_for_group)
return unless experiment_enabled_for_group
end
users_for_group(group).each do |user| users_for_group(group).each do |user|
if can_perform_action?(user, group) if can_perform_action?(user, group)
send_email(user, group) send_email(user, group)
...@@ -77,15 +69,6 @@ module Namespaces ...@@ -77,15 +69,6 @@ module Namespaces
save_tracked_emails! save_tracked_emails!
end end
def experiment_enabled_for_group?(group)
Gitlab::Experimentation.in_experiment_group?(:in_product_marketing_emails, subject: group)
end
def experiment_add_group(group, experiment_enabled_for_group)
variant = experiment_enabled_for_group ? GROUP_EXPERIMENTAL : GROUP_CONTROL
Experiment.add_group(:in_product_marketing_emails, variant: variant, group: group)
end
def groups_for_track def groups_for_track
onboarding_progress_scope = OnboardingProgress onboarding_progress_scope = OnboardingProgress
.completed_actions_with_latest_in_range(completed_actions, range) .completed_actions_with_latest_in_range(completed_actions, range)
......
...@@ -14,7 +14,6 @@ module Namespaces ...@@ -14,7 +14,6 @@ module Namespaces
def perform def perform
return if paid_self_managed_instance? return if paid_self_managed_instance?
return if setting_disabled? return if setting_disabled?
return if experiment_inactive?
Namespaces::InProductMarketingEmailsService.send_for_all_tracks_and_intervals Namespaces::InProductMarketingEmailsService.send_for_all_tracks_and_intervals
end end
...@@ -28,10 +27,6 @@ module Namespaces ...@@ -28,10 +27,6 @@ module Namespaces
def setting_disabled? def setting_disabled?
!Gitlab::CurrentSettings.in_product_marketing_emails_enabled !Gitlab::CurrentSettings.in_product_marketing_emails_enabled
end end
def experiment_inactive?
Gitlab.com? && !Gitlab::Experimentation.active?(:in_product_marketing_emails)
end
end end
end end
......
---
name: in_product_marketing_emails_experiment_percentage
introduced_by_url: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/50679
rollout_issue_url: https://gitlab.com/gitlab-org/growth/team-tasks/-/issues/303
milestone: "13.9"
type: experiment
group: group::activation
default_enabled: false
...@@ -13,7 +13,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do ...@@ -13,7 +13,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
create(:onboarding_progress, namespace: group, created_at: frozen_time - 2.days, git_write_at: nil) create(:onboarding_progress, namespace: group, created_at: frozen_time - 2.days, git_write_at: nil)
group.add_developer(user) group.add_developer(user)
stub_experiment_for_subject(in_product_marketing_emails: true)
allow(Ability).to receive(:allowed?).with(user, anything, anything).and_return(true) allow(Ability).to receive(:allowed?).with(user, anything, anything).and_return(true)
allow(Notify).to receive(:in_product_marketing_email).and_return(double(deliver_later: nil)) allow(Notify).to receive(:in_product_marketing_email).and_return(double(deliver_later: nil))
end end
......
...@@ -5,60 +5,35 @@ require 'spec_helper' ...@@ -5,60 +5,35 @@ require 'spec_helper'
RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform' do RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
context 'not on gitlab.com' do
let(:is_gitlab_com) { false }
let(:license) { build(:license) } let(:license) { build(:license) }
where(:in_product_marketing_emails_enabled, :experiment_active, :executes_service) do where(:in_product_marketing_emails_enabled, :on_gitlab_dot_com, :paid_license, :executes_service) do
true | true | 1 true | true | true | true
true | false | 1 true | true | false | true
false | false | 0 true | false | true | false
false | true | 0 true | false | false | true
false | true | true | false
false | true | false | false
false | false | true | false
false | false | false | false
end end
with_them do with_them do
context 'with a license' do
before do before do
allow(license).to receive(:paid?).and_return(is_paid) stub_application_setting(in_product_marketing_emails_enabled: in_product_marketing_emails_enabled)
allow(::Gitlab).to receive(:com?).and_return(on_gitlab_dot_com)
allow(License).to receive(:current).and_return(license) allow(License).to receive(:current).and_return(license)
allow(license).to receive(:paid?).and_return(paid_license)
end end
context 'paid' do it 'executes the email service' do
let(:is_paid) { true } if executes_service
let(:executes_service) { 0 } expect(Namespaces::InProductMarketingEmailsService).to receive(:send_for_all_tracks_and_intervals)
else
it_behaves_like 'in-product marketing email' expect(Namespaces::InProductMarketingEmailsService).not_to receive(:send_for_all_tracks_and_intervals)
end
context 'free' do
let(:is_paid) { false }
it_behaves_like 'in-product marketing email'
end
end
context 'without a license' do
before do
allow(License).to receive(:current).and_return(nil)
end end
it_behaves_like 'in-product marketing email' subject.perform
end
end
end
context 'on gitlab.com' do
let(:is_gitlab_com) { true }
where(:in_product_marketing_emails_enabled, :experiment_active, :executes_service) do
true | true | 1
true | false | 0
false | false | 0
false | true | 0
end
with_them do
it_behaves_like 'in-product marketing email'
end end
end end
end end
...@@ -62,9 +62,6 @@ module Gitlab ...@@ -62,9 +62,6 @@ module Gitlab
learn_gitlab_b: { learn_gitlab_b: {
tracking_category: 'Growth::Activation::Experiment::LearnGitLabB', tracking_category: 'Growth::Activation::Experiment::LearnGitLabB',
rollout_strategy: :user rollout_strategy: :user
},
in_product_marketing_emails: {
tracking_category: 'Growth::Activation::Experiment::InProductMarketingEmails'
} }
}.freeze }.freeze
......
...@@ -11,7 +11,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do ...@@ -11,7 +11,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
let(:frozen_time) { Time.zone.parse('23 Mar 2021 10:14:40 UTC') } let(:frozen_time) { Time.zone.parse('23 Mar 2021 10:14:40 UTC') }
let(:previous_action_completed_at) { frozen_time - 2.days } let(:previous_action_completed_at) { frozen_time - 2.days }
let(:current_action_completed_at) { nil } let(:current_action_completed_at) { nil }
let(:experiment_enabled) { true }
let(:user_can_perform_current_track_action) { true } let(:user_can_perform_current_track_action) { true }
let(:actions_completed) { { created_at: previous_action_completed_at, git_write_at: current_action_completed_at } } let(:actions_completed) { { created_at: previous_action_completed_at, git_write_at: current_action_completed_at } }
...@@ -22,7 +21,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do ...@@ -22,7 +21,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
travel_to(frozen_time) travel_to(frozen_time)
create(:onboarding_progress, namespace: group, **actions_completed) create(:onboarding_progress, namespace: group, **actions_completed)
group.add_developer(user) group.add_developer(user)
stub_experiment_for_subject(in_product_marketing_emails: experiment_enabled)
allow(Ability).to receive(:allowed?).with(user, anything, anything).and_return(user_can_perform_current_track_action) allow(Ability).to receive(:allowed?).with(user, anything, anything).and_return(user_can_perform_current_track_action)
allow(Notify).to receive(:in_product_marketing_email).and_return(double(deliver_later: nil)) allow(Notify).to receive(:in_product_marketing_email).and_return(double(deliver_later: nil))
end end
...@@ -85,50 +83,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do ...@@ -85,50 +83,6 @@ RSpec.describe Namespaces::InProductMarketingEmailsService, '#execute' do
end end
end end
describe 'experimentation' do
context 'when on dotcom' do
before do
allow(::Gitlab).to receive(:com?).and_return(true)
end
context 'when the experiment is enabled' do
it 'adds the group as an experiment subject in the experimental group' do
expect(Experiment).to receive(:add_group)
.with(:in_product_marketing_emails, variant: :experimental, group: group)
execute_service
end
end
context 'when the experiment is disabled' do
let(:experiment_enabled) { false }
it 'adds the group as an experiment subject in the control group' do
expect(Experiment).to receive(:add_group)
.with(:in_product_marketing_emails, variant: :control, group: group)
execute_service
end
it { is_expected.not_to send_in_product_marketing_email }
end
context 'when not on dotcom' do
before do
allow(::Gitlab).to receive(:com?).and_return(false)
end
it 'does not add the group as an experiment subject' do
expect(Experiment).not_to receive(:add_group)
execute_service
end
it { is_expected.to send_in_product_marketing_email(user.id, group.id, :create, 0) }
end
end
end
context 'when the previous track action is not yet completed' do context 'when the previous track action is not yet completed' do
let(:previous_action_completed_at) { nil } let(:previous_action_completed_at) { nil }
......
# frozen_string_literal: true
RSpec.shared_examples 'in-product marketing email' do
before do
stub_application_setting(in_product_marketing_emails_enabled: in_product_marketing_emails_enabled)
stub_experiment(in_product_marketing_emails: experiment_active)
allow(::Gitlab).to receive(:com?).and_return(is_gitlab_com)
end
it 'executes the email service service' do
expect(Namespaces::InProductMarketingEmailsService).to receive(:send_for_all_tracks_and_intervals).exactly(executes_service).times
subject.perform
end
end
...@@ -2,38 +2,31 @@ ...@@ -2,38 +2,31 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform' do RSpec.describe Namespaces::InProductMarketingEmailsWorker, '#perform', unless: Gitlab.ee? do
using RSpec::Parameterized::TableSyntax
# Running this in EE would call the overridden method, which can't be tested in CE. # Running this in EE would call the overridden method, which can't be tested in CE.
# The EE code is covered in a separate EE spec. # The EE code is covered in a separate EE spec.
context 'not on gitlab.com', unless: Gitlab.ee? do
let(:is_gitlab_com) { false } context 'when the in_product_marketing_emails_enabled setting is disabled' do
before do
where(:in_product_marketing_emails_enabled, :experiment_active, :executes_service) do stub_application_setting(in_product_marketing_emails_enabled: false)
true | true | 1
true | false | 1
false | false | 0
false | true | 0
end end
with_them do it 'does not execute the email service' do
it_behaves_like 'in-product marketing email' expect(Namespaces::InProductMarketingEmailsService).not_to receive(:send_for_all_tracks_and_intervals)
subject.perform
end end
end end
context 'on gitlab.com' do context 'when the in_product_marketing_emails_enabled setting is enabled' do
let(:is_gitlab_com) { true } before do
stub_application_setting(in_product_marketing_emails_enabled: true)
where(:in_product_marketing_emails_enabled, :experiment_active, :executes_service) do
true | true | 1
true | false | 0
false | false | 0
false | true | 0
end end
with_them do it 'executes the email service' do
it_behaves_like 'in-product marketing email' expect(Namespaces::InProductMarketingEmailsService).to receive(:send_for_all_tracks_and_intervals)
subject.perform
end end
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