The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Update v2_cities.pipe
Steven Teya3ec1cc13ff4
diff --git a/packages/tinybird/pipes/v2_cities.pipe b/packages/tinybird/pipes/v2_cities.pipeindex 70e6d927bd..dd3b5c0a6d 100644--- a/packages/tinybird/pipes/v2_cities.pipe+++ b/packages/tinybird/pipes/v2_cities.pipe@@ -36,7 +36,11 @@ NODE cities_clicksSQL >%- SELECT city, country, COUNT(city) as clicks+ SELECT+ city,+ CONCAT(country, '-', region) as region,+ country,+ COUNT(city) as clicksFROM{% if defined(customerId) %} dub_click_events_id{% else %} dub_click_events_mv@@ -52,6 +56,7 @@ SQL >{% end %}WHEREcity != 'Unknown'+ AND region NOT IN ('Unknown', 'arn1', 'bom1', 'cdg1', 'cle1', 'cpt1', 'dub1', 'fra1', 'gru1', 'hkg1', 'hnd1', 'iad1', 'icn1', 'kix1', 'lhr1', 'pdx1', 'sfo1', 'sin1', 'syd1'){% if defined(linkId) %} AND link_id = {{ String(linkId) }} {% end %}{% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}{% if defined(continent) %} AND continent = {{ continent }} {% end %}@@ -71,7 +76,7 @@ SQL >{% if defined(url) %} AND url = {{ url }} {% end %}{% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}- GROUP BY city, country+ GROUP BY city, region, countryORDER BY clicks DESC@@ -80,14 +85,19 @@ NODE cities_leadsSQL >%- SELECT city, country, COUNT(city) as leads+ SELECT+ city,+ CONCAT(country, '-', region) as region,+ country,+ COUNT(city) as leadsFROMdub_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 %}+ {% if not defined(linkId) and (+ defined(workspaceId) or defined(partnerId) or defined(programId)+ ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}WHEREcity != 'Unknown'+ AND region NOT IN ('Unknown', 'arn1', 'bom1', 'cdg1', 'cle1', 'cpt1', 'dub1', 'fra1', 'gru1', 'hkg1', 'hnd1', 'iad1', 'icn1', 'kix1', 'lhr1', 'pdx1', 'sfo1', 'sin1', 'syd1'){% 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 %}@@ -100,15 +110,26 @@ SQL >{% 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(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 %}- GROUP BY city, country+ GROUP BY city, region, countryORDER BY leads DESC@@ -119,12 +140,13 @@ SQL >%SELECTcity,+ CONCAT(country, '-', region) as region,country,sales,amount,amount AS saleAmountFROM (- SELECT city, country, COUNT(city) as sales, sum(amount) as amount+ SELECT city, region, country, COUNT(city) as sales, sum(amount) as amountFROMdub_sale_events_mv{% if not defined(linkId) and (defined(workspaceId) or defined(partnerId) or defined(programId)) %}@@ -132,6 +154,7 @@ SQL >{% end %}WHEREcity != 'Unknown'+ AND region NOT IN ('Unknown', 'arn1', 'bom1', 'cdg1', 'cle1', 'cpt1', 'dub1', 'fra1', 'gru1', 'hkg1', 'hnd1', 'iad1', 'icn1', 'kix1', 'lhr1', 'pdx1', 'sfo1', 'sin1', 'syd1'){% 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 %}@@ -152,7 +175,7 @@ SQL >{% if defined(url) %} AND url = {{ url }} {% end %}{% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %}- GROUP BY city, country+ GROUP BY city, region, countryORDER BY sales DESC) as subquery