The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Refactor getCustomerEvents to include optional linkIds parameter
Kiran K4c3bfb6857ef
diff --git a/apps/web/app/api/customers/[id]/activity/route.ts b/apps/web/app/api/customers/[id]/activity/route.tsindex 95645768b9..98cb69f2ad 100644--- a/apps/web/app/api/customers/[id]/activity/route.ts+++ b/apps/web/app/api/customers/[id]/activity/route.ts@@ -31,7 +31,10 @@ export const GET = withWorkspace(async ({ workspace, params, session }) => {let [events, link] = await Promise.all([getCustomerEvents(- { customerId: customer.id, clickId: customer.clickId },+ {+ customerId: customer.id,+ clickId: customer.clickId,+ },{sortOrder: "desc",interval: "1y",diff --git a/apps/web/app/api/partner-profile/programs/[programId]/customers/[customerId]/activity/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/customers/[customerId]/activity/route.tsindex 1679008588..518b636ea6 100644--- a/apps/web/app/api/partner-profile/programs/[programId]/customers/[customerId]/activity/route.ts+++ b/apps/web/app/api/partner-profile/programs/[programId]/customers/[customerId]/activity/route.ts@@ -11,7 +11,7 @@ import { NextResponse } from "next/server";export const GET = withPartnerProfile(async ({ partner, params }) => {const { customerId, programId } = params;- const { program } = await getProgramEnrollmentOrThrow({+ const { program, links } = await getProgramEnrollmentOrThrow({partnerId: partner.id,programId: programId,});@@ -70,7 +70,11 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {let [events, link] = await Promise.all([getCustomerEvents(- { customerId: customer.id, clickId: customer.clickId },+ {+ customerId: customer.id,+ clickId: customer.clickId,+ linkIds: links.map((link) => link.id),+ },{sortOrder: "desc",interval: "1y",@@ -79,14 +83,13 @@ export const GET = withPartnerProfile(async ({ partner, params }) => {prisma.link.findUniqueOrThrow({where: {- id: customer.linkId!,+ id: customer.linkId,},select: {id: true,domain: true,key: true,shortLink: true,- folderId: true,},}),]);diff --git a/apps/web/lib/analytics/get-customer-events.ts b/apps/web/lib/analytics/get-customer-events.tsindex 1365d9604a..f6d5ae498b 100644--- a/apps/web/lib/analytics/get-customer-events.ts+++ b/apps/web/lib/analytics/get-customer-events.ts@@ -14,7 +14,15 @@ import { EventsFilters } from "./types";import { getStartEndDates } from "./utils/get-start-end-dates";export const getCustomerEvents = async (- { customerId, clickId }: { customerId: string; clickId?: string | null },+ {+ customerId,+ clickId,+ linkIds,+ }: {+ customerId: string;+ clickId?: string | null;+ linkIds?: string[];+ },params: Pick<EventsFilters,"sortOrder" | "start" | "end" | "dataAvailableFrom" | "interval"@@ -39,6 +47,7 @@ export const getCustomerEvents = async (...params,customerId,...(clickId ? { clickId } : {}),+ ...(linkIds ? { linkIds } : {}),order: sortOrder,start: startDate.toISOString().replace("T", " ").replace("Z", ""),end: endDate.toISOString().replace("T", " ").replace("Z", ""),diff --git a/packages/tinybird/pipes/v2_customer_events.pipe b/packages/tinybird/pipes/v2_customer_events.pipeindex 143873515f..c3d52c089d 100644--- a/packages/tinybird/pipes/v2_customer_events.pipe+++ b/packages/tinybird/pipes/v2_customer_events.pipe@@ -42,6 +42,7 @@ SQL >required=True,)}}+ {% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}LIMIT {{ Int32(limit, 100) }}@@ -86,6 +87,7 @@ SQL >required=True,)}}+ {% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}AND timestamp >= {{ DateTime(start, '2025-01-01 00:00:00') }}AND timestamp < {{ DateTime(end, '2025-06-30 00:00:00') }}ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}@@ -136,6 +138,7 @@ SQL >required=True,)}}+ {% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}AND timestamp >= {{ DateTime(start, '2025-01-01 00:00:00') }}AND timestamp < {{ DateTime(end, '2025-06-30 00:00:00') }}LIMIT {{ Int32(limit, 100) }}