Disabled link replacement when link click tracking is disabled (#15483)
fixes https://github.com/TryGhost/Team/issues/1988 - We don't want to replace links when link click tracking is disabled (also not add ref) - Cleaned up some comments and methods
This commit is contained in:
parent
8c87bb8158
commit
6489cb01b5
@ -2,7 +2,6 @@ const _ = require('lodash');
|
||||
const template = require('./template');
|
||||
const settingsCache = require('../../../shared/settings-cache');
|
||||
const urlUtils = require('../../../shared/url-utils');
|
||||
const labs = require('../../../shared/labs');
|
||||
const moment = require('moment-timezone');
|
||||
const api = require('../../api').endpoints;
|
||||
const apiFramework = require('@tryghost/api-framework');
|
||||
@ -357,34 +356,24 @@ const PostEmailSerializer = {
|
||||
}
|
||||
|
||||
// Now replace the links in the HTML version
|
||||
if (labs.isSet('emailClicks')) {
|
||||
if ((!options.isBrowserPreview && !options.isTestEmail) || process.env.NODE_ENV === 'development') {
|
||||
const enableTracking = settingsCache.get('email_track_clicks');
|
||||
result.html = await linkReplacer.replace(result.html, async (url) => {
|
||||
// Add newsletter source attribution
|
||||
url = memberAttribution.service.addEmailSourceAttributionTracking(url, newsletter);
|
||||
const isSite = urlUtils.isSiteUrl(url);
|
||||
if (!options.isBrowserPreview && !options.isTestEmail && settingsCache.get('email_track_clicks')) {
|
||||
result.html = await linkReplacer.replace(result.html, async (url) => {
|
||||
// Add newsletter source attribution
|
||||
url = memberAttribution.service.addEmailSourceAttributionTracking(url, newsletter);
|
||||
const isSite = urlUtils.isSiteUrl(url);
|
||||
|
||||
// Add post attribution tracking
|
||||
if (isSite && enableTracking) {
|
||||
// Only add attribution links to our own site (except for the newsletter referrer)
|
||||
url = memberAttribution.service.addPostAttributionTracking(url, post);
|
||||
}
|
||||
if (isSite) {
|
||||
// Only add post attribution to our own site (because external sites could/should not process this information)
|
||||
url = memberAttribution.service.addPostAttributionTracking(url, post);
|
||||
}
|
||||
|
||||
// Add link click tracking
|
||||
if (enableTracking) {
|
||||
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;
|
||||
}
|
||||
|
||||
// Replace the URL with a normal redirect so we can change it later, but don't include tracking
|
||||
url = linkTracking.service.addRedirectToUrl(url, post);
|
||||
return url;
|
||||
});
|
||||
}
|
||||
// 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;
|
||||
});
|
||||
}
|
||||
|
||||
// Clean up any unknown replacements strings to get our final content
|
||||
|
@ -78,7 +78,8 @@ class LinkClickTrackingService {
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @private (not using # to allow tests)
|
||||
* Replace URL with a redirect that redirects to the original URL, and link that redirect with the given post
|
||||
*/
|
||||
async addRedirectToUrl(url, post) {
|
||||
|
Loading…
Reference in New Issue
Block a user