diff --git a/lib/tools.js b/lib/tools.js
index 5a7988bd..4fc8b396 100644
--- a/lib/tools.js
+++ b/lib/tools.js
@@ -188,7 +188,7 @@ function formatMessage(serviceUrl, campaign, list, subscription, message, filter
return message.replace(/\[([a-z0-9_]+)(?:\/([^\]]+))?\]/ig, (match, identifier, fallback) => {
identifier = identifier.toUpperCase();
let value = (getValue(identifier) || fallback || '').trim();
- return value ? filter(value) : '';
+ return value ? filter(value) : match;
});
}
diff --git a/routes/archive.js b/routes/archive.js
index c0c0245b..d9c7eb56 100644
--- a/routes/archive.js
+++ b/routes/archive.js
@@ -64,20 +64,26 @@ router.get('/:campaign/:list/:subscription', passport.csrfProtection, (req, res,
}
let renderHtml = (html, renderTags) => {
- campaign.editorName = campaign.editorName || 'summernote';
- let sfx = '';
- if (campaign.editorName !== 'summernote' && campaign.editorName !== 'codeeditor') {
- sfx = '-raw';
+ let render = (view, layout) => {
+ res.render(view, {
+ layout,
+ message: renderTags ? tools.formatMessage(serviceUrl, campaign, list, subscription, html) : html,
+ campaign,
+ list,
+ subscription,
+ attachments,
+ csrfToken: req.csrfToken()
+ });
+ };
+
+ if (campaign.editorName && campaign.editorName !== 'summernote' && campaign.editorName !== 'codeeditor') {
+ res.render('partials/tracking-scripts', { layout: 'archive/layout-raw' }, (err, scripts) => {
+ html = scripts ? html.replace(/<\/body\b/i, match => scripts + match) : html;
+ render('archive/view-raw', 'archive/layout-raw');
+ });
+ } else {
+ render('archive/view', 'archive/layout');
}
- res.render('archive/view' + sfx, {
- layout: 'archive/layout' + sfx,
- message: renderTags ? tools.formatMessage(serviceUrl, campaign, list, subscription, html) : html,
- campaign,
- list,
- subscription,
- attachments,
- csrfToken: req.csrfToken()
- });
};
let renderAndShow = (html, renderTags) => {
diff --git a/views/archive/layout.hbs b/views/archive/layout.hbs
index 88cafbf4..a257eb3b 100644
--- a/views/archive/layout.hbs
+++ b/views/archive/layout.hbs
@@ -41,24 +41,8 @@
- {{#if uaCode}}
-
- {{/if}}
+ {{> tracking_scripts}}
+