Commit fb418287 authored by Arturo Herrero's avatar Arturo Herrero

Merge branch 'add-click-tracking-to-in-product-marketing-email-campaigns' into 'master'

Add click tracking to in product marketing email campaigns

See merge request gitlab-org/gitlab!52723
parents 5c731d5a 3367c4c8
# frozen_string_literal: true
class Groups::EmailCampaignsController < Groups::ApplicationController
include InProductMarketingHelper
include Gitlab::Tracking::ControllerConcern
EMAIL_CAMPAIGNS_SCHEMA_URL = 'iglu:com.gitlab/email_campaigns/jsonschema/1-0-0'
feature_category :navigation
before_action :check_params
def index
track_click
redirect_to redirect_link
end
private
def track_click
data = {
namespace_id: group.id,
track: @track,
series: @series,
subject_line: subject_line(@track, @series)
}
track_self_describing_event(EMAIL_CAMPAIGNS_SCHEMA_URL, data: data)
end
def redirect_link
case @track
when :create
create_track_url
when :verify
project_pipelines_url(group.projects.first)
when :trial
'https://about.gitlab.com/free-trial/'
when :team
group_group_members_url(group)
end
end
def create_track_url
[
new_project_url,
new_project_url(anchor: 'import_project'),
help_page_url('user/project/repository/repository_mirroring')
][@series]
end
def check_params
@track = params[:track]&.to_sym
@series = params[:series]&.to_i
track_valid = @track.in?(Namespaces::InProductMarketingEmailsService::TRACKS.keys)
series_valid = @series.in?(0..Namespaces::InProductMarketingEmailsService::INTERVAL_DAYS.size - 1)
render_404 unless track_valid && series_valid
end
end
......@@ -187,9 +187,9 @@ module InProductMarketingHelper
def cta_link(track, series, group, format: nil)
case format
when :html
link_to in_product_marketing_cta_text(track, series), in_product_marketing_cta_link(track, series, group), target: '_blank', rel: 'noopener noreferrer'
link_to in_product_marketing_cta_text(track, series), group_email_campaigns_url(group, track: track, series: series), target: '_blank', rel: 'noopener noreferrer'
else
[in_product_marketing_cta_text(track, series), in_product_marketing_cta_link(track, series, group)].join(' >> ')
[in_product_marketing_cta_text(track, series), group_email_campaigns_url(group, track: track, series: series)].join(' >> ')
end
end
......@@ -260,31 +260,6 @@ module InProductMarketingHelper
}[track][series]
end
def in_product_marketing_cta_link(track, series, group)
{
create: [
new_project_url,
new_project_url(anchor: 'import_project'),
help_page_url('user/project/repository/repository_mirroring')
],
verify: [
project_pipelines_url(group.projects.first),
project_pipelines_url(group.projects.first),
project_pipelines_url(group.projects.first)
],
trial: [
'https://about.gitlab.com/free-trial/',
'https://about.gitlab.com/free-trial/',
'https://about.gitlab.com/free-trial/'
],
team: [
group_group_members_url(group),
group_group_members_url(group),
group_group_members_url(group)
]
}[track][series]
end
def project_link(format)
link(s_('InProductMarketing|create a project'), help_page_url('gitlab-basics/create-project'), format)
end
......
......@@ -111,6 +111,7 @@ constraints(::Constraints::GroupUrlConstrainer.new) do
resources :container_registries, only: [:index, :show], controller: 'registry/repositories'
resource :dependency_proxy, only: [:show, :update]
resources :email_campaigns, only: :index
end
scope(path: '*id',
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Groups::EmailCampaignsController do
include InProductMarketingHelper
using RSpec::Parameterized::TableSyntax
describe 'GET #index', :snowplow do
let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, group: group) }
let_it_be(:user) { create(:user) }
let(:track) { 'create' }
let(:series) { '0' }
before do
sign_in(user)
group.add_developer(user)
allow(Gitlab::Tracking).to receive(:self_describing_event)
end
subject(:get_index) do
get group_email_campaigns_url(group, track: track, series: series)
response
end
RSpec::Matchers.define :track_event do |*args|
match do
expect(Gitlab::Tracking).to have_received(:self_describing_event).with(
described_class::EMAIL_CAMPAIGNS_SCHEMA_URL,
data: {
namespace_id: group.id,
track: track.to_sym,
series: series.to_i,
subject_line: subject_line(track.to_sym, series.to_i)
}
)
end
match_when_negated do
expect(Gitlab::Tracking).not_to have_received(:self_describing_event)
end
end
context 'track parameter' do
where(:track, :valid) do
'create' | true
'verify' | true
'trial' | true
'team' | true
'xxxx' | false
nil | false
end
with_them do
it do
if valid
is_expected.to track_event
is_expected.to have_gitlab_http_status(:redirect)
else
is_expected.not_to track_event
is_expected.to have_gitlab_http_status(:not_found)
end
end
end
end
context 'series parameter' do
where(:series, :valid) do
'0' | true
'1' | true
'2' | true
'-1' | false
'3' | false
nil | false
end
with_them do
it do
if valid
is_expected.to track_event
is_expected.to have_gitlab_http_status(:redirect)
else
is_expected.not_to track_event
is_expected.to have_gitlab_http_status(:not_found)
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