Skip to content

Commit

Permalink
add open rate and click rate to campaign list (#523)
Browse files Browse the repository at this point in the history
Co-authored-by: Leo Barcellos <leo@martechdm.com>
  • Loading branch information
leobarcellos and Leo Barcellos authored Oct 17, 2024
1 parent fbbe4f9 commit 5e69eed
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions apps/ui/src/views/campaign/Campaigns.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,24 @@ export const DeliveryRatio = ({ delivery }: { delivery: CampaignDelivery }) => {
return `${sent} / ${total}`
}

export const OpenRatio = ({ delivery }: { delivery: CampaignDelivery }) => {
const opens = (delivery?.opens ?? 0)
const sent = (delivery?.sent ?? 0)
const ratio = sent > 0 ? opens / sent : 0
const opensStr = opens.toLocaleString()
const ratioStr = ratio.toLocaleString(undefined, { style: 'percent', minimumFractionDigits: 0 })
return `${opensStr} (${ratioStr})`
}

export const ClickRatio = ({ delivery }: { delivery: CampaignDelivery }) => {
const clicks = (delivery?.clicks ?? 0)
const sent = (delivery?.sent ?? 0)
const ratio = sent > 0 ? clicks / sent : 0
const clicksStr = clicks.toLocaleString()
const ratioStr = ratio.toLocaleString(undefined, { style: 'percent', minimumFractionDigits: 0 })
return `${clicksStr} (${ratioStr})`
}

export default function Campaigns() {
const [project] = useContext(ProjectContext)
const { t } = useTranslation()
Expand Down Expand Up @@ -116,6 +134,16 @@ export default function Campaigns() {
title: t('delivery'),
cell: ({ item: { delivery } }) => DeliveryRatio({ delivery }),
},
{
key: 'open_rate',
title: t('open_rate'),
cell: ({ item: { delivery } }) => OpenRatio({ delivery }),
},
{
key: 'click_rate',
title: t('click_rate'),
cell: ({ item: { delivery } }) => ClickRatio({ delivery }),
},
{
key: 'send_at',
sortable: true,
Expand Down

0 comments on commit 5e69eed

Please sign in to comment.