Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

update tb pipes

Steven Tey9bbb3cc53743
diff --git a/packages/tinybird/datasources/dub_api_logs.datasource b/packages/tinybird/datasources/dub_api_logs.datasource
index 9b179ba127..e69e91a388 100644
--- a/packages/tinybird/datasources/dub_api_logs.datasource
+++ b/packages/tinybird/datasources/dub_api_logs.datasource
@@ -1,5 +1,6 @@
TOKEN "dub_tinybird_token" APPEND
+
SCHEMA >
`id` String `json:$.id`,
`timestamp` DateTime64(3) `json:$.timestamp`,
@@ -11,7 +12,7 @@ SCHEMA >
`duration` UInt32 `json:$.duration`,
`user_agent` String `json:$.user_agent`,
`request_body` String `json:$.request_body`,
- `query_params` String `json:$.query_params`,
+ `query_params` String `json:$.query_params` DEFAULT '',
`response_body` String `json:$.response_body`,
`token_id` String `json:$.token_id`,
`user_id` String `json:$.user_id`,
diff --git a/packages/tinybird/datasources/dub_conversion_events_log.datasource b/packages/tinybird/datasources/dub_conversion_events_log.datasource
index f540c998ec..3359f0ebd9 100644
--- a/packages/tinybird/datasources/dub_conversion_events_log.datasource
+++ b/packages/tinybird/datasources/dub_conversion_events_log.datasource
@@ -1,5 +1,7 @@
TOKEN "dub_tinybird_token" APPEND
+DESCRIPTION >
+ DEPRECATED: We're using dub_api_logs now. This is kept for posterity
SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
diff --git a/packages/tinybird/datasources/dub_links_metadata_latest.datasource b/packages/tinybird/datasources/dub_links_metadata_latest.datasource
index 603314625d..12fa7dd783 100644
--- a/packages/tinybird/datasources/dub_links_metadata_latest.datasource
+++ b/packages/tinybird/datasources/dub_links_metadata_latest.datasource
@@ -10,9 +10,9 @@ SCHEMA >
`program_id` LowCardinality(String),
`partner_id` String,
`partner_group_id` String,
+ `partner_tag_ids` Array(String),
`folder_id` String,
`tag_ids` Array(String),
- `partner_tag_ids` Array(String) DEFAULT [],
`tenant_id` String,
`created_at` DateTime64(3),
`deleted` UInt8
diff --git a/packages/tinybird/pipes/all_stats.pipe b/packages/tinybird/pipes/all_stats.pipe
index 9e415b9743..e406adda6b 100644
--- a/packages/tinybird/pipes/all_stats.pipe
+++ b/packages/tinybird/pipes/all_stats.pipe
@@ -3,8 +3,13 @@ TAGS "Dub Misc Endpoints"
NODE endpoint
SQL >
- SELECT
- (SELECT COUNT(timestamp) FROM dub_click_events_mv) AS clicks,
+ SELECT
+ (
+ SELECT
+ (SELECT count() FROM dub_click_events_mv)
+ + (SELECT count() FROM dub_lead_events_mv)
+ + (SELECT count() FROM dub_sale_events_mv)
+ ) AS events,
(SELECT COUNT(timestamp) + 42036155 FROM dub_links_metadata) AS links,
(SELECT SUM(amount) FROM dub_sale_events_mv) AS sales
diff --git a/packages/tinybird/pipes/coordinates_all.pipe b/packages/tinybird/pipes/coordinates_all.pipe
index 732f7c376a..228bd5c054 100644
--- a/packages/tinybird/pipes/coordinates_all.pipe
+++ b/packages/tinybird/pipes/coordinates_all.pipe
@@ -3,94 +3,94 @@ TAGS "Dub Misc Endpoints"
NODE coordinates_clicks_data
SQL >
- %
- SELECT
- 'click' AS event,
- timestamp,
- country,
- city,
- latitude,
- longitude,
- device
- FROM dub_click_events_mv
- WHERE
- timestamp > now() - INTERVAL 5 MINUTE
- AND country != 'Unknown' AND city != 'Unknown' AND city != 'Ashburn'
- ORDER BY timestamp DESC
- LIMIT 100
+%
+ SELECT
+ 'click' AS event,
+ timestamp,
+ country,
+ city,
+ latitude,
+ longitude,
+ device
+ FROM dub_click_events_mv
+ WHERE
+ timestamp > now() - INTERVAL 5 MINUTE
+ AND country != 'Unknown' AND city != 'Unknown' AND city != 'Ashburn'
+ ORDER BY timestamp DESC
+ LIMIT 100
NODE coordinates_leads_data
SQL >
- %
- SELECT
- 'lead' AS event,
- timestamp,
- country,
- city,
- latitude,
- longitude,
- device
- FROM dub_lead_events_mv
- WHERE
- timestamp > now() - INTERVAL 12 HOUR
- AND country != 'Unknown'
- AND city != 'Unknown'
- AND city != 'Ashburn'
- ORDER BY timestamp DESC
- LIMIT 100
+%
+ SELECT
+ 'lead' AS event,
+ timestamp,
+ country,
+ city,
+ latitude,
+ longitude,
+ device
+ FROM dub_lead_events_mv
+ WHERE
+ timestamp > now() - INTERVAL 12 HOUR
+ AND country != 'Unknown'
+ AND city != 'Unknown'
+ AND city != 'Ashburn'
+ ORDER BY timestamp DESC
+ LIMIT 100
NODE coordinates_sales_data
SQL >
- %
- SELECT
- 'sale' AS event,
- timestamp,
- country,
- city,
- latitude,
- longitude,
- device,
- amount,
- round(
- amount * arrayElement([0.3, 0.4, 0.5], 1 + (toUnixTimestamp(timestamp) % 3))
- ) as commission
- FROM dub_sale_events_mv
- WHERE
- timestamp > now() - INTERVAL 12 HOUR
- AND country != 'Unknown'
- AND city != 'Unknown'
- AND city != 'Ashburn'
- ORDER BY timestamp DESC
- LIMIT 100
+%
+ SELECT
+ 'sale' AS event,
+ timestamp,
+ country,
+ city,
+ latitude,
+ longitude,
+ device,
+ amount,
+ round(
+ amount * arrayElement([0.3, 0.4, 0.5], 1 + (toUnixTimestamp(timestamp) % 3))
+ ) as commission
+ FROM dub_sale_events_mv
+ WHERE
+ timestamp > now() - INTERVAL 12 HOUR
+ AND country != 'Unknown'
+ AND city != 'Unknown'
+ AND city != 'Ashburn'
+ ORDER BY timestamp DESC
+ LIMIT 100
NODE endpoint
SQL >
- %
- SELECT *
- FROM
- (
- SELECT *, NULL AS amount, NULL AS commission
- FROM coordinates_leads_data
- UNION ALL
- SELECT
- *,
- NULL AS amount,
- NULL AS commission
- FROM coordinates_clicks_data
- UNION ALL
- SELECT *
- FROM coordinates_sales_data
- )
- ORDER BY
- timestamp DESC
+%
+ SELECT *
+ FROM
+ (
+ SELECT *, NULL AS amount, NULL AS commission
+ FROM coordinates_leads_data
+ UNION ALL
+ SELECT
+ *,
+ NULL AS amount,
+ NULL AS commission
+ FROM coordinates_clicks_data
+ UNION ALL
+ SELECT *
+ FROM coordinates_sales_data
+ )
+ ORDER BY
+ timestamp DESC
diff --git a/packages/tinybird/pipes/coordinates_sales.pipe b/packages/tinybird/pipes/coordinates_sales.pipe
index b10fdfec0a..8b241f031b 100644
--- a/packages/tinybird/pipes/coordinates_sales.pipe
+++ b/packages/tinybird/pipes/coordinates_sales.pipe
@@ -3,24 +3,24 @@ TAGS "Dub Misc Endpoints"
NODE endpoint
SQL >
- %
- SELECT
- timestamp,
- amount,
- round(
- amount * arrayElement([0.3, 0.4, 0.5], 1 + (toUnixTimestamp(timestamp) % 3))
- ) as commission,
- country,
- city,
- latitude,
- longitude
- FROM dub_sale_events_mv
- WHERE
- timestamp > now() - INTERVAL 12 HOUR
- AND country != 'Unknown'
- AND city != 'Unknown'
- AND city != 'Ashburn'
- ORDER BY timestamp DESC
- LIMIT 500
+%
+ SELECT
+ timestamp,
+ amount,
+ round(
+ amount * arrayElement([0.3, 0.4, 0.5], 1 + (toUnixTimestamp(timestamp) % 3))
+ ) as commission,
+ country,
+ city,
+ latitude,
+ longitude
+ FROM dub_sale_events_mv
+ WHERE
+ timestamp > now() - INTERVAL 12 HOUR
+ AND country != 'Unknown'
+ AND city != 'Unknown'
+ AND city != 'Ashburn'
+ ORDER BY timestamp DESC
+ LIMIT 500
diff --git a/packages/tinybird/pipes/dub_links_metadata_pipe.pipe b/packages/tinybird/pipes/dub_links_metadata_pipe.pipe
index 505c0f5fd4..e23d1a486a 100644
--- a/packages/tinybird/pipes/dub_links_metadata_pipe.pipe
+++ b/packages/tinybird/pipes/dub_links_metadata_pipe.pipe
@@ -19,6 +19,7 @@ SQL >
toLowCardinality(program_id) program_id,
partner_id,
partner_group_id,
+ partner_tag_ids,
folder_id,
tag_ids,
tenant_id,
diff --git a/packages/tinybird/pipes/get_api_log_by_id.pipe b/packages/tinybird/pipes/get_api_log_by_id.pipe
index 2cc86dce37..942133ae7e 100644
--- a/packages/tinybird/pipes/get_api_log_by_id.pipe
+++ b/packages/tinybird/pipes/get_api_log_by_id.pipe
@@ -1,6 +1,7 @@
NODE endpoint
SQL >
- %
+
+%
SELECT
id,
timestamp,
@@ -21,3 +22,5 @@ SQL >
id = {{ String(id) }}
AND workspace_id = {{ String(workspaceId) }}
LIMIT 1
+
+
diff --git a/packages/tinybird/pipes/get_api_logs.pipe b/packages/tinybird/pipes/get_api_logs.pipe
index 635777bd76..2990cbd270 100644
--- a/packages/tinybird/pipes/get_api_logs.pipe
+++ b/packages/tinybird/pipes/get_api_logs.pipe
@@ -1,6 +1,7 @@
NODE endpoint
SQL >
- %
+
+%
SELECT
id,
timestamp,
@@ -32,3 +33,5 @@ SQL >
ORDER BY timestamp DESC
LIMIT {{ Int32(limit, 100) }}
OFFSET {{ Int32(offset, 0) }}
+
+
diff --git a/packages/tinybird/pipes/get_api_logs_count.pipe b/packages/tinybird/pipes/get_api_logs_count.pipe
index 168af380e9..35f624e637 100644
--- a/packages/tinybird/pipes/get_api_logs_count.pipe
+++ b/packages/tinybird/pipes/get_api_logs_count.pipe
@@ -1,6 +1,7 @@
NODE count
SQL >
- %
+
+%
SELECT
count() as count
FROM dub_api_logs
@@ -17,9 +18,12 @@ SQL >
{% if defined(requestId) %} AND id = {{ String(requestId) }} {% end %}
{% if defined(requestType) %} AND request_type = {{ String(requestType) }} {% end %}
+
+
NODE count_by_route_pattern
SQL >
- %
+
+%
SELECT
route_pattern as routePattern,
count() as count
@@ -41,9 +45,12 @@ SQL >
ORDER BY count DESC
LIMIT 100
+
+
NODE count_by_status_code
SQL >
- %
+
+%
SELECT
status_code as statusCode,
count() as count
@@ -63,9 +70,12 @@ SQL >
GROUP BY status_code
ORDER BY count DESC
+
+
NODE count_by_method
SQL >
- %
+
+%
SELECT
method,
count() as count
@@ -85,9 +95,12 @@ SQL >
GROUP BY method
ORDER BY count DESC
+
+
NODE endpoint
SQL >
- %
+
+%
SELECT *
FROM
{% if defined(groupBy) and groupBy == 'routePattern' %} count_by_route_pattern
@@ -95,3 +108,5 @@ SQL >
{% elif defined(groupBy) and groupBy == 'method' %} count_by_method
{% else %} count
{% end %}
+
+
diff --git a/packages/tinybird/pipes/get_audit_logs.pipe b/packages/tinybird/pipes/get_audit_logs.pipe
index 426501187b..38a81f19fc 100644
--- a/packages/tinybird/pipes/get_audit_logs.pipe
+++ b/packages/tinybird/pipes/get_audit_logs.pipe
@@ -1,28 +1,28 @@
NODE endpoint
SQL >
- %
- SELECT
- id,
- timestamp,
- action,
- actor_id,
- actor_type,
- actor_name,
- targets,
- description,
- ip_address,
- user_agent,
- metadata
- FROM dub_audit_logs
- WHERE
- true
- {% if defined(start) and defined(end) %}
- AND timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }}
- {% end %}
- {% if defined(workspaceId) %} AND workspace_id = {{ String(workspaceId) }} {% end %}
- {% if defined(programId) %} AND program_id = {{ String(programId) }} {% end %}
- ORDER BY timestamp DESC
+%
+ SELECT
+ id,
+ timestamp,
+ action,
+ actor_id,
+ actor_type,
+ actor_name,
+ targets,
+ description,
+ ip_address,
+ user_agent,
+ metadata
+ FROM dub_audit_logs
+ WHERE
+ true
+ {% if defined(start) and defined(end) %}
+ AND timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}
+ AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }}
+ {% end %}
+ {% if defined(workspaceId) %} AND workspace_id = {{ String(workspaceId) }} {% end %}
+ {% if defined(programId) %} AND program_id = {{ String(programId) }} {% end %}
+ ORDER BY timestamp DESC
diff --git a/packages/tinybird/pipes/get_click_event.pipe b/packages/tinybird/pipes/get_click_event.pipe
index 66c6700c2b..613f92ec95 100644
--- a/packages/tinybird/pipes/get_click_event.pipe
+++ b/packages/tinybird/pipes/get_click_event.pipe
@@ -1,20 +1,20 @@
NODE endpoint
SQL >
- %
- SELECT *
- FROM dub_click_events_id
- WHERE
- click_id
- = {{
- String(
- clickId,
- 'Z4f1TFvkejrp9o0L',
- description="The unique ID for a given click event",
- required=True,
- )
- }}
- ORDER BY timestamp DESC
- LIMIT 1
+%
+ SELECT *
+ FROM dub_click_events_id
+ WHERE
+ click_id
+ = {{
+ String(
+ clickId,
+ 'Z4f1TFvkejrp9o0L',
+ description="The unique ID for a given click event",
+ required=True,
+ )
+ }}
+ ORDER BY timestamp DESC
+ LIMIT 1
diff --git a/packages/tinybird/pipes/get_framer_lead_events.pipe b/packages/tinybird/pipes/get_framer_lead_events.pipe
index c58575ab64..44215319da 100644
--- a/packages/tinybird/pipes/get_framer_lead_events.pipe
+++ b/packages/tinybird/pipes/get_framer_lead_events.pipe
@@ -1,11 +1,15 @@
+DESCRIPTION >
+ internal pipe for framer's lead event backfill
+
+
NODE endpoint
SQL >
- %
- SELECT *
- FROM dub_lead_events_mv
- WHERE
- link_id IN {{ Array(linkIds, 'String', ['link_1JWRSXGRTN95H1YCKTC5BM41B','link_1JWQHXN0Y1QBR7X07YQ6MHWTZ']) }}
- AND customer_id IN {{ Array(customerIds, 'String', ['cus_1JWTHSGTT67WY9NK98QSFJ3M4','cus_1JWTQS8S008Q3VTB8ZRG7AE3W']) }}
+%
+ SELECT *
+ FROM dub_lead_events_mv
+ WHERE
+ link_id IN {{ Array(linkIds, 'String', ['link_1JWRSXGRTN95H1YCKTC5BM41B','link_1JWQHXN0Y1QBR7X07YQ6MHWTZ']) }}
+ AND customer_id IN {{ Array(customerIds, 'String', ['cus_1JWTHSGTT67WY9NK98QSFJ3M4','cus_1JWTQS8S008Q3VTB8ZRG7AE3W']) }}
diff --git a/packages/tinybird/pipes/get_import_error_logs.pipe b/packages/tinybird/pipes/get_import_error_logs.pipe
index 1398892652..cd48657bb2 100644
--- a/packages/tinybird/pipes/get_import_error_logs.pipe
+++ b/packages/tinybird/pipes/get_import_error_logs.pipe
@@ -5,27 +5,27 @@ DESCRIPTION >
NODE endpoint
SQL >
- %
- SELECT *
- FROM dub_import_error_logs
- WHERE
- workspace_id
- = {{
- String(
- workspaceId,
- 'wh_fjs8YfXkgsFL7eF7LOBvbluDb',
- required=True,
- )
- }}
- AND import_id
- = {{
- String(
- importId,
- 'uC2DOqy',
- required=True,
- )
- }}
- ORDER BY timestamp DESC
- limit 5000
+%
+ SELECT *
+ FROM dub_import_error_logs
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'wh_fjs8YfXkgsFL7eF7LOBvbluDb',
+ required=True,
+ )
+ }}
+ AND import_id
+ = {{
+ String(
+ importId,
+ 'uC2DOqy',
+ required=True,
+ )
+ }}
+ ORDER BY timestamp DESC
+ limit 5000
diff --git a/packages/tinybird/pipes/get_lead_event.pipe b/packages/tinybird/pipes/get_lead_event.pipe
index 60e15fdabd..ffeec9b511 100644
--- a/packages/tinybird/pipes/get_lead_event.pipe
+++ b/packages/tinybird/pipes/get_lead_event.pipe
@@ -1,24 +1,20 @@
-DESCRIPTION >
- internal pipe for updating lead event
-
-
NODE endpoint
SQL >
- %
- SELECT *
- FROM dub_lead_events_mv
- WHERE
- customer_id
- = {{
- String(
- customerId,
- "cus_JzMqCLdaiVM1o1grw0yk84uC",
- description="The unique ID for a given customer.",
- required=True,
- )
- }}
- {% if defined(eventName) %} AND event_name = {{ eventName }} {% end %}
- ORDER BY timestamp DESC
+%
+SELECT *
+FROM dub_lead_events_mv
+WHERE
+ customer_id
+ = {{
+ String(
+ customerId,
+ "cus_JzMqCLdaiVM1o1grw0yk84uC",
+ description="The unique ID for a given customer.",
+ required=True,
+ )
+ }}
+ {% if defined(eventName) %} AND event_name = {{ eventName }} {% end %}
+ORDER BY timestamp DESC
diff --git a/packages/tinybird/pipes/get_lead_events.pipe b/packages/tinybird/pipes/get_lead_events.pipe
index 7e329df633..7445cf6dba 100644
--- a/packages/tinybird/pipes/get_lead_events.pipe
+++ b/packages/tinybird/pipes/get_lead_events.pipe
@@ -1,12 +1,12 @@
NODE endpoint
SQL >
- %
- SELECT *
- FROM dub_lead_events_mv
- WHERE
- true
- {% if defined(customerIds) %} AND customer_id IN {{ Array(customerIds, 'String') }} {% end %}
- ORDER BY timestamp DESC
+%
+ SELECT *
+ FROM dub_lead_events_mv
+ WHERE
+ true
+ {% if defined(customerIds) %} AND customer_id IN {{ Array(customerIds, 'String') }} {% end %}
+ ORDER BY timestamp DESC
diff --git a/packages/tinybird/pipes/get_postback_events.pipe b/packages/tinybird/pipes/get_postback_events.pipe
index 0e0449862b..6f6570fc83 100644
--- a/packages/tinybird/pipes/get_postback_events.pipe
+++ b/packages/tinybird/pipes/get_postback_events.pipe
@@ -5,7 +5,7 @@ DESCRIPTION >
NODE endpoint
SQL >
- %
+%
SELECT *
FROM dub_postback_events
WHERE
diff --git a/packages/tinybird/pipes/get_webhook_events.pipe b/packages/tinybird/pipes/get_webhook_events.pipe
index d6ad446634..bb7c3fe4d2 100644
--- a/packages/tinybird/pipes/get_webhook_events.pipe
+++ b/packages/tinybird/pipes/get_webhook_events.pipe
@@ -5,20 +5,20 @@ DESCRIPTION >
NODE endpoint
SQL >
- %
- SELECT *
- FROM dub_webhook_events
- WHERE
- webhook_id
- = {{
- String(
- webhookId,
- 'wh_fjs8YfXkgsFL7eF7LOBvbluDb',
- description="The ID of the webhook",
- required=True,
- )
- }}
- ORDER BY timestamp DESC
- limit 100
+%
+ SELECT *
+ FROM dub_webhook_events
+ WHERE
+ webhook_id
+ = {{
+ String(
+ webhookId,
+ 'wh_fjs8YfXkgsFL7eF7LOBvbluDb',
+ description="The ID of the webhook",
+ required=True,
+ )
+ }}
+ ORDER BY timestamp DESC
+ limit 100
diff --git a/packages/tinybird/pipes/v2_customer_events.pipe b/packages/tinybird/pipes/v2_customer_events.pipe
index 8589c91b57..89a455e192 100644
--- a/packages/tinybird/pipes/v2_customer_events.pipe
+++ b/packages/tinybird/pipes/v2_customer_events.pipe
@@ -7,158 +7,158 @@ TAGS "Dub Endpoints"
NODE lead_events
SQL >
- %
- SELECT
- timestamp,
- click_id,
- link_id,
- url,
- continent,
- country,
- city,
- region,
- latitude,
- longitude,
- device,
- browser,
- os,
- engine,
- ua,
- referer,
- referer_url,
- qr,
- ip,
- CONCAT(country, '-', region) as region_processed,
- splitByString('?', referer_url)[1] as referer_url_processed,
- 'lead' as event,
- event_id,
- event_name,
- metadata
- FROM dub_lead_events_mv
- WHERE
- customer_id
- = {{
- String(
- customerId,
- 'cus_1JRJNSVARH220RCNJ2K5SAX9Q',
- description="The unique ID for a given customer",
- required=True,
- )
- }}
- {% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}
- ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
- LIMIT {{ Int32(limit, 100) }}
+%
+ SELECT
+ timestamp,
+ click_id,
+ link_id,
+ url,
+ continent,
+ country,
+ city,
+ region,
+ latitude,
+ longitude,
+ device,
+ browser,
+ os,
+ engine,
+ ua,
+ referer,
+ referer_url,
+ qr,
+ ip,
+ CONCAT(country, '-', region) as region_processed,
+ splitByString('?', referer_url)[1] as referer_url_processed,
+ 'lead' as event,
+ event_id,
+ event_name,
+ metadata
+ FROM dub_lead_events_mv
+ WHERE
+ customer_id
+ = {{
+ String(
+ customerId,
+ 'cus_1JRJNSVARH220RCNJ2K5SAX9Q',
+ description="The unique ID for a given customer",
+ required=True,
+ )
+ }}
+ {% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}
+ ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
+ LIMIT {{ Int32(limit, 100) }}
NODE click_events
SQL >
- %
- SELECT
- timestamp,
- click_id,
- link_id,
- url,
- continent,
- country,
- city,
- region,
- latitude,
- longitude,
- device,
- browser,
- os,
- engine,
- ua,
- referer,
- referer_url,
- qr,
- ip,
- CONCAT(country, '-', region) as region_processed,
- splitByString('?', referer_url)[1] as referer_url_processed,
- 'click' as event
- FROM dub_click_events_id
- WHERE
- click_id IN (SELECT DISTINCT click_id FROM lead_events)
- {% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}
- LIMIT {{ Int32(limit, 100) }}
+%
+ SELECT
+ timestamp,
+ click_id,
+ link_id,
+ url,
+ continent,
+ country,
+ city,
+ region,
+ latitude,
+ longitude,
+ device,
+ browser,
+ os,
+ engine,
+ ua,
+ referer,
+ referer_url,
+ qr,
+ ip,
+ CONCAT(country, '-', region) as region_processed,
+ splitByString('?', referer_url)[1] as referer_url_processed,
+ 'click' as event
+ FROM dub_click_events_id
+ WHERE
+ click_id IN (SELECT DISTINCT click_id FROM lead_events)
+ {% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}
+ LIMIT {{ Int32(limit, 100) }}
NODE sale_events
SQL >
- %
- SELECT
- timestamp,
- click_id,
- link_id,
- url,
- continent,
- country,
- city,
- region,
- latitude,
- longitude,
- device,
- browser,
- os,
- engine,
- ua,
- referer,
- referer_url,
- qr,
- ip,
- CONCAT(country, '-', region) as region_processed,
- splitByString('?', referer_url)[1] as referer_url_processed,
- 'sale' as event,
- event_id,
- event_name,
- metadata,
- amount as saleAmount,
- invoice_id,
- payment_processor
- FROM dub_sale_events_mv
- WHERE
- customer_id
- = {{
- String(
- customerId,
- 'cus_1JRJNSVARH220RCNJ2K5SAX9Q',
- description="The unique ID for a given customer",
- required=True,
- )
- }}
- {% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}
- LIMIT {{ Int32(limit, 100) }}
+%
+ SELECT
+ timestamp,
+ click_id,
+ link_id,
+ url,
+ continent,
+ country,
+ city,
+ region,
+ latitude,
+ longitude,
+ device,
+ browser,
+ os,
+ engine,
+ ua,
+ referer,
+ referer_url,
+ qr,
+ ip,
+ CONCAT(country, '-', region) as region_processed,
+ splitByString('?', referer_url)[1] as referer_url_processed,
+ 'sale' as event,
+ event_id,
+ event_name,
+ metadata,
+ amount as saleAmount,
+ invoice_id,
+ payment_processor
+ FROM dub_sale_events_mv
+ WHERE
+ customer_id
+ = {{
+ String(
+ customerId,
+ 'cus_1JRJNSVARH220RCNJ2K5SAX9Q',
+ description="The unique ID for a given customer",
+ required=True,
+ )
+ }}
+ {% if defined(linkIds) %} AND link_id IN ({{ Array(linkIds, 'link_id') }}) {% end %}
+ LIMIT {{ Int32(limit, 100) }}
NODE endpoint
SQL >
- %
- SELECT *
- FROM
- (
- SELECT *, NULL AS saleAmount, NULL AS invoice_id, NULL AS payment_processor
- FROM lead_events
- UNION ALL
- SELECT
- *,
- NULL AS event_id,
- NULL AS event_name,
- NULL AS metadata,
- NULL AS saleAmount,
- NULL AS invoice_id,
- NULL AS payment_processor
- FROM click_events
- UNION ALL
- SELECT *
- FROM sale_events
- )
- ORDER BY
- timestamp DESC, CASE event WHEN 'click' THEN 1 WHEN 'lead' THEN 2 WHEN 'sale' THEN 3 END DESC
+%
+ SELECT *
+ FROM
+ (
+ SELECT *, NULL AS saleAmount, NULL AS invoice_id, NULL AS payment_processor
+ FROM lead_events
+ UNION ALL
+ SELECT
+ *,
+ NULL AS event_id,
+ NULL AS event_name,
+ NULL AS metadata,
+ NULL AS saleAmount,
+ NULL AS invoice_id,
+ NULL AS payment_processor
+ FROM click_events
+ UNION ALL
+ SELECT *
+ FROM sale_events
+ )
+ ORDER BY
+ timestamp DESC, CASE event WHEN 'click' THEN 1 WHEN 'lead' THEN 2 WHEN 'sale' THEN 3 END DESC
diff --git a/packages/tinybird/pipes/v2_top_programs.pipe b/packages/tinybird/pipes/v2_top_programs.pipe
index 88bedfe166..e51d9ef922 100644
--- a/packages/tinybird/pipes/v2_top_programs.pipe
+++ b/packages/tinybird/pipes/v2_top_programs.pipe
@@ -5,150 +5,153 @@ DESCRIPTION >
NODE program_links
SQL >
- %
- SELECT link_id, program_id
- FROM dub_links_metadata_latest FINAL
- WHERE deleted == 0 AND program_id != ''
+%
+ SELECT link_id, program_id
+ FROM dub_links_metadata_latest FINAL
+ WHERE deleted == 0 AND program_id != ''
NODE top_programs_clicks
SQL >
- %
- SELECT pl.program_id as programId, COUNT(*) AS clicks
- FROM dub_click_events_mv AS ce
- JOIN program_links AS pl ON ce.link_id = pl.link_id
- WHERE 1
- {% if defined(continent) %} AND ce.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND ce.country = {{ country }} {% end %}
- {% if defined(region) %} AND ce.region = {{ region }} {% end %}
- {% if defined(city) %} AND ce.city = {{ city }} {% end %}
- {% if defined(device) %} AND ce.device = {{ device }} {% end %}
- {% if defined(browser) %} AND ce.browser = {{ browser }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% end %}
- {% if defined(os) %} AND ce.os = {{ os }} {% end %}
- {% if defined(referer) %} AND ce.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', ce.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND ce.url LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND ce.url LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND ce.url LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND ce.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND ce.url LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND ce.url = {{ url }} {% end %}
- {% if defined(start) %} AND ce.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND ce.timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY pl.program_id
- ORDER BY clicks DESC
- LIMIT 5000
+%
+ SELECT pl.program_id as programId, COUNT(*) AS clicks
+ FROM dub_click_events_mv AS ce
+ JOIN program_links AS pl ON ce.link_id = pl.link_id
+ WHERE 1
+ {% if defined(continent) %} AND ce.continent = {{ continent }} {% end %}
+ {% if defined(country) %} AND ce.country = {{ country }} {% end %}
+ {% if defined(region) %} AND ce.region = {{ region }} {% end %}
+ {% if defined(city) %} AND ce.city = {{ city }} {% end %}
+ {% if defined(device) %} AND ce.device = {{ device }} {% end %}
+ {% if defined(browser) %} AND ce.browser = {{ browser }} {% end %}
+ {% if defined(trigger) %} AND trigger = {{ trigger }} {% end %}
+ {% if defined(os) %} AND ce.os = {{ os }} {% end %}
+ {% if defined(referer) %} AND ce.referer = {{ referer }} {% end %}
+ {% if defined(refererUrl) %}
+ AND splitByString('?', ce.referer_url)[1] = {{ refererUrl }}
+ {% end %}
+ {% if defined(utm_source) %}
+ AND ce.url LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
+ {% end %}
+ {% if defined(utm_medium) %}
+ AND ce.url LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
+ {% end %}
+ {% if defined(utm_campaign) %}
+ AND ce.url LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
+ {% end %}
+ {% if defined(utm_term) %}
+ AND ce.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
+ {% end %}
+ {% if defined(utm_content) %}
+ AND ce.url LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
+ {% end %}
+ {% if defined(url) %} AND ce.url = {{ url }} {% end %}
+ {% if defined(start) %} AND ce.timestamp >= {{ DateTime64(start) }} {% end %}
+ {% if defined(end) %} AND ce.timestamp <= {{ DateTime64(end) }} {% end %}
+ GROUP BY pl.program_id
+ ORDER BY clicks DESC
+ LIMIT 5000
NODE top_programs_leads
SQL >
- %
- SELECT pl.program_id as programId, COUNT(*) AS leads
- FROM dub_lead_events AS le
- JOIN program_links AS pl ON le.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND le.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND le.country = {{ country }} {% end %}
- {% if defined(region) %} AND le.region = {{ region }} {% end %}
- {% if defined(city) %} AND le.city = {{ city }} {% end %}
- {% if defined(device) %} AND le.device = {{ device }} {% end %}
- {% if defined(browser) %} AND le.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND le.os = {{ os }} {% end %}
- {% if defined(referer) %} AND le.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', le.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND le.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND le.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND le.url
- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND le.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND le.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND le.url = {{ url }} {% end %}
- {% if defined(start) %} AND le.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND le.timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY pl.program_id
- ORDER BY leads DESC
- LIMIT 5000
+%
+ SELECT pl.program_id as programId, COUNT(*) AS leads
+ FROM dub_lead_events AS le
+ JOIN program_links AS pl ON le.link_id = pl.link_id
+ WHERE
+ 1
+ {% if defined(continent) %} AND le.continent = {{ continent }} {% end %}
+ {% if defined(country) %} AND le.country = {{ country }} {% end %}
+ {% if defined(region) %} AND le.region = {{ region }} {% end %}
+ {% if defined(city) %} AND le.city = {{ city }} {% end %}
+ {% if defined(device) %} AND le.device = {{ device }} {% end %}
+ {% if defined(browser) %} AND le.browser = {{ browser }} {% end %}
+ {% if defined(os) %} AND le.os = {{ os }} {% end %}
+ {% if defined(referer) %} AND le.referer = {{ referer }} {% end %}
+ {% if defined(refererUrl) %}
+ AND splitByString('?', le.referer_url)[1] = {{ refererUrl }}
+ {% end %}
+ {% if defined(utm_source) %}
+ AND le.url
+ LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
+ {% end %}
+ {% if defined(utm_medium) %}
+ AND le.url
+ LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
+ {% end %}
+ {% if defined(utm_campaign) %}
+ AND le.url
+ LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
+ {% end %}
+ {% if defined(utm_term) %}
+ AND le.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
+ {% end %}
+ {% if defined(utm_content) %}
+ AND le.url
+ LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
+ {% end %}
+ {% if defined(url) %} AND le.url = {{ url }} {% end %}
+ {% if defined(start) %} AND le.timestamp >= {{ DateTime64(start) }} {% end %}
+ {% if defined(end) %} AND le.timestamp <= {{ DateTime64(end) }} {% end %}
+ GROUP BY pl.program_id
+ ORDER BY leads DESC
+ LIMIT 5000
NODE top_programs_sales
SQL >
- %
- SELECT pl.program_id as programId, COUNT(*) AS sales, sum(amount) as saleAmount
- FROM dub_sale_events_mv AS se
- JOIN program_links AS pl ON se.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND se.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND se.country = {{ country }} {% end %}
- {% if defined(region) %} AND se.region = {{ region }} {% end %}
- {% if defined(city) %} AND se.city = {{ city }} {% end %}
- {% if defined(device) %} AND se.device = {{ device }} {% end %}
- {% if defined(browser) %} AND se.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND se.os = {{ os }} {% end %}
- {% if defined(referer) %} AND se.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', se.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND se.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND se.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND se.url
- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND se.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND se.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND se.url = {{ url }} {% end %}
- {% if defined(start) %} AND se.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND se.timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY pl.program_id
- ORDER BY saleAmount DESC
- LIMIT 5000
+%
+SELECT
+ pl.program_id as programId,
+ COUNT(*) AS sales,
+ sum(amount) as saleAmount
+FROM dub_sale_events_mv AS se
+JOIN program_links AS pl ON se.link_id = pl.link_id
+WHERE
+ 1
+ {% if defined(continent) %} AND se.continent = {{ continent }} {% end %}
+ {% if defined(country) %} AND se.country = {{ country }} {% end %}
+ {% if defined(region) %} AND se.region = {{ region }} {% end %}
+ {% if defined(city) %} AND se.city = {{ city }} {% end %}
+ {% if defined(device) %} AND se.device = {{ device }} {% end %}
+ {% if defined(browser) %} AND se.browser = {{ browser }} {% end %}
+ {% if defined(os) %} AND se.os = {{ os }} {% end %}
+ {% if defined(referer) %} AND se.referer = {{ referer }} {% end %}
+ {% if defined(refererUrl) %}
+ AND splitByString('?', se.referer_url)[1] = {{ refererUrl }}
+ {% end %}
+ {% if defined(utm_source) %}
+ AND se.url
+ LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
+ {% end %}
+ {% if defined(utm_medium) %}
+ AND se.url
+ LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
+ {% end %}
+ {% if defined(utm_campaign) %}
+ AND se.url
+ LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
+ {% end %}
+ {% if defined(utm_term) %}
+ AND se.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
+ {% end %}
+ {% if defined(utm_content) %}
+ AND se.url
+ LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
+ {% end %}
+ {% if defined(url) %} AND se.url = {{ url }} {% end %}
+ {% if defined(start) %} AND se.timestamp >= {{ DateTime64(start) }} {% end %}
+ {% if defined(end) %} AND se.timestamp <= {{ DateTime64(end) }} {% end %}
+GROUP BY pl.program_id
+ORDER BY saleAmount DESC
+LIMIT 5000
@@ -166,13 +169,13 @@ SQL >
NODE endpoint
SQL >
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} top_programs_clicks
- {% elif eventType == 'leads' %} top_programs_leads
- {% elif eventType == 'composite' %} top_programs_composite
- {% else %} top_programs_sales
- {% end %}
+%
+ SELECT *
+ FROM
+ {% if eventType == 'clicks' %} top_programs_clicks
+ {% elif eventType == 'leads' %} top_programs_leads
+ {% elif eventType == 'composite' %} top_programs_composite
+ {% else %} top_programs_sales
+ {% end %}
diff --git a/packages/tinybird/pipes/v3_group_by_link_country.pipe b/packages/tinybird/pipes/v3_group_by_link_country.pipe
index 77db5a9549..842ce452b1 100644
--- a/packages/tinybird/pipes/v3_group_by_link_country.pipe
+++ b/packages/tinybird/pipes/v3_group_by_link_country.pipe
@@ -5,22 +5,22 @@ DESCRIPTION >
NODE endpoint
SQL >
- %
- SELECT
- link_id,
- country,
- COUNT(*) AS clicks
- FROM
- dub_click_events_mv
- WHERE
- link_id IN {{ Array(linkIds, 'String') }}
- AND timestamp >= {{ DateTime64(start) }}
- AND timestamp <= {{ DateTime64(end) }}
- GROUP BY
- link_id,
- country
- ORDER BY
- link_id ASC,
- clicks DESC
+%
+ SELECT
+ link_id,
+ country,
+ COUNT(*) AS clicks
+ FROM
+ dub_click_events_mv
+ WHERE
+ link_id IN {{ Array(linkIds, 'String') }}
+ AND timestamp >= {{ DateTime64(start) }}
+ AND timestamp <= {{ DateTime64(end) }}
+ GROUP BY
+ link_id,
+ country
+ ORDER BY
+ link_id ASC,
+ clicks DESC
diff --git a/packages/tinybird/pipes/v3_usage.pipe b/packages/tinybird/pipes/v3_usage.pipe
index 9ff55a557f..9f60a30d2a 100644
--- a/packages/tinybird/pipes/v3_usage.pipe
+++ b/packages/tinybird/pipes/v3_usage.pipe
@@ -1,144 +1,144 @@
NODE day_intervals
SQL >
- %
- WITH
- toStartOfDay(
- toDateTime64({{ DateTime64(start, '2025-09-03 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS start,
- toStartOfDay(
- toDateTime64({{ DateTime64(end, '2025-10-03 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS
- end
- SELECT
- arrayJoin(
- arrayMap(
- x -> toDateTime64(toStartOfDay(toDateTime64(x, 3), {{ String(timezone, 'UTC') }}), 3),
- range(toUInt32(start + 86400), toUInt32(end + 86400),
- 86400
- )
+%
+ WITH
+ toStartOfDay(
+ toDateTime64({{ DateTime64(start, '2025-09-03 00:00:00.000') }}, 3),
+ {{ String(timezone, 'UTC') }}
+ ) AS start,
+ toStartOfDay(
+ toDateTime64({{ DateTime64(end, '2025-10-03 00:00:00.000') }}, 3),
+ {{ String(timezone, 'UTC') }}
+ ) AS
+ end
+ SELECT
+ arrayJoin(
+ arrayMap(
+ x -> toDateTime64(toStartOfDay(toDateTime64(x, 3), {{ String(timezone, 'UTC') }}), 3),
+ range(toUInt32(start + 86400), toUInt32(end + 86400),
+ 86400
)
- ) as interval
+ )
+ ) as interval
NODE usage_events_data
SQL >
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- {% if defined(groupBy) %} {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %}, {% end %}
- uniq(*) AS events
- FROM
- (
- -- Click events
- SELECT e.timestamp{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} m.folder_id {% else %} e.domain {% end %}, {% end %}
- FROM dub_click_events_mv e
- {% if groupBy == 'folder_id' or defined(folderId) %} LEFT JOIN dub_links_metadata_latest m ON m.link_id = e.link_id {% end %}
- WHERE
- workspace_id
- = {{
- String(
- workspaceId,
- 'cl7pj5kq4006835rbjlt2ofka',
- description="The unique ID for the workspace",
- required=True,
- )
- }}
- AND timestamp >= {{ DateTime(start, '2025-09-03 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2025-10-03 00:00:00') }}
- {% if defined(folderId) %} AND folder_id = {{ folderId }} {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- UNION ALL
- -- Lead events
- SELECT e.timestamp{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} m.folder_id {% else %} e.domain {% end %}, {% end %}
- FROM dub_lead_events_mv e
- {% if groupBy == 'folder_id' or defined(folderId) %} LEFT JOIN dub_links_metadata_latest m ON m.link_id = e.link_id {% end %}
- WHERE
- workspace_id = {{ String(workspaceId, 'cl7pj5kq4006835rbjlt2ofka') }}
- AND timestamp >= {{ DateTime(start, '2025-09-03 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2025-10-03 00:00:00') }}
- {% if defined(folderId) %} AND folder_id = {{ folderId }} {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- UNION ALL
- -- Sale events
- SELECT e.timestamp{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} m.folder_id {% else %} e.domain {% end %}, {% end %}
- FROM dub_sale_events_mv e
- {% if groupBy == 'folder_id' or defined(folderId) %} LEFT JOIN dub_links_metadata_latest m ON m.link_id = e.link_id {% end %}
- WHERE
- workspace_id = {{ String(workspaceId, 'cl7pj5kq4006835rbjlt2ofka') }}
- AND timestamp >= {{ DateTime(start, '2025-09-03 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2025-10-03 00:00:00') }}
- {% if defined(folderId) %} AND folder_id = {{ folderId }} {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- )
- GROUP BY interval{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %} {% end %}
- ORDER BY interval
+%
+ SELECT
+ toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
+ {% if defined(groupBy) %} {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %}, {% end %}
+ uniq(*) AS events
+ FROM
+ (
+ -- Click events
+ SELECT e.timestamp{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} m.folder_id {% else %} e.domain {% end %}, {% end %}
+ FROM dub_click_events_mv e
+ {% if groupBy == 'folder_id' or defined(folderId) %} LEFT JOIN dub_links_metadata_latest m ON m.link_id = e.link_id {% end %}
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'cl7pj5kq4006835rbjlt2ofka',
+ description="The unique ID for the workspace",
+ required=True,
+ )
+ }}
+ AND timestamp >= {{ DateTime(start, '2025-09-03 00:00:00') }}
+ AND timestamp < {{ DateTime(end, '2025-10-03 00:00:00') }}
+ {% if defined(folderId) %} AND folder_id = {{ folderId }} {% end %}
+ {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
+ UNION ALL
+ -- Lead events
+ SELECT e.timestamp{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} m.folder_id {% else %} e.domain {% end %}, {% end %}
+ FROM dub_lead_events_mv e
+ {% if groupBy == 'folder_id' or defined(folderId) %} LEFT JOIN dub_links_metadata_latest m ON m.link_id = e.link_id {% end %}
+ WHERE
+ workspace_id = {{ String(workspaceId, 'cl7pj5kq4006835rbjlt2ofka') }}
+ AND timestamp >= {{ DateTime(start, '2025-09-03 00:00:00') }}
+ AND timestamp < {{ DateTime(end, '2025-10-03 00:00:00') }}
+ {% if defined(folderId) %} AND folder_id = {{ folderId }} {% end %}
+ {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
+ UNION ALL
+ -- Sale events
+ SELECT e.timestamp{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} m.folder_id {% else %} e.domain {% end %}, {% end %}
+ FROM dub_sale_events_mv e
+ {% if groupBy == 'folder_id' or defined(folderId) %} LEFT JOIN dub_links_metadata_latest m ON m.link_id = e.link_id {% end %}
+ WHERE
+ workspace_id = {{ String(workspaceId, 'cl7pj5kq4006835rbjlt2ofka') }}
+ AND timestamp >= {{ DateTime(start, '2025-09-03 00:00:00') }}
+ AND timestamp < {{ DateTime(end, '2025-10-03 00:00:00') }}
+ {% if defined(folderId) %} AND folder_id = {{ folderId }} {% end %}
+ {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
+ )
+ GROUP BY interval{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %} {% end %}
+ ORDER BY interval
NODE usage_events
SQL >
- %
- SELECT
- formatDateTime(interval, '%FT%T.000%z') as date,
- {% if defined(groupBy) %} {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %}, {% end %}
- events as value
- FROM day_intervals
- LEFT JOIN usage_events_data USING interval
+%
+ SELECT
+ formatDateTime(interval, '%FT%T.000%z') as date,
+ {% if defined(groupBy) %} {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %}, {% end %}
+ events as value
+ FROM day_intervals
+ LEFT JOIN usage_events_data USING interval
NODE usage_links_data
SQL >
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- {% if defined(groupBy) %} {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %}, {% end %}
- uniq(*) as links
- FROM dub_links_metadata_latest FINAL
- WHERE
- workspace_id
- = {{
- String(
- workspaceId,
- 'clrei1gld0002vs9mzn93p8ik',
- description="The ID of the workspace",
- required=True,
- )
- }}
- AND toDateTime64(timestamp, 3) >= {{ DateTime(start, '2025-09-03 00:00:00') }}
- AND toDateTime64(timestamp, 3) < {{ DateTime(end, '2025-10-03 00:00:00') }}
- {% if defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- GROUP BY interval{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %} {% end %}
- ORDER BY interval
+%
+ SELECT
+ toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
+ {% if defined(groupBy) %} {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %}, {% end %}
+ uniq(*) as links
+ FROM dub_links_metadata_latest FINAL
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'clrei1gld0002vs9mzn93p8ik',
+ description="The ID of the workspace",
+ required=True,
+ )
+ }}
+ AND toDateTime64(timestamp, 3) >= {{ DateTime(start, '2025-09-03 00:00:00') }}
+ AND toDateTime64(timestamp, 3) < {{ DateTime(end, '2025-10-03 00:00:00') }}
+ {% if defined(folderId) %} AND folder_id = {{ folderId }}
+ {% end %}
+ {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
+ GROUP BY interval{% if defined(groupBy) %}, {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %} {% end %}
+ ORDER BY interval
NODE usage_links
SQL >
- %
- SELECT
- formatDateTime(interval, '%FT%T.000%z') as date,
- {% if defined(groupBy) %} {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %}, {% end %}
- links as value
- FROM day_intervals
- LEFT JOIN usage_links_data USING interval
+%
+ SELECT
+ formatDateTime(interval, '%FT%T.000%z') as date,
+ {% if defined(groupBy) %} {% if groupBy == 'folder_id' %} folder_id {% else %} domain {% end %}, {% end %}
+ links as value
+ FROM day_intervals
+ LEFT JOIN usage_links_data USING interval
NODE endpoint
SQL >
- %
- SELECT * FROM {% if resource == 'events' %} usage_events {% else %} usage_links {% end %}
+%
+ SELECT * FROM {% if resource == 'events' %} usage_events {% else %} usage_links {% end %}