From 1613470a8c288be6d134317ec1b5250b45622425 Mon Sep 17 00:00:00 2001 From: Fabien 'egg' O'Carroll Date: Mon, 3 Oct 2022 09:29:58 +0100 Subject: [PATCH] Used the higher of click count and open count for email open count (#15508) fixes https://github.com/TryGhost/Team/issues/2017 We process clicks much faster than we process Mailgun events which can result in a higher click rater than open rate shown on the dashboard. This ensures that the open rate will never be lower than the click rate. This is a stopgap solution until we can get click events updating the opened_at time for email_recipients --- .../utils/serializers/output/mappers/posts.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/posts.js b/ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/posts.js index 4cee4f5ced..2154c36376 100644 --- a/ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/posts.js +++ b/ghost/core/core/server/api/endpoints/utils/serializers/output/mappers/posts.js @@ -110,6 +110,18 @@ module.exports = async (model, frame, options = {}) => { }); } + if (labs.isSet('emailClicks')) { + if (jsonModel.email && jsonModel.count) { + jsonModel.email.opened_count = Math.min( + Math.max( + jsonModel.email.opened_count || 0, + jsonModel.count.clicks || 0 + ), + jsonModel.email.email_count + ); + } + } + if (!labs.isSet('memberAttribution') && !labs.isSet('emailClicks')) { delete jsonModel.count; }