diff --git a/lib/tools.js b/lib/tools.js index 41c8b782..05f1244b 100644 --- a/lib/tools.js +++ b/lib/tools.js @@ -186,7 +186,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 a4356462..221cce0e 100644 --- a/routes/archive.js +++ b/routes/archive.js @@ -62,20 +62,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 bc9e27a9..98a3e25c 100644 --- a/views/archive/layout.hbs +++ b/views/archive/layout.hbs @@ -41,24 +41,8 @@ - {{#if uaCode}} - - {{/if}} + {{> tracking_scripts}} + diff --git a/views/layout.hbs b/views/layout.hbs index 91b4b9a5..6a0fecc7 100644 --- a/views/layout.hbs +++ b/views/layout.hbs @@ -153,24 +153,8 @@ {{/if}} - {{#if uaCode}} - - {{/if}} diff --git a/views/partials/tracking-scripts.hbs b/views/partials/tracking-scripts.hbs new file mode 100644 index 00000000..72e045d2 --- /dev/null +++ b/views/partials/tracking-scripts.hbs @@ -0,0 +1,18 @@ +{{#if uaCode}} + +{{/if}}