The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
v2_count_new -> v2_count
Tim Wilson5d79d7c819da
diff --git a/apps/web/lib/analytics/constants.ts b/apps/web/lib/analytics/constants.tsindex dc6b1863b2..6635c0d7cd 100644--- a/apps/web/lib/analytics/constants.ts+++ b/apps/web/lib/analytics/constants.ts@@ -114,7 +114,6 @@ export const INTERVAL_DATA: Record<export const VALID_ANALYTICS_ENDPOINTS = ["count",- "count_new","timeseries","continents","regions",diff --git a/apps/web/lib/analytics/get-analytics.ts b/apps/web/lib/analytics/get-analytics.tsindex 728fba1c7e..c3ca94f3d6 100644--- a/apps/web/lib/analytics/get-analytics.ts+++ b/apps/web/lib/analytics/get-analytics.ts@@ -44,7 +44,7 @@ export const getAnalytics = async (params: AnalyticsFilters) => {// 5. no other dimensional filters are appliedif (linkId &&- ["count", "count_new"].includes(groupBy) &&+ groupBy === "count" &&interval === "all" &&!start &&!end &&@@ -121,7 +121,7 @@ export const getAnalytics = async (params: AnalyticsFilters) => {region,});- if (["count", "count_new"].includes(groupBy)) {+ if (groupBy === "count") {// Return the count value for deprecated endpointsif (isDeprecatedClicksEndpoint) {return response.data[0][event];diff --git a/apps/web/lib/zod/schemas/analytics-response.ts b/apps/web/lib/zod/schemas/analytics-response.tsindex 23058ec68b..86f4a9ccbe 100644--- a/apps/web/lib/zod/schemas/analytics-response.ts+++ b/apps/web/lib/zod/schemas/analytics-response.ts@@ -38,17 +38,6 @@ export const analyticsResponse = {.default(0),}).openapi({ ref: "AnalyticsCount", title: "AnalyticsCount" }),- count_new: z- .object({- clicks: z.number().describe("The total number of clicks").default(0),- leads: z.number().describe("The total number of leads").default(0),- sales: z.number().describe("The total number of sales").default(0),- saleAmount: z- .number()- .describe("The total amount of sales, in cents")- .default(0),- })- .openapi({ ref: "AnalyticsCount", title: "AnalyticsCount" }),timeseries: z.object({start: z.string().describe("The starting timestamp of the interval"),diff --git a/apps/web/ui/partners/overview/blocks/sale-type-block.tsx b/apps/web/ui/partners/overview/blocks/sale-type-block.tsxindex bbf3701bd3..ee2378f934 100644--- a/apps/web/ui/partners/overview/blocks/sale-type-block.tsx+++ b/apps/web/ui/partners/overview/blocks/sale-type-block.tsx@@ -25,7 +25,7 @@ export function SaleTypeBlock() {}>(`/api/analytics?${editQueryString(queryString, {event: "sales",- groupBy: "count_new",+ groupBy: "count",saleType: "recurring",})}`,fetcher,diff --git a/packages/tinybird/pipes/v2_count.pipe b/packages/tinybird/pipes/v2_count.pipeindex 9b6fb8d088..0fdae48d16 100644--- a/packages/tinybird/pipes/v2_count.pipe+++ b/packages/tinybird/pipes/v2_count.pipe@@ -125,10 +125,13 @@ NODE count_salesSQL >%- SELECT sales, amount, amount AS saleAmount- FROM- (- SELECT COUNT(*) as sales, sum(amount) as amount+ WITH+ sale_rankings AS (+ SELECT+ *,+ ROW_NUMBER() OVER (+ PARTITION BY customer_id, link_id ORDER BY timestamp ASC+ ) as sale_rankFROMdub_sale_events_mv{% if not defined(linkId) and (@@ -174,6 +177,19 @@ SQL >{% if defined(url) %} AND url = {{ url }} {% end %}{% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %}+ )+ SELECT sales, amount, amount AS saleAmount+ FROM+ (+ SELECT COUNT(*) as sales, sum(amount) as amount+ FROM sale_rankings+ WHERE+ 1 = 1+ {% if defined(saleType) %}+ {% if saleType == 'new' %} AND sale_rank = 1+ {% elif saleType == 'recurring' %} AND sale_rank > 1+ {% end %}+ {% end %}) AS subquerydiff --git a/packages/tinybird/pipes/v2_count_new.pipe b/packages/tinybird/pipes/v2_count_new.pipedeleted file mode 100644index 0fdae48d16..0000000000--- a/packages/tinybird/pipes/v2_count_new.pipe+++ /dev/null@@ -1,216 +0,0 @@-DESCRIPTION >- Top countries---TAGS "Dub Endpoints"--NODE workspace_links-SQL >-- %- SELECT link_id- FROM- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest- {% else %} dub_regular_links_metadata_latest- {% end %} FINAL- WHERE- deleted == 0- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}- {% elif defined(folderId) %} AND folder_id = {{ folderId }}- {% end %}- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}- {% if defined(tagIds) %}- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []- {% end %}- {% if defined(root) %}- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}- {% end %}----NODE count_clicks-SQL >-- %- SELECT COUNT(*) as clicks- FROM- {% if defined(customerId) %} dub_click_events_id- {% else %} dub_click_events_mv- {% end %}- {% if defined(customerId) %}- PREWHERE click_id IN (- SELECT DISTINCT click_id- FROM dub_lead_events_mv- WHERE customer_id = {{ String(customerId) }}- )- {% elif not defined(linkId) and (- defined(workspaceId) or defined(partnerId) or defined(programId)- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)- {% end %}- WHERE- true- {% if defined(linkId) %} AND link_id = {{ String(linkId) }} {% end %}- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}- {% if defined(continent) %} AND continent = {{ continent }} {% end %}- {% if defined(country) %} AND country = {{ country }} {% end %}- {% if defined(region) %} AND region = {{ region }} {% end %}- {% if defined(city) %} AND city = {{ city }} {% end %}- {% if defined(device) %} AND device = {{ device }} {% end %}- {% if defined(browser) %} AND browser = {{ browser }} {% end %}- {% if defined(os) %} AND os = {{ os }} {% end %}- {% if defined(referer) %} AND referer = {{ referer }} {% end %}- {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %}- {% if defined(utm_source) %}- AND url LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')- {% end %}- {% if defined(utm_medium) %}- AND url LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')- {% end %}- {% if defined(utm_campaign) %}- AND url- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')- {% end %}- {% if defined(utm_term) %}- AND url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')- {% end %}- {% if defined(utm_content) %}- AND url LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')- {% end %}- {% if defined(url) %} AND url = {{ url }} {% end %}- {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %}- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}----NODE count_leads-SQL >-- %- SELECT COUNT(*) as leads- FROM- dub_lead_events_mv- {% if not defined(linkId) and (defined(workspaceId) or defined(partnerId) or defined(programId)) %}- PREWHERE link_id in (SELECT link_id from workspace_links)- {% end %}- WHERE- true- {% if defined(linkId) %} AND link_id = {{ String(linkId) }} {% end %}- {% if defined(customerId) %} AND customer_id = {{ String(customerId) }} {% end %}- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}- {% if defined(continent) %} AND continent = {{ continent }} {% end %}- {% if defined(country) %} AND country = {{ country }} {% end %}- {% if defined(region) %} AND region = {{ region }} {% end %}- {% if defined(city) %} AND city = {{ city }} {% end %}- {% if defined(device) %} AND device = {{ device }} {% end %}- {% if defined(browser) %} AND browser = {{ browser }} {% end %}- {% if defined(os) %} AND os = {{ os }} {% end %}- {% if defined(referer) %} AND referer = {{ referer }} {% end %}- {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %}- {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%') {% end %}- {% if defined(url) %} AND url = {{ url }} {% end %}- {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %}- {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %}----NODE count_sales-SQL >-- %- WITH- sale_rankings AS (- SELECT- *,- ROW_NUMBER() OVER (- PARTITION BY customer_id, link_id ORDER BY timestamp ASC- ) as sale_rank- FROM- dub_sale_events_mv- {% if not defined(linkId) and (- defined(workspaceId) or defined(partnerId) or defined(programId)- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}- WHERE- true- {% if defined(linkId) %} AND link_id = {{ String(linkId) }} {% end %}- {% if defined(customerId) %} AND customer_id = {{ String(customerId) }} {% end %}- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}- {% if defined(continent) %} AND continent = {{ continent }} {% end %}- {% if defined(country) %} AND country = {{ country }} {% end %}- {% if defined(region) %} AND region = {{ region }} {% end %}- {% if defined(city) %} AND city = {{ city }} {% end %}- {% if defined(device) %} AND device = {{ device }} {% end %}- {% if defined(browser) %} AND browser = {{ browser }} {% end %}- {% if defined(os) %} AND os = {{ os }} {% end %}- {% if defined(referer) %} AND referer = {{ referer }} {% end %}- {% if defined(refererUrl) %}- AND splitByString('?', referer_url)[1] = {{ refererUrl }}- {% end %}- {% if defined(utm_source) %}- AND url- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')- {% end %}- {% if defined(utm_medium) %}- AND url- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')- {% end %}- {% if defined(utm_campaign) %}- AND url LIKE concat(- '%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%'- )- {% end %}- {% if defined(utm_term) %}- AND url- LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')- {% end %}- {% if defined(utm_content) %}- AND url- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')- {% end %}- {% if defined(url) %} AND url = {{ url }} {% end %}- {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %}- {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %}- )- SELECT sales, amount, amount AS saleAmount- FROM- (- SELECT COUNT(*) as sales, sum(amount) as amount- FROM sale_rankings- WHERE- 1 = 1- {% if defined(saleType) %}- {% if saleType == 'new' %} AND sale_rank = 1- {% elif saleType == 'recurring' %} AND sale_rank > 1- {% end %}- {% end %}- ) AS subquery----NODE count_composite-SQL >-- SELECT clicks, leads, sales, amount, saleAmount FROM count_clicks, count_leads, count_sales----NODE endpoint-SQL >-- %- SELECT *- FROM- {% if eventType == 'clicks' %} count_clicks- {% elif eventType == 'leads' %} count_leads- {% elif eventType == 'sales' %} count_sales- {% else %} count_composite- {% end %}--