Complete Rybbit campaign aggregation
This commit is contained in:
@@ -22,6 +22,11 @@ export type CampaignRybbitSummary = {
|
||||
auditOpens: number;
|
||||
ctaClicks: number;
|
||||
outboundClicks: number;
|
||||
byPath: Record<string, {
|
||||
auditOpens: number;
|
||||
ctaClicks: number;
|
||||
outboundClicks: number;
|
||||
}>;
|
||||
};
|
||||
|
||||
type FetchLike = (
|
||||
@@ -127,6 +132,25 @@ export function summarizeCampaignRybbitEvents(
|
||||
events: RybbitEvent[],
|
||||
): CampaignRybbitSummary {
|
||||
const auditEvents = events.filter((event) => eventPath(event).startsWith("/audit/"));
|
||||
const byPath: CampaignRybbitSummary["byPath"] = {};
|
||||
|
||||
for (const event of auditEvents) {
|
||||
const path = eventPath(event);
|
||||
byPath[path] ??= { auditOpens: 0, ctaClicks: 0, outboundClicks: 0 };
|
||||
|
||||
if (event.type === "pageview") {
|
||||
byPath[path].auditOpens += 1;
|
||||
}
|
||||
if (event.type === "custom_event" && eventName(event) === "audit_cta_click") {
|
||||
byPath[path].ctaClicks += 1;
|
||||
}
|
||||
if (
|
||||
event.type === "outbound_link" ||
|
||||
eventName(event) === "audit_website_link_click"
|
||||
) {
|
||||
byPath[path].outboundClicks += 1;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
auditOpens: auditEvents.filter((event) => event.type === "pageview").length,
|
||||
@@ -137,6 +161,7 @@ export function summarizeCampaignRybbitEvents(
|
||||
return event.type === "outbound_link" ||
|
||||
eventName(event) === "audit_website_link_click";
|
||||
}).length,
|
||||
byPath,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user