The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
update v2_ pipes
Steven Tey6960d3e5ac46
diff --git a/packages/tinybird/pipes/v2_browsers.pipe b/packages/tinybird/pipes/v2_browsers.pipeindex 12ad08294f..300485afa3 100644--- a/packages/tinybird/pipes/v2_browsers.pipe+++ b/packages/tinybird/pipes/v2_browsers.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_browsers_endpoint_read_1118" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -33,9 +38,18 @@ SQL >%SELECT browser, COUNT(browser) as clicksFROM- dub_click_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)+ {% 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 %}WHEREbrowser != 'Unknown'@@ -50,11 +64,22 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -76,6 +101,7 @@ SQL >WHEREbrowser != 'Unknown'{% 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 %}@@ -86,11 +112,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -118,6 +144,7 @@ SQL >WHEREbrowser != 'Unknown'{% 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 %}@@ -128,11 +155,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -165,3 +192,4 @@ SQL >{% else %} browsers_composite{% end %}+diff --git a/packages/tinybird/pipes/v2_cities.pipe b/packages/tinybird/pipes/v2_cities.pipeindex 1f338958d9..70e6d927bd 100644--- a/packages/tinybird/pipes/v2_cities.pipe+++ b/packages/tinybird/pipes/v2_cities.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_cities_endpoint_read_6984" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -33,8 +38,16 @@ SQL >%SELECT city, country, COUNT(city) as clicksFROM- dub_click_events_mv- {% if not defined(linkId) and (defined(workspaceId) or defined(partnerId) or defined(programId)) %}+ {% 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@@ -50,11 +63,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -76,6 +89,7 @@ SQL >WHEREcity != 'Unknown'{% 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 %}@@ -86,11 +100,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -119,6 +133,7 @@ SQL >WHEREcity != 'Unknown'{% 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 %}@@ -129,11 +144,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}diff --git a/packages/tinybird/pipes/v2_continents.pipe b/packages/tinybird/pipes/v2_continents.pipeindex 020a434bbc..926ad0baf3 100644--- a/packages/tinybird/pipes/v2_continents.pipe+++ b/packages/tinybird/pipes/v2_continents.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top continents-TOKEN "v2_continents_endpoint_read_0662" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -33,9 +38,18 @@ SQL >%SELECT continent, COUNT(continent) as clicksFROM- dub_click_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)+ {% 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 %}WHEREcontinent != ''@@ -59,11 +73,22 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -94,6 +119,7 @@ SQL >)}}{% 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 %}@@ -104,11 +130,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -145,6 +171,7 @@ SQL >)}}{% 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 %}@@ -155,11 +182,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}diff --git a/packages/tinybird/pipes/v2_count.pipe b/packages/tinybird/pipes/v2_count.pipeindex 2f8202fa93..9b6fb8d088 100644--- a/packages/tinybird/pipes/v2_count.pipe+++ b/packages/tinybird/pipes/v2_count.pipe@@ -38,20 +38,22 @@ SQL >%SELECT COUNT(*) as clicksFROM- dub_click_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)+ {% if defined(customerId) %} dub_click_events_id+ {% else %} dub_click_events_mv{% end %}- WHERE- true- {% if defined(linkId) %} AND link_id = {{ String(linkId) }} {% end %}- {% if defined(customerId) %}- AND link_id IN (- SELECT DISTINCT link_id- FROM dub_lead_events_mv+ {% if defined(customerId) %}+ PREWHERE click_id IN (+ SELECT DISTINCT click_id+ FROM dub_lead_events_mvWHERE 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 %}@@ -62,11 +64,22 @@ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -112,40 +125,56 @@ NODE count_salesSQL >%- SELECT- sales,- amount,- amount AS saleAmount- FROM (- SELECT COUNT(*) as sales, sum(amount) as amount- 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 %}- ) AS subquery+ SELECT sales, amount, amount AS saleAmount+ FROM+ (+ SELECT COUNT(*) as sales, sum(amount) as amount+ 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 %}+ ) AS subquerydiff --git a/packages/tinybird/pipes/v2_countries.pipe b/packages/tinybird/pipes/v2_countries.pipeindex fcdd2f2e60..1fd9b6d25d 100644--- a/packages/tinybird/pipes/v2_countries.pipe+++ b/packages/tinybird/pipes/v2_countries.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_countries_endpoint_read_6734" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -33,8 +38,16 @@ SQL >%SELECT country, COUNT(country) as clicksFROM- dub_click_events_mv- {% if not defined(linkId) and (defined(workspaceId) or defined(partnerId) or defined(programId)) %}+ {% 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@@ -59,11 +72,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -94,6 +107,7 @@ SQL >)}}{% 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 %}@@ -104,11 +118,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -145,6 +159,7 @@ SQL >)}}{% 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 %}@@ -155,11 +170,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -192,3 +207,4 @@ SQL >{% else %} countries_composite{% end %}+diff --git a/packages/tinybird/pipes/v2_devices.pipe b/packages/tinybird/pipes/v2_devices.pipeindex 0c98d07c24..8555c81c5e 100644--- a/packages/tinybird/pipes/v2_devices.pipe+++ b/packages/tinybird/pipes/v2_devices.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_devices_endpoint_read_4705" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -33,9 +38,18 @@ SQL >%SELECT device, COUNT(device) as clicksFROM- dub_click_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)+ {% 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 %}WHEREdevice != 'Unknown'@@ -50,11 +64,22 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -76,6 +101,7 @@ SQL >WHEREdevice != 'Unknown'{% 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 %}@@ -86,11 +112,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -118,6 +144,7 @@ SQL >WHEREdevice != 'Unknown'{% 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 %}@@ -128,11 +155,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}diff --git a/packages/tinybird/pipes/v2_events.pipe b/packages/tinybird/pipes/v2_events.pipeindex c6e5b9b5db..593dff0d6c 100644--- a/packages/tinybird/pipes/v2_events.pipe+++ b/packages/tinybird/pipes/v2_events.pipe@@ -41,20 +41,19 @@ SQL >splitByString('?', referer_url)[1] as referer_url_processed,CONCAT(country, '-', region) as region_processed,'click' as event- FROM dub_click_events_mv+ FROM {% if defined(customerId) %} dub_click_events_id {% else %} dub_click_events_mv {% end %}WHEREtimestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }}- {% if defined(linkId) %} AND link_id = {{ String(linkId) }}- {% elif defined(workspaceId) or defined(partnerId) or defined(programId) %}- AND link_id IN (SELECT link_id FROM workspace_links)- {% end %}- {% if defined(customerId) %}+ {% if defined(customerId) %}AND click_id IN (- SELECT DISTINCT click_id- FROM lead_events+ SELECT DISTINCT click_id+ FROM dub_lead_events_mvWHERE customer_id = {{ String(customerId) }})+ {% elif defined(linkId) %} AND link_id = {{ String(linkId) }}+ {% elif defined(workspaceId) or defined(partnerId) or defined(programId) %}+ AND link_id IN (SELECT link_id FROM workspace_links){% end %}{% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}{% if defined(continent) %} AND continent = {{ continent }} {% end %}@@ -66,11 +65,22 @@ 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 %}ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}LIMIT {{ Int32(limit, 100) }}@@ -87,7 +97,7 @@ SQL >splitByString('?', referer_url)[1] as referer_url_processed,CONCAT(country, '-', region) as region_processed,'lead' as event- FROM dub_lead_events_mv_new+ FROM dub_lead_events_mvWHEREtimestamp >= {{ DateTime(start, '2024-01-01 00:00:00') }}AND timestamp < {{ DateTime(end, '2025-12-31 00:00:00') }}@@ -139,7 +149,7 @@ SQL >CONCAT(country, '-', region) as region_processed,splitByString('?', referer_url)[1] as referer_url_processed,'sale' as event- FROM dub_sale_events_mv_new+ FROM dub_sale_events_mvWHEREtimestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }}diff --git a/packages/tinybird/pipes/v2_os.pipe b/packages/tinybird/pipes/v2_os.pipeindex 577cae12a5..8c0874617e 100644--- a/packages/tinybird/pipes/v2_os.pipe+++ b/packages/tinybird/pipes/v2_os.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_os_endpoint_read_0301" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -33,9 +38,18 @@ SQL >%SELECT os, COUNT(os) as clicksFROM- dub_click_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)+ {% 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 %}WHEREos != 'Unknown'@@ -50,11 +64,22 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -76,6 +101,7 @@ SQL >WHEREos != 'Unknown'{% 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 %}@@ -86,11 +112,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -118,6 +144,7 @@ SQL >WHEREos != 'Unknown'{% 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 %}@@ -128,11 +155,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}diff --git a/packages/tinybird/pipes/v2_referer_urls.pipe b/packages/tinybird/pipes/v2_referer_urls.pipeindex 901bddfe80..23b91c2bc7 100644--- a/packages/tinybird/pipes/v2_referer_urls.pipe+++ b/packages/tinybird/pipes/v2_referer_urls.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_referer_urls_endpoint_read_1826" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -52,11 +57,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -79,6 +84,7 @@ SQL >WHEREtrue{% 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 %}@@ -89,11 +95,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -122,6 +128,7 @@ SQL >WHEREreferer != 'Unknown'{% 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 %}@@ -132,11 +139,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}diff --git a/packages/tinybird/pipes/v2_referers.pipe b/packages/tinybird/pipes/v2_referers.pipeindex 7ec6508dbd..0b56aa70f3 100644--- a/packages/tinybird/pipes/v2_referers.pipe+++ b/packages/tinybird/pipes/v2_referers.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_referers_endpoint_read_1177" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -33,9 +38,18 @@ SQL >%SELECT referer, COUNT(referer) as clicksFROM- dub_click_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)+ {% 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 %}WHEREtrue@@ -50,11 +64,22 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -76,6 +101,7 @@ SQL >WHEREtrue{% 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 %}@@ -86,11 +112,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -118,6 +144,7 @@ SQL >WHEREtrue{% 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 %}@@ -128,11 +155,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}diff --git a/packages/tinybird/pipes/v2_regions.pipe b/packages/tinybird/pipes/v2_regions.pipeindex da0324a63c..0c42ff5c64 100644--- a/packages/tinybird/pipes/v2_regions.pipe+++ b/packages/tinybird/pipes/v2_regions.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_regions_endpoint_read_9112" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -56,11 +61,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -89,6 +94,7 @@ SQL >region NOT IN ('Unknown', 'arn1', 'bom1', 'cdg1', 'cle1', 'cpt1', 'dub1', 'fra1', 'gru1', 'hkg1', 'hnd1', 'iad1', 'icn1', 'kix1', 'lhr1', 'pdx1', 'sfo1', 'sin1', 'syd1')AND country != 'Unknown'{% 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 %}@@ -99,11 +105,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -134,6 +140,7 @@ SQL >region NOT IN ('Unknown', 'arn1', 'bom1', 'cdg1', 'cle1', 'cpt1', 'dub1', 'fra1', 'gru1', 'hkg1', 'hnd1', 'iad1', 'icn1', 'kix1', 'lhr1', 'pdx1', 'sfo1', 'sin1', 'syd1')AND country != 'Unknown'{% 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 %}@@ -144,11 +151,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}diff --git a/packages/tinybird/pipes/v2_timeseries.pipe b/packages/tinybird/pipes/v2_timeseries.pipeindex cb4f69a50a..9d32ee9d51 100644--- a/packages/tinybird/pipes/v2_timeseries.pipe+++ b/packages/tinybird/pipes/v2_timeseries.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Timeseries data-TOKEN "v2_timeseries_endpoint_read_8675" READ-TAGS "Dub Endpoints"NODE month_intervals@@ -49,7 +47,7 @@ SQL >arrayJoin(arrayMap(x -> toDateTime64(toStartOfDay(toDateTime64(x, 3), {{ String(timezone, 'UTC') }}), 3),- range(toUInt32(start + 86400), toUInt32(end + 86400),+ range(toUInt32(start), toUInt32(end + 86400),86400))@@ -73,7 +71,7 @@ SQL >endSELECTarrayJoin(- arrayMap(x -> toDateTime64(x, 3), range(toUInt32(start + 3600), toUInt32(end + 3600), 3600)+ arrayMap(x -> toDateTime64(x, 3), range(toUInt32(start), toUInt32(end + 3600), 3600))) as interval@@ -84,16 +82,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -114,11 +119,20 @@ SQL >){% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3){% end %} AS interval,- uniq(*) as clicks+ uniq(click_id) as clicksFROM- dub_click_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)+ {% 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 %}WHEREtrue@@ -133,11 +147,22 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}@@ -184,6 +209,7 @@ SQL >WHEREtrue{% 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 %}@@ -194,11 +220,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}@@ -249,6 +275,7 @@ SQL >WHEREtrue{% 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 %}@@ -259,11 +286,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}diff --git a/packages/tinybird/pipes/v2_top_links.pipe b/packages/tinybird/pipes/v2_top_links.pipeindex 021435ad7b..6854c7a55b 100644--- a/packages/tinybird/pipes/v2_top_links.pipe+++ b/packages/tinybird/pipes/v2_top_links.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_top_links_endpoint_read_5142" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -33,9 +38,18 @@ SQL >%SELECT link_id as link, COUNT(*) AS clicksFROM- dub_click_events_mv- {% if defined(workspaceId) or defined(partnerId) or defined(programId) %}- PREWHERE link_id in (SELECT link_id from workspace_links)+ {% 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 %}WHEREtrue@@ -50,17 +64,28 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}GROUP BY link_idORDER BY clicks DESC- LIMIT 5000+ LIMIT 1000@@ -71,12 +96,13 @@ SQL >SELECT link_id as link, COUNT(*) AS leadsFROMdub_lead_events_mv- {% if defined(workspaceId) or defined(partnerId) or defined(programId) %}+ {% if not defined(linkId) and (defined(workspaceId) or defined(partnerId) or defined(programId)) %}PREWHERE link_id in (SELECT link_id from workspace_links){% end %}WHEREtrue{% 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 %}@@ -87,11 +113,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -114,12 +140,13 @@ SQL >SELECT link_id as link, COUNT(*) as sales, sum(amount) as amountFROMdub_sale_events_mv- {% if defined(workspaceId) or defined(partnerId) or defined(programId) %}+ {% if not defined(linkId) and (defined(workspaceId) or defined(partnerId) or defined(programId)) %}PREWHERE link_id in (SELECT link_id from workspace_links){% end %}WHEREtrue{% 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 %}@@ -130,17 +157,17 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}GROUP BY link_idORDER BY sales DESC- LIMIT 5000+ LIMIT 1000) as subquerydiff --git a/packages/tinybird/pipes/v2_top_tags.pipe b/packages/tinybird/pipes/v2_top_tags.pipenew file mode 100644index 0000000000..9132b119b7--- /dev/null+++ b/packages/tinybird/pipes/v2_top_tags.pipe@@ -0,0 +1,283 @@+DESCRIPTION >+ Top countries+++TAGS "Dub Endpoints"++NODE workspace_links_with_tags+SQL >++ %+ SELECT link_id, arrayJoin(tag_ids) as tag_id+ FROM dub_links_metadata_latest 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(folderId) %} AND folder_id = {{ folderId }} {% end %}+ {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}+ {% if defined(root) %}+ {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}+ {% end %}++++NODE top_tags_clicks+SQL >++ %+ SELECT tag_id, COUNT(*) AS clicks+ FROM (SELECT link_id, tag_id FROM workspace_links_with_tags) AS tags+ JOIN+ (+ SELECT link_id+ FROM+ dub_click_events_mv+ {% if defined(workspaceId) or defined(partnerId) or defined(programId) %}+ PREWHERE link_id in (SELECT link_id from workspace_links_with_tags)+ {% end %}+ WHERE+ true+ {% 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 %}+ ) AS clicks+ ON clicks.link_id = tags.link_id+ GROUP BY tag_id+ ORDER BY clicks DESC+ LIMIT 5000++++NODE top_tags_leads+SQL >++ %+ SELECT tag_id, COUNT(*) AS leads+ FROM (SELECT link_id, tag_id FROM workspace_links_with_tags) AS tags+ JOIN+ (+ SELECT link_id+ FROM+ dub_lead_events_mv+ {% if defined(workspaceId) or defined(partnerId) or defined(programId) %}+ PREWHERE link_id in (SELECT link_id from workspace_links_with_tags)+ {% end %}+ WHERE+ true+ {% if defined(customerId) %} AND customer_id = {{ String(customerId) }} {% 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 %}+ ) AS leads+ ON leads.link_id = tags.link_id+ GROUP BY tag_id+ ORDER BY leads DESC+ LIMIT 5000++++NODE top_tags_sales+SQL >++ %+ SELECT tag_id, sales, amount, amount AS saleAmount+ FROM+ (+ SELECT tag_id, COUNT(*) as sales, sum(amount) as amount+ FROM (SELECT link_id, tag_id FROM workspace_links_with_tags) AS tags+ JOIN+ (+ SELECT link_id, amount+ FROM+ dub_sale_events_mv+ {% if defined(workspaceId) or defined(partnerId) or defined(programId) %}+ PREWHERE link_id in (SELECT link_id from workspace_links_with_tags)+ {% end %}+ WHERE+ true+ {% if defined(customerId) %} AND customer_id = {{ String(customerId) }} {% 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 %}+ ) AS sales+ ON sales.link_id = tags.link_id+ GROUP BY tag_id+ ORDER BY sales DESC+ LIMIT 5000+ ) as subquery++++NODE top_tags_composite+SQL >++ SELECT COALESCE(c.tag_id, l.tag_id, s.tag_id) as tag_id, clicks, leads, sales, amount, saleAmount+ FROM (SELECT tag_id, clicks FROM top_tags_clicks) AS c+ FULL OUTER JOIN (SELECT tag_id, leads FROM top_tags_leads) AS l ON c.tag_id = l.tag_id+ FULL OUTER JOIN+ (SELECT tag_id, sales, amount, saleAmount FROM top_tags_sales) AS s+ ON COALESCE(c.tag_id, l.tag_id) = s.tag_id+ ORDER BY clicks DESC NULLS LAST++++NODE endpoint+SQL >++ %+ SELECT *+ FROM+ {% if eventType == 'clicks' %} top_tags_clicks+ {% elif eventType == 'leads' %} top_tags_leads+ {% elif eventType == 'sales' %} top_tags_sales+ {% else %} top_tags_composite+ {% end %}++++NODE filtered_clicks+SQL >++ %+ SELECT link_id, COUNT(*) AS clicks+ FROM dub_click_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(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=', {{ String(utm_source) }}, '%')+ {% end %}+ {% if defined(utm_medium) %}+ AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%')+ {% end %}+ {% if defined(utm_campaign) %}+ AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%')+ {% end %}+ {% if defined(utm_term) %}+ AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%')+ {% end %}+ {% if defined(utm_content) %}+ AND url LIKE concat('%utm_content=', {{ 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 %}+ GROUP BY link_id++diff --git a/packages/tinybird/pipes/v2_top_urls.pipe b/packages/tinybird/pipes/v2_top_urls.pipeindex fd8a368937..a2c6332109 100644--- a/packages/tinybird/pipes/v2_top_urls.pipe+++ b/packages/tinybird/pipes/v2_top_urls.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_top_urls_endpoint_read_4482" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -34,7 +39,7 @@ SQL >SELECT url, COUNT(*) AS clicksFROMdub_click_events_mv- {% if defined(workspaceId) or defined(partnerId) or defined(programId) %}+ {% 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@@ -50,11 +55,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -71,12 +76,13 @@ SQL >SELECT url, COUNT(*) AS leadsFROMdub_lead_events_mv- {% if defined(workspaceId) or defined(partnerId) or defined(programId) %}+ {% if not defined(linkId) and (defined(workspaceId) or defined(partnerId) or defined(programId)) %}PREWHERE link_id in (SELECT link_id from workspace_links){% end %}WHEREurl != ''{% 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 %}@@ -87,11 +93,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -114,12 +120,13 @@ SQL >SELECT url, COUNT(*) as sales, sum(amount) as amountFROMdub_sale_events_mv- {% if defined(workspaceId) or defined(partnerId) or defined(programId) %}+ {% if not defined(linkId) and (defined(workspaceId) or defined(partnerId) or defined(programId)) %}PREWHERE link_id in (SELECT link_id from workspace_links){% end %}WHEREurl != ''{% 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 %}@@ -130,11 +137,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}diff --git a/packages/tinybird/pipes/v2_triggers.pipe b/packages/tinybird/pipes/v2_triggers.pipeindex 7097375fcb..5a86db8a2a 100644--- a/packages/tinybird/pipes/v2_triggers.pipe+++ b/packages/tinybird/pipes/v2_triggers.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Top countries-TOKEN "v2_triggers_endpoint_read_4261" READ-TAGS "Dub Endpoints"NODE workspace_links@@ -11,16 +9,23 @@ SQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -33,9 +38,18 @@ SQL >%SELECT CASE WHEN qr = 0 THEN 'link' WHEN qr = 1 THEN 'qr' END as trigger, COUNT(qr) as clicksFROM- dub_click_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)+ {% 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 %}WHEREtrue@@ -50,11 +64,22 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -76,6 +101,7 @@ SQL >WHEREtrue{% 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 %}@@ -86,11 +112,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}@@ -121,6 +147,7 @@ SQL >WHEREtrue{% 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 %}@@ -131,11 +158,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 %}diff --git a/packages/tinybird/pipes/v2_usage.pipe b/packages/tinybird/pipes/v2_usage.pipeindex 8784169fa9..ffb5a23873 100644--- a/packages/tinybird/pipes/v2_usage.pipe+++ b/packages/tinybird/pipes/v2_usage.pipe@@ -2,8 +2,6 @@ DESCRIPTION >Timeseries data-TOKEN "v1_usage_endpoint_read_1647" READ-NODE day_intervalsSQL >diff --git a/packages/tinybird/pipes/v2_utms.pipe b/packages/tinybird/pipes/v2_utms.pipeindex d713070bff..707904fa2b 100644--- a/packages/tinybird/pipes/v2_utms.pipe+++ b/packages/tinybird/pipes/v2_utms.pipe@@ -1,20 +1,25 @@-TOKEN "v2_utms_endpoint_read_8196" READ-NODE workspace_linksSQL >%SELECT link_id- from dub_links_metadata_latest FINAL+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} FINALWHEREdeleted == 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(folderId) %} AND folder_id = {{ folderId }} {% 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(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 %}@@ -27,7 +32,7 @@ SQL >%WITHextractURLParameter(- url,+ decodeURLFormComponent(url),{{String(groupByUtmTag,@@ -39,9 +44,18 @@ SQL >) as utmSELECT utm, count(*) as clicksFROM- dub_click_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)+ {% 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 %}WHEREurl != ''@@ -56,11 +70,22 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -76,7 +101,7 @@ SQL >%WITHextractURLParameter(- url,+ decodeURLFormComponent(url),{{String(groupByUtmTag,@@ -95,6 +120,7 @@ SQL >WHEREurl != ''{% 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 %}@@ -105,11 +131,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}@@ -125,7 +151,7 @@ SQL >%WITHextractURLParameter(- url,+ decodeURLFormComponent(url),{{String(groupByUtmTag,@@ -144,6 +170,7 @@ SQL >WHEREurl != ''{% 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 %}@@ -154,11 +181,11 @@ 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=', {{ String(utm_source) }}, '%') {% end %}- {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %}- {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %}- {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %}- {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ 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 >= {{ DateTime64(start) }} {% end %}{% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}