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.

fix some stuff

Steven Tey2f55b5b00432
diff --git a/apps/web/app/api/customers/[id]/activity/route.ts b/apps/web/app/api/customers/[id]/activity/route.ts
index 98cb69f2ad..d6b93feafd 100644
--- a/apps/web/app/api/customers/[id]/activity/route.ts
+++ b/apps/web/app/api/customers/[id]/activity/route.ts
@@ -33,7 +33,6 @@ export const GET = withWorkspace(async ({ workspace, params, session }) => {
getCustomerEvents(
{
customerId: customer.id,
- clickId: customer.clickId,
},
{
sortOrder: "desc",
diff --git a/apps/web/lib/analytics/get-customer-events.ts b/apps/web/lib/analytics/get-customer-events.ts
index f6d5ae498b..b7dc06f49f 100644
--- a/apps/web/lib/analytics/get-customer-events.ts
+++ b/apps/web/lib/analytics/get-customer-events.ts
@@ -16,11 +16,9 @@ import { getStartEndDates } from "./utils/get-start-end-dates";
export const getCustomerEvents = async (
{
customerId,
- clickId,
linkIds,
}: {
customerId: string;
- clickId?: string | null;
linkIds?: string[];
},
params: Pick<
@@ -46,7 +44,6 @@ export const getCustomerEvents = async (
const response = await pipe({
...params,
customerId,
- ...(clickId ? { clickId } : {}),
...(linkIds ? { linkIds } : {}),
order: sortOrder,
start: startDate.toISOString().replace("T", " ").replace("Z", ""),
diff --git a/packages/tinybird/pipes/v2_customer_events.pipe b/packages/tinybird/pipes/v2_customer_events.pipe
index c3d52c089d..50e6d46907 100644
--- a/packages/tinybird/pipes/v2_customer_events.pipe
+++ b/packages/tinybird/pipes/v2_customer_events.pipe
@@ -4,7 +4,7 @@ DESCRIPTION >
TAGS "Dub Endpoints"
-NODE click_events
+NODE lead_events
SQL >
%
@@ -30,24 +30,30 @@ SQL >
ip,
CONCAT(country, '-', region) as region_processed,
splitByString('?', referer_url)[1] as referer_url_processed,
- 'click' as event
- FROM dub_click_events_id
+ 'lead' as event,
+ event_id,
+ event_name,
+ metadata
+ FROM dub_lead_events_mv
WHERE
- click_id
+ customer_id
= {{
String(
- clickId,
- '8bBSF1CbVlXRCMJY',
- description="The unique ID for a given click event",
+ customerId,
+ 'cus_1JRJNSVARH220RCNJ2K5SAX9Q',
+ description="The unique ID for a given customer",
required=True,
)
}}
{% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}
+ AND timestamp >= {{ DateTime(start, '2024-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 %}
LIMIT {{ Int32(limit, 100) }}
-NODE lead_events
+NODE click_events
SQL >
%
@@ -73,24 +79,11 @@ SQL >
ip,
CONCAT(country, '-', region) as region_processed,
splitByString('?', referer_url)[1] as referer_url_processed,
- 'lead' as event,
- event_id,
- event_name
- FROM dub_lead_events_mv
+ 'click' as event
+ FROM dub_click_events_id
WHERE
- customer_id
- = {{
- String(
- customerId,
- 'cm1a18x7w0001aqhx744lrtxp',
- description="The unique ID for a given customer",
- required=True,
- )
- }}
+ click_id IN (SELECT DISTINCT click_id FROM lead_events)
{% 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 %}
LIMIT {{ Int32(limit, 100) }}
@@ -124,6 +117,7 @@ SQL >
'sale' as event,
event_id,
event_name,
+ metadata,
amount as saleAmount,
invoice_id,
payment_processor
@@ -133,7 +127,7 @@ SQL >
= {{
String(
customerId,
- 'cm1a18x7w0001aqhx744lrtxp',
+ 'cus_1JRJNSVARH220RCNJ2K5SAX9Q',
description="The unique ID for a given customer",
required=True,
)
@@ -149,26 +143,25 @@ NODE endpoint
SQL >
%
- SELECT *
- FROM
- (
- {% if defined(clickId) %}
- SELECT
- *,
- NULL AS event_id,
- NULL AS event_name,
- NULL AS saleAmount,
- NULL AS invoice_id,
- NULL AS payment_processor
- FROM click_events
- UNION ALL
- {% end %}
- SELECT *, NULL AS saleAmount, NULL AS invoice_id, NULL AS payment_processor
- FROM lead_events
- UNION ALL
- SELECT *
- FROM sale_events
- )
- ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
+ SELECT *
+ FROM
+ (
+ SELECT *, NULL AS saleAmount, NULL AS invoice_id, NULL AS payment_processor
+ FROM lead_events
+ UNION ALL
+ SELECT
+ *,
+ NULL AS event_id,
+ NULL AS event_name,
+ NULL AS metadata,
+ NULL AS saleAmount,
+ NULL AS invoice_id,
+ NULL AS payment_processor
+ FROM click_events
+ UNION ALL
+ SELECT *
+ FROM sale_events
+ )
+ ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}