Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
17538ffe
Commit
17538ffe
authored
Apr 19, 2021
by
Nicolas Dular
Committed by
Bob Van Landuyt
Apr 19, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Record cta click for in-product marketing emails
parent
bb89a15b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
132 additions
and
22 deletions
+132
-22
app/controllers/groups/email_campaigns_controller.rb
app/controllers/groups/email_campaigns_controller.rb
+12
-9
app/models/users/in_product_marketing_email.rb
app/models/users/in_product_marketing_email.rb
+10
-0
spec/models/users/in_product_marketing_email_spec.rb
spec/models/users/in_product_marketing_email_spec.rb
+74
-3
spec/requests/groups/email_campaigns_controller_spec.rb
spec/requests/groups/email_campaigns_controller_spec.rb
+36
-10
No files found.
app/controllers/groups/email_campaigns_controller.rb
View file @
17538ffe
...
...
@@ -17,16 +17,19 @@ class Groups::EmailCampaignsController < Groups::ApplicationController
private
def
track_click
data
=
{
namespace_id:
group
.
id
,
track:
@track
.
to_s
,
series:
@series
,
subject_line:
subject_line
(
@track
,
@series
)
}
if
Gitlab
.
com?
data
=
{
namespace_id:
group
.
id
,
track:
@track
.
to_s
,
series:
@series
,
subject_line:
subject_line
(
@track
,
@series
)
}
context
=
SnowplowTracker
::
SelfDescribingJson
.
new
(
EMAIL_CAMPAIGNS_SCHEMA_URL
,
data
)
context
=
SnowplowTracker
::
SelfDescribingJson
.
new
(
EMAIL_CAMPAIGNS_SCHEMA_URL
,
data
)
::
Gitlab
::
Tracking
.
event
(
self
.
class
.
name
,
'click'
,
context:
[
context
])
::
Gitlab
::
Tracking
.
event
(
self
.
class
.
name
,
'click'
,
context:
[
context
])
else
::
Users
::
InProductMarketingEmail
.
save_cta_click
(
current_user
,
@track
,
@series
)
end
end
def
redirect_link
...
...
app/models/users/in_product_marketing_email.rb
View file @
17538ffe
...
...
@@ -35,5 +35,15 @@ module Users
.
where
(
in_product_marketing_emails:
{
id:
nil
})
.
select
(
Arel
.
sql
(
"DISTINCT ON(
#{
users
.
table_name
}
.id)
#{
users
.
table_name
}
.*"
))
end
scope
:for_user_with_track_and_series
,
->
(
user
,
track
,
series
)
do
where
(
user:
user
,
track:
track
,
series:
series
)
end
def
self
.
save_cta_click
(
user
,
track
,
series
)
email
=
for_user_with_track_and_series
(
user
,
track
,
series
).
take
email
.
update
(
cta_clicked_at:
Time
.
zone
.
now
)
if
email
&&
email
.
cta_clicked_at
.
blank?
end
end
end
spec/models/users/in_product_marketing_email_spec.rb
View file @
17538ffe
...
...
@@ -3,6 +3,9 @@
require
'spec_helper'
RSpec
.
describe
Users
::
InProductMarketingEmail
,
type: :model
do
let
(
:track
)
{
:create
}
let
(
:series
)
{
0
}
describe
'associations'
do
it
{
is_expected
.
to
belong_to
(
:user
)
}
end
...
...
@@ -17,9 +20,6 @@ RSpec.describe Users::InProductMarketingEmail, type: :model do
end
describe
'.without_track_and_series'
do
let
(
:track
)
{
:create
}
let
(
:series
)
{
0
}
let_it_be
(
:user
)
{
create
(
:user
)
}
subject
(
:without_track_and_series
)
{
User
.
merge
(
described_class
.
without_track_and_series
(
track
,
series
))
}
...
...
@@ -57,4 +57,75 @@ RSpec.describe Users::InProductMarketingEmail, type: :model do
it
{
expect
(
without_track_and_series
).
to
eq
[
@other_user
]
}
end
end
describe
'.for_user_with_track_and_series'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:in_product_marketing_email
)
{
create
(
:in_product_marketing_email
,
series:
0
,
track:
0
,
user:
user
)
}
subject
(
:for_user_with_track_and_series
)
{
described_class
.
for_user_with_track_and_series
(
user
,
track
,
series
).
first
}
context
'when record for user with given track and series exists'
do
it
{
is_expected
.
to
eq
(
in_product_marketing_email
)
}
end
context
'when user is different'
do
let
(
:user
)
{
build_stubbed
(
:user
)
}
it
{
is_expected
.
to
be_nil
}
end
context
'when track is different'
do
let
(
:track
)
{
1
}
it
{
is_expected
.
to
be_nil
}
end
context
'when series is different'
do
let
(
:series
)
{
1
}
it
{
is_expected
.
to
be_nil
}
end
end
describe
'.save_cta_click'
do
let
(
:user
)
{
create
(
:user
)
}
subject
(
:save_cta_click
)
{
described_class
.
save_cta_click
(
user
,
track
,
series
)
}
context
'when there is no record'
do
it
'does not error'
do
expect
{
save_cta_click
}.
not_to
raise_error
end
end
context
'when there is no record for the track and series'
do
it
'does not perform an update'
do
other_email
=
create
(
:in_product_marketing_email
,
user:
user
,
track: :verify
,
series:
2
,
cta_clicked_at:
nil
)
expect
{
save_cta_click
}.
not_to
change
{
other_email
.
reload
}
end
end
context
'when there is a record for the track and series'
do
it
'saves the cta click date'
do
email
=
create
(
:in_product_marketing_email
,
user:
user
,
track:
track
,
series:
series
,
cta_clicked_at:
nil
)
freeze_time
do
expect
{
save_cta_click
}.
to
change
{
email
.
reload
.
cta_clicked_at
}.
from
(
nil
).
to
(
Time
.
zone
.
now
)
end
end
context
'cta_clicked_at is already set'
do
it
'does not update'
do
create
(
:in_product_marketing_email
,
user:
user
,
track:
track
,
series:
series
,
cta_clicked_at:
Time
.
zone
.
now
)
expect_next_found_instance_of
(
described_class
)
do
|
record
|
expect
(
record
).
not_to
receive
(
:update
)
end
save_cta_click
end
end
end
end
end
spec/requests/groups/email_campaigns_controller_spec.rb
View file @
17538ffe
...
...
@@ -38,17 +38,43 @@ RSpec.describe Groups::EmailCampaignsController do
expect
(
subject
).
to
have_gitlab_http_status
(
:redirect
)
end
it
'emits a snowplow event'
,
:snowplow
do
subject
context
'on .com'
do
before
do
allow
(
Gitlab
).
to
receive
(
:com?
).
and_return
(
true
)
end
it
'emits a snowplow event'
,
:snowplow
do
subject
expect_snowplow_event
(
category:
described_class
.
name
,
action:
'click'
,
context:
[{
schema:
described_class
::
EMAIL_CAMPAIGNS_SCHEMA_URL
,
data:
{
namespace_id:
group
.
id
,
series:
series
.
to_i
,
subject_line:
subject_line_text
,
track:
track
.
to_s
}
}]
)
end
expect_snowplow_event
(
category:
described_class
.
name
,
action:
'click'
,
context:
[{
schema:
described_class
::
EMAIL_CAMPAIGNS_SCHEMA_URL
,
data:
{
namespace_id:
group
.
id
,
series:
series
.
to_i
,
subject_line:
subject_line_text
,
track:
track
.
to_s
}
}]
)
it
'does not save the cta_click'
do
expect
(
Users
::
InProductMarketingEmail
).
not_to
receive
(
:save_cta_click
)
subject
end
end
context
'when not on.com'
do
it
'saves the cta_click'
do
expect
(
Users
::
InProductMarketingEmail
).
to
receive
(
:save_cta_click
)
subject
end
it
'does not track snowplow events'
do
subject
expect_no_snowplow_event
end
end
end
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment