Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Merge branch 'main' into calculated-stats

Steven Teyd128e46ef1e7
diff --cc apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
index 9967993ecf,1aee1a41c0..556526adf8
--- a/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
+++ b/apps/web/app/app.dub.co/(dashboard)/[slug]/(ee)/program/partners/partners-table.tsx
@@@ -278,94 -271,17 +278,94 @@@ export function PartnersTable()
{
id: "totalSaleAmount",
header: "Revenue",
- accessorFn: (d) => currencyFormatter(d.totalSaleAmount),
+ accessorFn: (d: EnrolledPartnerProps) =>
- currencyFormatter(d.totalSaleAmount / 100),
++ currencyFormatter(d.totalSaleAmount),
},
{
id: "totalCommissions",
header: "Commissions",
- accessorFn: (d) => currencyFormatter(d.totalCommissions),
+ accessorFn: (d: EnrolledPartnerProps) =>
- currencyFormatter(d.totalCommissions / 100),
++ currencyFormatter(d.totalCommissions),
},
{
id: "netRevenue",
header: "Net Revenue",
- accessorFn: (d) => currencyFormatter(d.netRevenue),
+ meta: {
+ headerTooltip:
+ "Net revenue after commissions. \n`Total Revenue - Total Commissions`",
+ },
+ accessorFn: (d: EnrolledPartnerProps) =>
- currencyFormatter(d.netRevenue / 100),
++ currencyFormatter(d.netRevenue),
+ },
+ {
+ id: "earningsPerClick",
+ header: "EPC",
+ meta: {
+ headerTooltip:
+ "Average earnings per click. \n`Total Revenue ÷ Total Clicks`",
+ },
+ accessorFn: (d: EnrolledPartnerProps) =>
- currencyFormatter(d.earningsPerClick / 100),
++ currencyFormatter(d.earningsPerClick),
+ },
+ {
+ id: "averageLifetimeValue",
+ header: "Avg LTV",
+ meta: {
+ headerTooltip:
+ "Average lifetime value per conversion. \n`Total Revenue ÷ Total Conversions`",
+ },
+ accessorFn: (d: EnrolledPartnerProps) =>
+ d.averageLifetimeValue
- ? currencyFormatter(d.averageLifetimeValue / 100)
++ ? currencyFormatter(d.averageLifetimeValue)
+ : "-",
+ },
+ {
+ id: "clickToLeadRate",
+ header: "Click → Lead",
+ meta: {
+ headerTooltip:
+ "Percentage of clicks that become leads. \n`Total Leads ÷ Total Clicks`",
+ },
+ accessorFn: (d: EnrolledPartnerProps) =>
+ d.clickToLeadRate
+ ? `${(d.clickToLeadRate * 100).toFixed(2)}%`
+ : "-",
+ },
+ {
+ id: "clickToConversionRate",
+ header: "Click → Conv",
+ meta: {
+ headerTooltip:
+ "Percentage of clicks that convert. \n`Total Conversions ÷ Total Clicks`",
+ },
+ accessorFn: (d: EnrolledPartnerProps) =>
+ d.clickToConversionRate
+ ? `${(d.clickToConversionRate * 100).toFixed(2)}%`
+ : "-",
+ },
+ {
+ id: "leadToConversionRate",
+ header: "Lead → Conv",
+ meta: {
+ headerTooltip:
+ "Percentage of leads that convert. \n`Total Conversions ÷ Total Leads`",
+ },
+ accessorFn: (d: EnrolledPartnerProps) =>
+ d.leadToConversionRate
+ ? `${(d.leadToConversionRate * 100).toFixed(2)}%`
+ : "-",
+ },
+ {
+ id: "returnOnAdSpend",
+ header: "ROAS",
+ meta: {
+ headerTooltip:
+ "Return on ad spend ratio. \n`Total Revenue ÷ Total Commissions`",
+ },
+ accessorFn: (d: EnrolledPartnerProps) =>
+ d.returnOnAdSpend
+ ? `${(d.returnOnAdSpend * 100).toFixed(2)}%`
+ : "-",
},
// Menu
{
diff --cc apps/web/lib/api/network/calculate-partner-ranking.ts
index df2dbc18ac,b55fef3b6c..0b659bbc12
--- a/apps/web/lib/api/network/calculate-partner-ranking.ts
+++ b/apps/web/lib/api/network/calculate-partner-ranking.ts
@@@ -39,10 -36,10 +36,10 @@@ export interface PartnerRankingParams e
* - Rewards partners enrolled in many similar programs
* - 2 points per similar program (capped at 15)
*
- * Final Score = Multi-Program Bonus + Similarity + Match (0-265+ points)
+ * Final Score = Trusted Bonus + Similarity + Match (0-265+ points)
*
* Displayed Metrics:
- * - conversionRate: Average conversion rate across ALL programs the partner is enrolled in
+ * - clickToConversionRate: Average click-to-conversion rate across ALL programs the partner is enrolled in
* - lastConversionAt: Most recent conversion date across ALL programs the partner is enrolled in
*
* Note: Ranking is primarily used for the "discover" tab. For "invited" and "recruited"
@@@ -150,12 -143,15 +143,15 @@@ export async function calculatePartnerR
SELECT
pe_all.partnerId,
MAX(pe_all.lastConversionAt) as lastConversionAt,
- AVG(COALESCE(pe_all.conversionRate, 0)) as avgConversionRate
+ AVG(COALESCE(pe_all.clickToConversionRate, 0)) as avgConversionRate
FROM ProgramEnrollment pe_all
- -- OPTIMIZATION: Only process enrollments for discoverable partners
- INNER JOIN Partner p_filter_all ON p_filter_all.id = pe_all.partnerId
- AND ${discoverablePartnersAllProgramsFilter}
- WHERE pe_all.programId != ${ACME_PROGRAM_ID}
+ -- OPTIMIZATION: Only process enrollments for discoverable partners (using subquery to avoid JOIN)
+ WHERE pe_all.partnerId IN (
+ SELECT p_filter_all.id
+ FROM Partner p_filter_all
+ WHERE ${discoverablePartnersAllProgramsFilter}
+ )
+ AND pe_all.programId != ${ACME_PROGRAM_ID}
AND pe_all.totalConversions > 0
GROUP BY pe_all.partnerId
) allProgramMetrics ON allProgramMetrics.partnerId = p.id`;