summaryrefslogtreecommitdiff
path: root/lib/gitlab/email/message/in_product_marketing/base.rb
blob: 6341a7c759672c87459de38b3a883b62ffdf22db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
# frozen_string_literal: true

module Gitlab
  module Email
    module Message
      module InProductMarketing
        class Base
          include Gitlab::Email::Message::InProductMarketing::Helper
          include Gitlab::Routing

          attr_accessor :format

          def initialize(group:, series:, format: :html)
            raise ArgumentError, "Only #{total_series} series available for this track." unless series.between?(0, total_series - 1)

            @group = group
            @series = series
            @format = format
          end

          def subject_line
            raise NotImplementedError
          end

          def tagline
            raise NotImplementedError
          end

          def title
            raise NotImplementedError
          end

          def subtitle
            raise NotImplementedError
          end

          def body_line1
            raise NotImplementedError
          end

          def body_line2
            raise NotImplementedError
          end

          def cta_text
            raise NotImplementedError
          end

          def cta_link
            case format
            when :html
              link_to cta_text, group_email_campaigns_url(group, track: track, series: series), target: '_blank', rel: 'noopener noreferrer'
            else
              [cta_text, group_email_campaigns_url(group, track: track, series: series)].join(' >> ')
            end
          end

          def unsubscribe
            parts = Gitlab.com? ? unsubscribe_com : unsubscribe_self_managed(track, series)

            case format
            when :html
              parts.join(' ')
            else
              parts.join("\n" + ' ' * 16)
            end
          end

          def progress
            if Gitlab.com?
              s_('InProductMarketing|This is email %{current_series} of %{total_series} in the %{track} series.') % { current_series: series + 1, total_series: total_series, track: track.to_s.humanize }
            else
              s_('InProductMarketing|This is email %{current_series} of %{total_series} in the %{track} series. To disable notification emails sent by your local GitLab instance, either contact your administrator or %{unsubscribe_link}.') % { current_series: series + 1, total_series: total_series, track: track.to_s.humanize, unsubscribe_link: unsubscribe_link }
            end
          end

          def address
            s_('InProductMarketing|%{strong_start}GitLab Inc.%{strong_end} 268 Bush Street, #350, San Francisco, CA 94104, USA').html_safe % strong_options
          end

          def footer_links
            links = [
              [s_('InProductMarketing|Blog'), 'https://about.gitlab.com/blog'],
              [s_('InProductMarketing|Twitter'), 'https://twitter.com/gitlab'],
              [s_('InProductMarketing|Facebook'), 'https://www.facebook.com/gitlab'],
              [s_('InProductMarketing|YouTube'), 'https://www.youtube.com/channel/UCnMGQ8QHMAnVIsI3xJrihhg']
            ]
            case format
            when :html
              links.map do |text, link|
                link_to(text, link)
              end
            else
              '| ' + links.map do |text, link|
                [text, link].join(' ')
              end.join("\n| ")
            end
          end

          def logo_path
            ["mailers/in_product_marketing", "#{track}-#{series}.png"].join('/')
          end

          protected

          attr_reader :group, :series

          def total_series
            3
          end

          private

          def track
            self.class.name.demodulize.downcase.to_sym
          end

          def unsubscribe_com
            [
              s_('InProductMarketing|If you no longer wish to receive marketing emails from us,'),
              s_('InProductMarketing|you may %{unsubscribe_link} at any time.') % { unsubscribe_link: unsubscribe_link }
            ]
          end

          def unsubscribe_self_managed(track, series)
            [
              s_('InProductMarketing|To opt out of these onboarding emails, %{unsubscribe_link}.') % { unsubscribe_link: unsubscribe_link },
              s_("InProductMarketing|If you don't want to receive marketing emails directly from GitLab, %{marketing_preference_link}.") % { marketing_preference_link: marketing_preference_link(track, series) }
            ]
          end

          def unsubscribe_link
            unsubscribe_url = Gitlab.com? ? '%tag_unsubscribe_url%' : profile_notifications_url

            link(s_('InProductMarketing|unsubscribe'), unsubscribe_url)
          end

          def marketing_preference_link(track, series)
            params = {
              utm_source: 'SM',
              utm_medium: 'email',
              utm_campaign: 'onboarding',
              utm_term: "#{track}_#{series}"
            }

            preference_link = "https://about.gitlab.com/company/preference-center/?#{params.to_query}"

            link(s_('InProductMarketing|update your preferences'), preference_link)
          end
        end
      end
    end
  end
end