-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added the feedback buttons in the emails #15619
Merged
lenabaidakova
merged 6 commits into
TryGhost:main
from
lenabaidakova:2046-add-the-html-buttons-in-the-emails
Oct 14, 2022
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c328a4c
Added the feedback buttons in the emails
lenabaidakova 0bc9add
fixup! Added the feedback buttons in the emails
lenabaidakova 6e035df
fixup! Added the feedback buttons in the emails
lenabaidakova 075e753
fixup! Added the feedback buttons in the emails
lenabaidakova 204df61
fixup! Added the feedback buttons in the emails
lenabaidakova 6cbf75e
fixup! Added the feedback buttons in the emails
lenabaidakova File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
const {Color} = require('@tryghost/color-utils'); | ||
const audienceFeedback = require('../audience-feedback'); | ||
|
||
const templateStrings = { | ||
like: '%{feedback_button_like}%', | ||
dislike: '%{feedback_button_dislike}%' | ||
}; | ||
|
||
const generateLinks = (postId, uuid, html) => { | ||
const positiveLink = audienceFeedback.service.buildLink( | ||
uuid, | ||
postId, | ||
1 | ||
); | ||
const negativeLink = audienceFeedback.service.buildLink( | ||
uuid, | ||
postId, | ||
0 | ||
); | ||
|
||
html = html.replace(templateStrings.like, positiveLink.href); | ||
html = html.replace(templateStrings.dislike, negativeLink.href); | ||
|
||
return html; | ||
}; | ||
|
||
const getTemplate = (accentColor) => { | ||
const likeButtonHtml = getButtonHtml(templateStrings.like, 'More like this', accentColor); | ||
const dislikeButtonHtml = getButtonHtml(templateStrings.dislike, 'Less like this', accentColor); | ||
|
||
return (` | ||
<tr> | ||
<td dir="ltr" width="100%" style="background-color: #ffffff; text-align: center; padding: 40px 4px; border-bottom: 1px solid #e5eff5" align="center"> | ||
<h3 style="text-align: center; margin-bottom: 22px; font-size: 17px; letter-spacing: -0.2px; margin-top: 0 !important;">What did you think of this post?</h3> | ||
<table role="presentation" border="0" cellpadding="0" cellspacing="0" style="margin: auto; width: auto !important;"> | ||
<tr> | ||
${likeButtonHtml} | ||
${dislikeButtonHtml} | ||
</tr> | ||
</table> | ||
</td> | ||
</tr> | ||
`); | ||
}; | ||
|
||
function getButtonHtml(href, buttonText, accentColor) { | ||
const color = new Color(accentColor); | ||
const bgColor = `${accentColor}10`; | ||
const textColor = color.darken(0.6).hex(); | ||
|
||
return (` | ||
<td dir="ltr" valign="top" align="center" style="font-family: inherit; font-size: 14px; text-align: center;" nowrap> | ||
<table align="center" role="presentation" cellspacing="0" cellpadding="0" border="0" style="width: auto !important;"> | ||
<tr> | ||
<td style="padding: 0 6px; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol';"> | ||
<a href=${href} style="background-color: ${bgColor}; color: ${textColor}; border-radius: 22px; font-family: inherit; padding: 12px 20px; border: none; font-size: 14px; font-weight: bold; line-height: 100%; text-decoration: none; display: block;"> | ||
${buttonText} | ||
</a> | ||
</td> | ||
</tr> | ||
</table> | ||
</td> | ||
`); | ||
} | ||
|
||
module.exports = { | ||
generateLinks, | ||
getTemplate | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,11 +16,12 @@ const urlService = require('../../services/url'); | |
const linkReplacer = require('@tryghost/link-replacer'); | ||
const linkTracking = require('../link-tracking'); | ||
const memberAttribution = require('../member-attribution'); | ||
const feedbackButtons = require('./feedback-buttons'); | ||
|
||
const ALLOWED_REPLACEMENTS = ['first_name', 'uuid']; | ||
|
||
const PostEmailSerializer = { | ||
|
||
// Format a full html document ready for email by inlining CSS, adjusting links, | ||
// and performing any client-specific fixes | ||
formatHtmlForEmail(html) { | ||
|
@@ -107,6 +108,23 @@ const PostEmailSerializer = { | |
return signupUrl.href; | ||
}, | ||
|
||
/** | ||
* createUserLinks | ||
* | ||
* Generate personalised links for each user | ||
* | ||
* @param {string} memberUuid member uuid | ||
* @param {Object} email | ||
*/ | ||
createUserLinks(email, memberUuid) { | ||
const result = {...email}; | ||
|
||
result.html = feedbackButtons.generateLinks(result.post.id, memberUuid, result.html); | ||
result.plaintext = htmlToPlaintext.email(result.html); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is it necessary that we do this here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd suggest keeping it :) We added new links to Html and I think it's better to update the plain version |
||
|
||
return result; | ||
}, | ||
|
||
// NOTE: serialization is needed to make sure we do post transformations such as image URL transformation from relative to absolute | ||
async serializePostModel(model) { | ||
// fetch mobiledoc rather than html and plaintext so we can render email-specific contents | ||
|
@@ -206,6 +224,7 @@ const PostEmailSerializer = { | |
titleAlignment: newsletter.get('title_alignment'), | ||
bodyFontCategory: newsletter.get('body_font_category'), | ||
showBadge: newsletter.get('show_badge'), | ||
feedbackEnabled: newsletter.get('feedback_enabled'), | ||
footerContent: newsletter.get('footer_content'), | ||
showHeaderName: newsletter.get('show_header_name'), | ||
accentColor, | ||
|
@@ -335,7 +354,7 @@ const PostEmailSerializer = { | |
plaintext: post.plaintext | ||
}; | ||
|
||
/** | ||
/** | ||
* If a part of the email is members-only and the post is paid-only, add a paywall: | ||
* - Just before sending the email, we'll hide the paywall or paid content depending on the member segment it is sent to. | ||
* - We already need to do URL-replacement on the HTML here | ||
|
@@ -369,7 +388,7 @@ const PostEmailSerializer = { | |
|
||
// Add link click tracking | ||
url = await linkTracking.service.addTrackingToUrl(url, post, '--uuid--'); | ||
|
||
// We need to convert to a string at this point, because we need invalid string characters in the URL | ||
const str = url.toString().replace(/--uuid--/g, '%%{uuid}%%'); | ||
return str; | ||
|
@@ -490,7 +509,7 @@ const PostEmailSerializer = { | |
}); | ||
|
||
result.html = this.formatHtmlForEmail($.html()); | ||
result.plaintext = htmlToPlaintext.email(result.html); | ||
result.plaintext = htmlToPlaintext.email(result.html); | ||
delete result.post; | ||
|
||
return result; | ||
|
@@ -501,6 +520,7 @@ module.exports = { | |
serialize: PostEmailSerializer.serialize.bind(PostEmailSerializer), | ||
createUnsubscribeUrl: PostEmailSerializer.createUnsubscribeUrl.bind(PostEmailSerializer), | ||
createPostSignupUrl: PostEmailSerializer.createPostSignupUrl.bind(PostEmailSerializer), | ||
createUserLinks: PostEmailSerializer.createUserLinks.bind(PostEmailSerializer), | ||
renderEmailForSegment: PostEmailSerializer.renderEmailForSegment.bind(PostEmailSerializer), | ||
parseReplacements: PostEmailSerializer.parseReplacements.bind(PostEmailSerializer), | ||
// Export for tests | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buttons in email without icons yet, will add them in https://github.com/TryGhost/Team/issues/2075 (need more time)