The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update v2_top_partners.pipe
Steven Tey017f8b8e9666
diff --git a/packages/tinybird/pipes/v2_top_partners.pipe b/packages/tinybird/pipes/v2_top_partners.pipeindex 144f0c1782..119ec72791 100644--- a/packages/tinybird/pipes/v2_top_partners.pipe+++ b/packages/tinybird/pipes/v2_top_partners.pipe@@ -17,75 +17,47 @@ NODE top_partners_clicksSQL >%- WITH- sales AS (- SELECT se.customer_id, se.link_id, se.timestamp, se.amount, pl.partner_id- FROM dub_sale_events AS se- JOIN partner_links AS pl ON se.link_id = pl.link_id- WHERE- 1- {% if defined(continent) %} AND se.continent = {{ continent }} {% end %}- {% if defined(country) %} AND se.country = {{ country }} {% end %}- {% if defined(region) %} AND se.region = {{ region }} {% end %}- {% if defined(city) %} AND se.city = {{ city }} {% end %}- {% if defined(device) %} AND se.device = {{ device }} {% end %}- {% if defined(browser) %} AND se.browser = {{ browser }} {% end %}- {% if defined(os) %} AND se.os = {{ os }} {% end %}- {% if defined(referer) %} AND se.referer = {{ referer }} {% end %}- {% if defined(refererUrl) %}- AND splitByString('?', se.referer_url)[1] = {{ refererUrl }}- {% end %}- {% if defined(utm_source) %}- AND se.url- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')- {% end %}- {% if defined(utm_medium) %}- AND se.url- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')- {% end %}- {% if defined(utm_campaign) %}- AND se.url- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')- {% end %}- {% if defined(utm_term) %}- AND se.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')- {% end %}- {% if defined(utm_content) %}- AND se.url- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')- {% end %}- {% if defined(url) %} AND se.url = {{ url }} {% end %}- {% if defined(start) %} AND se.timestamp >= {{ DateTime64(start) }} {% end %}- {% if defined(end) %} AND se.timestamp <= {{ DateTime64(end) }} {% end %}- ),- distinct_sales AS (- SELECT DISTINCT customer_id, link_id- FROM sales- ),- min_timestamps AS (- SELECT- customer_id,- link_id,- min(timestamp) AS first_sale_ts- FROM dub_sale_events- WHERE (customer_id, link_id) IN distinct_sales- GROUP BY customer_id, link_id- )- SELECT pl.partner_id as partnerId, COUNT(*) AS sales, sum(amount) as saleAmount- FROM sales- INNER JOIN min_timestamps USING (customer_id, link_id)- JOIN partner_links AS pl ON sales.link_id = pl.link_id- WHERE- 1 = 1- {% if defined(saleType) %}- {% if saleType == 'new' %} AND timestamp <= first_sale_ts- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts- {% end %}- {% end %}- GROUP BY pl.partner_id- ORDER BY saleAmount DESC- LIMIT 5000-+ SELECT pl.partner_id as partnerId, COUNT(*) AS clicks+ FROM dub_click_events_mv AS ce+ JOIN partner_links AS pl ON ce.link_id = pl.link_id+ WHERE+ 1+ {% if defined(continent) %} AND ce.continent = {{ continent }} {% end %}+ {% if defined(country) %} AND ce.country = {{ country }} {% end %}+ {% if defined(region) %} AND ce.region = {{ region }} {% end %}+ {% if defined(city) %} AND ce.city = {{ city }} {% end %}+ {% if defined(device) %} AND ce.device = {{ device }} {% end %}+ {% if defined(browser) %} AND ce.browser = {{ browser }} {% end %}+ {% if defined(os) %} AND ce.os = {{ os }} {% end %}+ {% if defined(referer) %} AND ce.referer = {{ referer }} {% end %}+ {% if defined(refererUrl) %}+ AND splitByString('?', ce.referer_url)[1] = {{ refererUrl }}+ {% end %}+ {% if defined(utm_source) %}+ AND ce.url+ LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')+ {% end %}+ {% if defined(utm_medium) %}+ AND ce.url+ LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')+ {% end %}+ {% if defined(utm_campaign) %}+ AND ce.url+ LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')+ {% end %}+ {% if defined(utm_term) %}+ AND ce.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')+ {% end %}+ {% if defined(utm_content) %}+ AND ce.url+ LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')+ {% end %}+ {% if defined(url) %} AND ce.url = {{ url }} {% end %}+ {% if defined(start) %} AND ce.timestamp >= {{ DateTime64(start) }} {% end %}+ {% if defined(end) %} AND ce.timestamp <= {{ DateTime64(end) }} {% end %}+ GROUP BY pl.partner_id+ ORDER BY clicks DESC+ LIMIT 5000@@ -93,47 +65,47 @@ NODE top_partners_leadsSQL >%- SELECT pl.partner_id as partnerId, COUNT(*) AS leads- FROM dub_lead_events AS le- JOIN partner_links AS pl ON le.link_id = pl.link_id- WHERE- 1- {% if defined(continent) %} AND le.continent = {{ continent }} {% end %}- {% if defined(country) %} AND le.country = {{ country }} {% end %}- {% if defined(region) %} AND le.region = {{ region }} {% end %}- {% if defined(city) %} AND le.city = {{ city }} {% end %}- {% if defined(device) %} AND le.device = {{ device }} {% end %}- {% if defined(browser) %} AND le.browser = {{ browser }} {% end %}- {% if defined(os) %} AND le.os = {{ os }} {% end %}- {% if defined(referer) %} AND le.referer = {{ referer }} {% end %}- {% if defined(refererUrl) %}- AND splitByString('?', le.referer_url)[1] = {{ refererUrl }}- {% end %}- {% if defined(utm_source) %}- AND le.url- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')- {% end %}- {% if defined(utm_medium) %}- AND le.url- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')- {% end %}- {% if defined(utm_campaign) %}- AND le.url- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')- {% end %}- {% if defined(utm_term) %}- AND le.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')- {% end %}- {% if defined(utm_content) %}- AND le.url- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')- {% end %}- {% if defined(url) %} AND le.url = {{ url }} {% end %}- {% if defined(start) %} AND le.timestamp >= {{ DateTime64(start) }} {% end %}- {% if defined(end) %} AND le.timestamp <= {{ DateTime64(end) }} {% end %}- GROUP BY pl.partner_id- ORDER BY leads DESC- LIMIT 5000+ SELECT pl.partner_id as partnerId, COUNT(*) AS leads+ FROM dub_lead_events AS le+ JOIN partner_links AS pl ON le.link_id = pl.link_id+ WHERE+ 1+ {% if defined(continent) %} AND le.continent = {{ continent }} {% end %}+ {% if defined(country) %} AND le.country = {{ country }} {% end %}+ {% if defined(region) %} AND le.region = {{ region }} {% end %}+ {% if defined(city) %} AND le.city = {{ city }} {% end %}+ {% if defined(device) %} AND le.device = {{ device }} {% end %}+ {% if defined(browser) %} AND le.browser = {{ browser }} {% end %}+ {% if defined(os) %} AND le.os = {{ os }} {% end %}+ {% if defined(referer) %} AND le.referer = {{ referer }} {% end %}+ {% if defined(refererUrl) %}+ AND splitByString('?', le.referer_url)[1] = {{ refererUrl }}+ {% end %}+ {% if defined(utm_source) %}+ AND le.url+ LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')+ {% end %}+ {% if defined(utm_medium) %}+ AND le.url+ LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')+ {% end %}+ {% if defined(utm_campaign) %}+ AND le.url+ LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')+ {% end %}+ {% if defined(utm_term) %}+ AND le.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')+ {% end %}+ {% if defined(utm_content) %}+ AND le.url+ LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')+ {% end %}+ {% if defined(url) %} AND le.url = {{ url }} {% end %}+ {% if defined(start) %} AND le.timestamp >= {{ DateTime64(start) }} {% end %}+ {% if defined(end) %} AND le.timestamp <= {{ DateTime64(end) }} {% end %}+ GROUP BY pl.partner_id+ ORDER BY leads DESC+ LIMIT 5000@@ -141,47 +113,47 @@ NODE top_partners_salesSQL >%- SELECT pl.partner_id as partnerId, COUNT(*) AS sales, sum(amount) as saleAmount- FROM dub_sale_events AS se- JOIN partner_links AS pl ON se.link_id = pl.link_id- WHERE- 1- {% if defined(continent) %} AND se.continent = {{ continent }} {% end %}- {% if defined(country) %} AND se.country = {{ country }} {% end %}- {% if defined(region) %} AND se.region = {{ region }} {% end %}- {% if defined(city) %} AND se.city = {{ city }} {% end %}- {% if defined(device) %} AND se.device = {{ device }} {% end %}- {% if defined(browser) %} AND se.browser = {{ browser }} {% end %}- {% if defined(os) %} AND se.os = {{ os }} {% end %}- {% if defined(referer) %} AND se.referer = {{ referer }} {% end %}- {% if defined(refererUrl) %}- AND splitByString('?', se.referer_url)[1] = {{ refererUrl }}- {% end %}- {% if defined(utm_source) %}- AND se.url- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')- {% end %}- {% if defined(utm_medium) %}- AND se.url- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')- {% end %}- {% if defined(utm_campaign) %}- AND se.url- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')- {% end %}- {% if defined(utm_term) %}- AND se.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')- {% end %}- {% if defined(utm_content) %}- AND se.url- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')- {% end %}- {% if defined(url) %} AND se.url = {{ url }} {% end %}- {% if defined(start) %} AND se.timestamp >= {{ DateTime64(start) }} {% end %}- {% if defined(end) %} AND se.timestamp <= {{ DateTime64(end) }} {% end %}- GROUP BY pl.partner_id- ORDER BY saleAmount DESC, sales DESC, partnerId ASC- LIMIT 5000+ SELECT pl.partner_id as partnerId, COUNT(*) AS sales, sum(amount) as saleAmount+ FROM dub_sale_events AS se+ JOIN partner_links AS pl ON se.link_id = pl.link_id+ WHERE+ 1+ {% if defined(continent) %} AND se.continent = {{ continent }} {% end %}+ {% if defined(country) %} AND se.country = {{ country }} {% end %}+ {% if defined(region) %} AND se.region = {{ region }} {% end %}+ {% if defined(city) %} AND se.city = {{ city }} {% end %}+ {% if defined(device) %} AND se.device = {{ device }} {% end %}+ {% if defined(browser) %} AND se.browser = {{ browser }} {% end %}+ {% if defined(os) %} AND se.os = {{ os }} {% end %}+ {% if defined(referer) %} AND se.referer = {{ referer }} {% end %}+ {% if defined(refererUrl) %}+ AND splitByString('?', se.referer_url)[1] = {{ refererUrl }}+ {% end %}+ {% if defined(utm_source) %}+ AND se.url+ LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')+ {% end %}+ {% if defined(utm_medium) %}+ AND se.url+ LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')+ {% end %}+ {% if defined(utm_campaign) %}+ AND se.url+ LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')+ {% end %}+ {% if defined(utm_term) %}+ AND se.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')+ {% end %}+ {% if defined(utm_content) %}+ AND se.url+ LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')+ {% end %}+ {% if defined(url) %} AND se.url = {{ url }} {% end %}+ {% if defined(start) %} AND se.timestamp >= {{ DateTime64(start) }} {% end %}+ {% if defined(end) %} AND se.timestamp <= {{ DateTime64(end) }} {% end %}+ GROUP BY pl.partner_id+ ORDER BY saleAmount DESC, sales DESC, partnerId ASC+ LIMIT 5000@@ -260,7 +232,7 @@ NODE top_partners_compositeSQL >%- SELECT c.partnerId as partnerId, c.sales as clicks, l.leads, s.sales, s.saleAmount+ SELECT c.partnerId as partnerId, c.clicks, l.leads, s.sales, s.saleAmountFROM top_partners_clicks AS cLEFT JOIN top_partners_leads AS l ON c.partnerId = l.partnerIdLEFT JOIN