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.

Finalize Tinybird pipes/datasources (#3001)

Steven Teye659ea654cc6
diff --git a/packages/tinybird/datasources/dub_audit_logs.datasource b/packages/tinybird/datasources/dub_audit_logs.datasource
index 8d4e8135db..f483fd7523 100644
--- a/packages/tinybird/datasources/dub_audit_logs.datasource
+++ b/packages/tinybird/datasources/dub_audit_logs.datasource
@@ -1,4 +1,5 @@
-TOKEN dub_tinybird_token APPEND
+TOKEN "dub_tinybird_token" APPEND
+
SCHEMA >
`id` String `json:$.id`,
diff --git a/packages/tinybird/datasources/dub_click_events.datasource b/packages/tinybird/datasources/dub_click_events.datasource
index 766db57e82..025e77add7 100644
--- a/packages/tinybird/datasources/dub_click_events.datasource
+++ b/packages/tinybird/datasources/dub_click_events.datasource
@@ -1,4 +1,5 @@
-TOKEN dub_tinybird_token APPEND
+TOKEN "dub_tinybird_token" APPEND
+
SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp`,
@@ -31,7 +32,10 @@ SCHEMA >
`qr` UInt8 `json:$.qr`,
`continent` LowCardinality(String) `json:$.continent`,
`vercel_region` Nullable(String) `json:$.vercel_region`,
- `trigger` String `json:$.trigger`
+ `trigger` String `json:$.trigger`,
+ `workspace_id` Nullable(String) `json:$.workspace_id`,
+ `domain` Nullable(String) `json:$.domain`,
+ `key` Nullable(String) `json:$.key`
ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
diff --git a/packages/tinybird/datasources/dub_click_events_id.datasource b/packages/tinybird/datasources/dub_click_events_id.datasource
index 00d2d9e67d..b98e11b9b3 100644
--- a/packages/tinybird/datasources/dub_click_events_id.datasource
+++ b/packages/tinybird/datasources/dub_click_events_id.datasource
@@ -3,33 +3,37 @@
SCHEMA >
`timestamp` DateTime64(3),
`click_id` String,
+ `workspace_id` LowCardinality(String),
`link_id` String,
+ `domain` String,
+ `key` String,
`url` String,
`continent` LowCardinality(String),
`country` LowCardinality(String),
- `city` String,
- `region` String,
+ `city` LowCardinality(String),
+ `region` LowCardinality(String),
`latitude` String,
`longitude` String,
`device` LowCardinality(String),
+ `browser` LowCardinality(String),
+ `os` LowCardinality(String),
+ `trigger` String,
+ `ua` String,
+ `referer` String,
+ `referer_url` String,
+ `ip` String,
+ `identity_hash` String,
`device_model` LowCardinality(String),
`device_vendor` LowCardinality(String),
- `browser` LowCardinality(String),
`browser_version` String,
- `os` LowCardinality(String),
`os_version` String,
`engine` LowCardinality(String),
`engine_version` String,
`cpu_architecture` LowCardinality(String),
- `ua` String,
- `bot` UInt8,
- `referer` String,
- `referer_url` String,
- `identity_hash` Nullable(String),
- `ip` String,
`qr` UInt8,
- `trigger` String
+ `bot` UInt8
ENGINE "MergeTree"
-ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
+ENGINE_PARTITION_KEY "tuple()"
ENGINE_SORTING_KEY "click_id"
+ENGINE_SETTINGS "index_granularity = 256"
diff --git a/packages/tinybird/datasources/dub_click_events_mv.datasource b/packages/tinybird/datasources/dub_click_events_mv.datasource
index 00b4c5332f..d5887c8e1e 100644
--- a/packages/tinybird/datasources/dub_click_events_mv.datasource
+++ b/packages/tinybird/datasources/dub_click_events_mv.datasource
@@ -3,26 +3,36 @@
SCHEMA >
`timestamp` DateTime64(3),
`click_id` String,
+ `workspace_id` LowCardinality(String),
`link_id` String,
+ `domain` String,
+ `key` String,
`url` String,
`continent` LowCardinality(String),
`country` LowCardinality(String),
- `city` String,
- `region` String,
+ `city` LowCardinality(String),
+ `region` LowCardinality(String),
`latitude` String,
`longitude` String,
`device` LowCardinality(String),
`browser` LowCardinality(String),
`os` LowCardinality(String),
`trigger` String,
- `engine` LowCardinality(String),
`ua` String,
- `identity_hash` String,
`referer` String,
`referer_url` String,
`ip` String,
- `qr` UInt8
+ `identity_hash` String,
+ `device_model` LowCardinality(String),
+ `device_vendor` LowCardinality(String),
+ `browser_version` String,
+ `os_version` String,
+ `engine` LowCardinality(String),
+ `engine_version` String,
+ `cpu_architecture` LowCardinality(String),
+ `qr` UInt8,
+ `bot` UInt8
ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
-ENGINE_SORTING_KEY "link_id, timestamp"
+ENGINE_SORTING_KEY "workspace_id, link_id, timestamp"
diff --git a/packages/tinybird/datasources/dub_conversion_events_log.datasource b/packages/tinybird/datasources/dub_conversion_events_log.datasource
index c7137e111b..f540c998ec 100644
--- a/packages/tinybird/datasources/dub_conversion_events_log.datasource
+++ b/packages/tinybird/datasources/dub_conversion_events_log.datasource
@@ -1,4 +1,5 @@
-TOKEN dub_tinybird_token APPEND
+TOKEN "dub_tinybird_token" APPEND
+
SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
diff --git a/packages/tinybird/datasources/dub_import_error_logs.datasource b/packages/tinybird/datasources/dub_import_error_logs.datasource
index f2d06efc4c..a3fab635f2 100644
--- a/packages/tinybird/datasources/dub_import_error_logs.datasource
+++ b/packages/tinybird/datasources/dub_import_error_logs.datasource
@@ -1,4 +1,5 @@
-TOKEN dub_tinybird_token APPEND
+TOKEN "dub_tinybird_token" APPEND
+
SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
diff --git a/packages/tinybird/datasources/dub_lead_events.datasource b/packages/tinybird/datasources/dub_lead_events.datasource
index 67068fcf84..e034e058ea 100644
--- a/packages/tinybird/datasources/dub_lead_events.datasource
+++ b/packages/tinybird/datasources/dub_lead_events.datasource
@@ -1,4 +1,5 @@
-TOKEN dub_tinybird_token APPEND
+TOKEN "dub_tinybird_token" APPEND
+
SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
@@ -30,7 +31,11 @@ SCHEMA >
`referer_url` String `json:$.referer_url`,
`ip` String `json:$.ip`,
`qr` UInt8 `json:$.qr`,
- `metadata` String `json:$.metadata`
+ `metadata` String `json:$.metadata`,
+ `trigger` String `json:$.trigger`,
+ `domain` Nullable(String) `json:$.domain`,
+ `key` Nullable(String) `json:$.key`,
+ `workspace_id` Nullable(String) `json:$.workspace_id`
ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
diff --git a/packages/tinybird/datasources/dub_lead_events_mv.datasource b/packages/tinybird/datasources/dub_lead_events_mv.datasource
index f462ed814e..6b0b7b6f29 100644
--- a/packages/tinybird/datasources/dub_lead_events_mv.datasource
+++ b/packages/tinybird/datasources/dub_lead_events_mv.datasource
@@ -2,29 +2,40 @@
SCHEMA >
`timestamp` DateTime64(3),
- `event_id` String,
- `event_name` String,
`click_id` String,
+ `workspace_id` LowCardinality(String),
`link_id` String,
- `customer_id` String,
+ `domain` String,
+ `key` String,
`url` String,
+ `event_id` String,
+ `event_name` String,
+ `customer_id` String,
+ `metadata` String,
`continent` LowCardinality(String),
`country` LowCardinality(String),
- `city` String,
- `region` String,
+ `city` LowCardinality(String),
+ `region` LowCardinality(String),
`latitude` String,
`longitude` String,
`device` LowCardinality(String),
`browser` LowCardinality(String),
`os` LowCardinality(String),
- `engine` LowCardinality(String),
+ `trigger` String,
`ua` String,
`referer` String,
`referer_url` String,
- `qr` UInt8,
`ip` String,
- `metadata` String
+ `device_model` LowCardinality(String),
+ `device_vendor` LowCardinality(String),
+ `browser_version` String,
+ `os_version` String,
+ `engine` LowCardinality(String),
+ `engine_version` String,
+ `cpu_architecture` LowCardinality(String),
+ `qr` UInt8,
+ `bot` UInt8
ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
-ENGINE_SORTING_KEY "link_id, timestamp"
+ENGINE_SORTING_KEY "workspace_id, link_id, timestamp"
diff --git a/packages/tinybird/datasources/dub_links_metadata.datasource b/packages/tinybird/datasources/dub_links_metadata.datasource
index 3a46ee0b1b..f5165b9c4b 100644
--- a/packages/tinybird/datasources/dub_links_metadata.datasource
+++ b/packages/tinybird/datasources/dub_links_metadata.datasource
@@ -1,4 +1,5 @@
-TOKEN dub_tinybird_token APPEND
+TOKEN "dub_tinybird_token" APPEND
+
SCHEMA >
`timestamp` DateTime `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 eb33cbeb5e..c319272ed4 100644
--- a/packages/tinybird/datasources/dub_links_metadata_latest.datasource
+++ b/packages/tinybird/datasources/dub_links_metadata_latest.datasource
@@ -2,20 +2,20 @@
SCHEMA >
`timestamp` DateTime,
+ `workspace_id` LowCardinality(String),
`link_id` String,
`domain` String,
`key` String,
`url` String,
+ `program_id` LowCardinality(String),
+ `partner_id` String,
+ `folder_id` String,
`tag_ids` Array(String),
- `workspace_id` String,
- `created_at` DateTime64(3),
- `deleted` UInt8,
- `program_id` String,
`tenant_id` String,
- `partner_id` String,
- `folder_id` String
+ `created_at` DateTime64(3),
+ `deleted` UInt8
ENGINE "ReplacingMergeTree"
-ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
-ENGINE_SORTING_KEY "link_id"
+ENGINE_SORTING_KEY "workspace_id, link_id"
ENGINE_VER "timestamp"
+ENGINE_IS_DELETED "deleted"
diff --git a/packages/tinybird/datasources/dub_regular_links_metadata_latest.datasource b/packages/tinybird/datasources/dub_regular_links_metadata_latest.datasource
deleted file mode 100644
index 7a2e1afa7c..0000000000
--- a/packages/tinybird/datasources/dub_regular_links_metadata_latest.datasource
+++ /dev/null
@@ -1,20 +0,0 @@
-# Data Source created from Pipe 'dub_regular_links_metadata_pipe'
-
-SCHEMA >
- `timestamp` DateTime,
- `link_id` String,
- `domain` String,
- `key` String,
- `url` String,
- `tag_ids` Array(String),
- `workspace_id` String,
- `created_at` DateTime64(3),
- `deleted` UInt8,
- `program_id` String,
- `tenant_id` String,
- `partner_id` String,
- `folder_id` String
-
-ENGINE "ReplacingMergeTree"
-ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
-ENGINE_SORTING_KEY "link_id"
diff --git a/packages/tinybird/datasources/dub_sale_events.datasource b/packages/tinybird/datasources/dub_sale_events.datasource
index 52e0c6102b..5c6289abe0 100644
--- a/packages/tinybird/datasources/dub_sale_events.datasource
+++ b/packages/tinybird/datasources/dub_sale_events.datasource
@@ -1,4 +1,5 @@
-TOKEN dub_tinybird_token APPEND
+TOKEN "dub_tinybird_token" APPEND
+
SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
@@ -34,7 +35,11 @@ SCHEMA >
`referer_url` String `json:$.referer_url`,
`ip` String `json:$.ip`,
`qr` UInt8 `json:$.qr`,
- `metadata` String `json:$.metadata`
+ `metadata` String `json:$.metadata`,
+ `trigger` String `json:$.trigger`,
+ `domain` Nullable(String) `json:$.domain`,
+ `key` Nullable(String) `json:$.key`,
+ `workspace_id` Nullable(String) `json:$.workspace_id`
ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
diff --git a/packages/tinybird/datasources/dub_sale_events_id.datasource b/packages/tinybird/datasources/dub_sale_events_id.datasource
deleted file mode 100644
index d9d5a90feb..0000000000
--- a/packages/tinybird/datasources/dub_sale_events_id.datasource
+++ /dev/null
@@ -1,41 +0,0 @@
-# Data Source created from Pipe 'dub_sale_events_id_pipe'
-
-SCHEMA >
- `timestamp` DateTime64(3),
- `event_id` String,
- `event_name` String,
- `customer_id` String,
- `payment_processor` LowCardinality(String),
- `invoice_id` String,
- `amount` UInt32,
- `currency` LowCardinality(String),
- `click_id` String,
- `link_id` String,
- `url` String,
- `continent` LowCardinality(String),
- `country` LowCardinality(String),
- `city` String,
- `region` String,
- `latitude` String,
- `longitude` String,
- `device` LowCardinality(String),
- `device_model` LowCardinality(String),
- `device_vendor` LowCardinality(String),
- `browser` LowCardinality(String),
- `browser_version` String,
- `os` LowCardinality(String),
- `os_version` String,
- `engine` LowCardinality(String),
- `engine_version` String,
- `cpu_architecture` LowCardinality(String),
- `ua` String,
- `bot` UInt8,
- `referer` String,
- `referer_url` String,
- `ip` String,
- `qr` UInt8,
- `metadata` String
-
-ENGINE "MergeTree"
-ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
-ENGINE_SORTING_KEY "event_id"
diff --git a/packages/tinybird/datasources/dub_sale_events_mv.datasource b/packages/tinybird/datasources/dub_sale_events_mv.datasource
index 14ea754a06..cbb7bf2a46 100644
--- a/packages/tinybird/datasources/dub_sale_events_mv.datasource
+++ b/packages/tinybird/datasources/dub_sale_events_mv.datasource
@@ -2,32 +2,44 @@
SCHEMA >
`timestamp` DateTime64(3),
- `event_id` String,
- `event_name` String,
`click_id` String,
+ `workspace_id` LowCardinality(String),
`link_id` String,
+ `domain` String,
+ `key` String,
+ `url` String,
+ `event_id` String,
+ `event_name` String,
`customer_id` String,
`payment_processor` LowCardinality(String),
`invoice_id` String,
`amount` UInt32,
- `url` String,
+ `sale_type` String,
+ `metadata` String,
`continent` LowCardinality(String),
`country` LowCardinality(String),
- `city` String,
- `region` String,
+ `city` LowCardinality(String),
+ `region` LowCardinality(String),
`latitude` String,
`longitude` String,
`device` LowCardinality(String),
`browser` LowCardinality(String),
`os` LowCardinality(String),
- `engine` LowCardinality(String),
+ `trigger` String,
`ua` String,
`referer` String,
`referer_url` String,
- `qr` UInt8,
`ip` String,
- `metadata` String
+ `device_model` LowCardinality(String),
+ `device_vendor` LowCardinality(String),
+ `browser_version` String,
+ `os_version` String,
+ `engine` LowCardinality(String),
+ `engine_version` String,
+ `cpu_architecture` LowCardinality(String),
+ `qr` UInt8,
+ `bot` UInt8
ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)"
-ENGINE_SORTING_KEY "link_id, timestamp"
+ENGINE_SORTING_KEY "workspace_id, link_id, timestamp"
diff --git a/packages/tinybird/datasources/dub_webhook_events.datasource b/packages/tinybird/datasources/dub_webhook_events.datasource
index bd92d3c5e1..0bcae5ef40 100644
--- a/packages/tinybird/datasources/dub_webhook_events.datasource
+++ b/packages/tinybird/datasources/dub_webhook_events.datasource
@@ -1,4 +1,5 @@
-TOKEN dub_tinybird_token APPEND
+TOKEN "dub_tinybird_token" APPEND
+
SCHEMA >
`timestamp` DateTime64(3) `json:$.timestamp` DEFAULT now(),
diff --git a/packages/tinybird/endpoints/all_stats.pipe b/packages/tinybird/endpoints/all_stats.pipe
deleted file mode 100644
index 51c9a00869..0000000000
--- a/packages/tinybird/endpoints/all_stats.pipe
+++ /dev/null
@@ -1,13 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-TAGS "Dub Misc Endpoints"
-
-NODE endpoint
-SQL >
-
- SELECT
- (SELECT COUNT(timestamp) FROM dub_click_events_mv) AS clicks,
- (SELECT COUNT(timestamp) + 42036155 FROM dub_links_metadata_latest FINAL) AS links,
- (SELECT SUM(amount) FROM dub_sale_events_mv) AS sales
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/coordinates_all.pipe b/packages/tinybird/endpoints/coordinates_all.pipe
deleted file mode 100644
index d21d554b10..0000000000
--- a/packages/tinybird/endpoints/coordinates_all.pipe
+++ /dev/null
@@ -1,98 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-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
-
-
-
-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
-
-
-
-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
-
-
-
-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
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/coordinates_sales.pipe b/packages/tinybird/endpoints/coordinates_sales.pipe
deleted file mode 100644
index 93bfca795f..0000000000
--- a/packages/tinybird/endpoints/coordinates_sales.pipe
+++ /dev/null
@@ -1,28 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-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
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/get_audit_logs.pipe b/packages/tinybird/endpoints/get_audit_logs.pipe
deleted file mode 100644
index ed6f4a0512..0000000000
--- a/packages/tinybird/endpoints/get_audit_logs.pipe
+++ /dev/null
@@ -1,30 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-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
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/get_click_event.pipe b/packages/tinybird/endpoints/get_click_event.pipe
deleted file mode 100644
index 3d5c7fd189..0000000000
--- a/packages/tinybird/endpoints/get_click_event.pipe
+++ /dev/null
@@ -1,22 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-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
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/get_framer_lead_events.pipe b/packages/tinybird/endpoints/get_framer_lead_events.pipe
deleted file mode 100644
index c76dba6989..0000000000
--- a/packages/tinybird/endpoints/get_framer_lead_events.pipe
+++ /dev/null
@@ -1,13 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-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']) }}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/get_import_error_logs.pipe b/packages/tinybird/endpoints/get_import_error_logs.pipe
deleted file mode 100644
index 0eb2c32362..0000000000
--- a/packages/tinybird/endpoints/get_import_error_logs.pipe
+++ /dev/null
@@ -1,33 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Get import logs by ID
-
-
-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
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/get_lead_event.pipe b/packages/tinybird/endpoints/get_lead_event.pipe
deleted file mode 100644
index 82fda4a50f..0000000000
--- a/packages/tinybird/endpoints/get_lead_event.pipe
+++ /dev/null
@@ -1,22 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM dub_lead_events
- 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
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/get_lead_event_by_id.pipe b/packages/tinybird/endpoints/get_lead_event_by_id.pipe
deleted file mode 100644
index 8bcfb710ee..0000000000
--- a/packages/tinybird/endpoints/get_lead_event_by_id.pipe
+++ /dev/null
@@ -1,25 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- internal pipe for updating lead event
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM dub_lead_events
- WHERE
- event_id
- = {{
- String(
- eventId,
- "nLvob3FdmsYuI1BI",
- description="The unique event ID.",
- required=True,
- )
- }}
- ORDER BY timestamp DESC
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/get_lead_events.pipe b/packages/tinybird/endpoints/get_lead_events.pipe
deleted file mode 100644
index 2eece42e4a..0000000000
--- a/packages/tinybird/endpoints/get_lead_events.pipe
+++ /dev/null
@@ -1,14 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM dub_lead_events
- WHERE
- true
- {% if defined(customerIds) %} AND customer_id IN {{ Array(customerIds, 'String') }} {% end %}
- ORDER BY timestamp DESC
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/get_sale_event.pipe b/packages/tinybird/endpoints/get_sale_event.pipe
deleted file mode 100644
index ff3cbbf337..0000000000
--- a/packages/tinybird/endpoints/get_sale_event.pipe
+++ /dev/null
@@ -1,20 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM dub_sale_events_id
- WHERE
- event_id
- = {{
- String(
- eventId,
- "O9Q8fKbfY809HXBp",
- description="The unique event ID.",
- required=True,
- )
- }}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/get_webhook_events.pipe b/packages/tinybird/endpoints/get_webhook_events.pipe
deleted file mode 100644
index 776605bee8..0000000000
--- a/packages/tinybird/endpoints/get_webhook_events.pipe
+++ /dev/null
@@ -1,26 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Get webhook events
-
-
-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
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_browsers.pipe b/packages/tinybird/endpoints/v2_browsers.pipe
deleted file mode 100644
index 73f6b975df..0000000000
--- a/packages/tinybird/endpoints/v2_browsers.pipe
+++ /dev/null
@@ -1,318 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE browsers_clicks
-SQL >
-
- %
- SELECT browser, COUNT(browser) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND browser != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY browser
- ORDER BY clicks DESC
-
-
-
-NODE browsers_leads
-SQL >
-
- %
- SELECT browser, COUNT(browser) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND browser != 'Unknown'
- {% 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 %}
- GROUP BY browser
- ORDER BY leads DESC
-
-
-
-NODE browsers_sales
-SQL >
-
- %
- SELECT browser, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT browser, COUNT(*) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND browser != 'Unknown'
- {% 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 %}
- GROUP BY browser
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE browsers_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT browser, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND browser != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT browser, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT browser, COUNT(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY browser
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE browsers_composite
-SQL >
-
- %
- SELECT dce.browser AS browser, clicks, leads, sales, amount, saleAmount
- FROM (SELECT * FROM browsers_clicks) AS dce
- LEFT JOIN (SELECT * FROM browsers_leads) AS dle ON dce.browser = dle.browser
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} browsers_sales_with_type {% else %} browsers_sales {% end %}
- ) AS dse
- ON dce.browser = dse.browser
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} browsers_clicks
- {% elif eventType == 'leads' %} browsers_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} browsers_sales_with_type {% else %} browsers_sales {% end %}
- {% else %} browsers_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_cities.pipe b/packages/tinybird/endpoints/v2_cities.pipe
deleted file mode 100644
index d9edfb22e9..0000000000
--- a/packages/tinybird/endpoints/v2_cities.pipe
+++ /dev/null
@@ -1,418 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE cities_clicks
-SQL >
-
- %
- SELECT city, CONCAT(country, '-', region) as region, country, COUNT(city) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND city != 'Unknown'
- AND region NOT IN (
- 'Unknown',
- 'arn1',
- 'bom1',
- 'cdg1',
- 'cle1',
- 'cpt1',
- 'dub1',
- 'fra1',
- 'gru1',
- 'hkg1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'lhr1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1'
- )
- {% if defined(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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY city, region, country
- ORDER BY clicks DESC
- LIMIT 1000
-
-
-
-NODE cities_leads
-SQL >
-
- %
- SELECT city, CONCAT(country, '-', region) as region, country, COUNT(city) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND city != 'Unknown'
- AND region NOT IN (
- 'Unknown',
- 'arn1',
- 'bom1',
- 'cdg1',
- 'cle1',
- 'cpt1',
- 'dub1',
- 'fra1',
- 'gru1',
- 'hkg1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'lhr1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1'
- )
- {% if defined(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 %}
- GROUP BY city, region, country
- ORDER BY leads DESC
- LIMIT 1000
-
-
-
-NODE cities_sales
-SQL >
-
- %
- SELECT city, CONCAT(country, '-', region) as region, country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT city, region, country, COUNT(city) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND city != 'Unknown'
- AND region NOT IN (
- 'Unknown',
- 'arn1',
- 'bom1',
- 'cdg1',
- 'cle1',
- 'cpt1',
- 'dub1',
- 'fra1',
- 'gru1',
- 'hkg1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'lhr1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1'
- )
- {% if defined(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 %}
- GROUP BY city, region, country
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE cities_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT city, region, country, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND city != 'Unknown'
- AND region NOT IN (
- 'Unknown',
- 'arn1',
- 'bom1',
- 'cdg1',
- 'cle1',
- 'cpt1',
- 'dub1',
- 'fra1',
- 'gru1',
- 'hkg1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'lhr1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1'
- )
- {% if defined(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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT city, CONCAT(country, '-', region) as region, country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT city, region, country, COUNT(city) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY city, region, country
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE cities_composite
-SQL >
-
- %
- SELECT
- dce.city AS city,
- dce.region AS region,
- dce.country AS country,
- clicks,
- leads,
- sales,
- amount,
- saleAmount
- FROM (SELECT city, region, country, clicks FROM cities_clicks) AS dce
- LEFT JOIN (SELECT * FROM cities_leads) AS dle ON dce.city = dle.city AND dce.region = dle.region
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} cities_sales_with_type {% else %} cities_sales {% end %}
- ) AS dse
- ON dce.city = dse.city
- AND dce.region = dse.region
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} cities_clicks
- {% elif eventType == 'leads' %} cities_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} cities_sales_with_type {% else %} cities_sales {% end %}
- {% else %} cities_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_continents.pipe b/packages/tinybird/endpoints/v2_continents.pipe
deleted file mode 100644
index d64662a645..0000000000
--- a/packages/tinybird/endpoints/v2_continents.pipe
+++ /dev/null
@@ -1,321 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top continents
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE continents_clicks
-SQL >
-
- %
- SELECT continent, COUNT(continent) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND continent != ''
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY continent
- ORDER BY clicks DESC
-
-
-
-NODE continents_leads
-SQL >
-
- %
- SELECT continent, COUNT(continent) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND continent != ''
- {% 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 %}
- GROUP BY continent
- ORDER BY leads DESC
-
-
-
-NODE continents_sales
-SQL >
-
- %
- SELECT continent, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT continent, COUNT(continent) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND continent != ''
- {% 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 %}
- GROUP BY continent
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE continents_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT continent, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND continent != ''
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT continent, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT continent, COUNT(continent) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY continent
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE continents_composite
-SQL >
-
- %
- SELECT dce.continent AS continent, clicks, leads, sales, amount, saleAmount
- FROM (SELECT continent, clicks FROM continents_clicks) AS dce
- LEFT JOIN (SELECT * FROM continents_leads) AS dle ON dce.continent = dle.continent
- LEFT JOIN
- (
- SELECT *
- FROM
- {% if defined(saleType) %} continents_sales_with_type
- {% else %} continents_sales
- {% end %}
- ) AS dse
- ON dce.continent = dse.continent
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} continents_clicks
- {% elif eventType == 'leads' %} continents_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} continents_sales_with_type {% else %} continents_sales {% end %}
- {% else %} continents_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_count.pipe b/packages/tinybird/endpoints/v2_count.pipe
deleted file mode 100644
index 5a04867747..0000000000
--- a/packages/tinybird/endpoints/v2_count.pipe
+++ /dev/null
@@ -1,366 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE count_clicks
-SQL >
-
- %
- SELECT COUNT(*) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% end %}
- {% if defined(referer) %} AND referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %}
- {% if defined(utm_source) %}
- AND url LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND url LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND url
- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND url LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND url = {{ url }} {% end %}
- {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
-
-
-
-NODE count_leads
-SQL >
-
- %
- SELECT COUNT(*) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- {% if defined(filters) %}
- {% for item in JSON(filters, '[]') %}
- {% if item.get('operand', '').startswith('metadata.') %}
- {% set metadataKey = item.get('operand', '').split('.')[1] %}
- {% set operator = item.get('operator', 'equals') %}
- {% set value = item.get('value', '') %}
-
- {% if operator == 'equals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
- {% elif operator == 'notEquals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
- {% elif operator == 'greaterThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
- {% elif operator == 'lessThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
- {% elif operator == 'greaterThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
- {% elif operator == 'lessThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
- {% end %}
- {% end %}
- {% end %}
- {% end %}
-
-
-
-NODE count_sales
-SQL >
-
- %
- 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 not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- {% if defined(filters) %}
- {% for item in JSON(filters, '[]') %}
- {% if item.get('operand', '').startswith('metadata.') %}
- {% set metadataKey = item.get('operand', '').split('.')[1] %}
- {% set operator = item.get('operator', 'equals') %}
- {% set value = item.get('value', '') %}
-
- {% if operator == 'equals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
- {% elif operator == 'notEquals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
- {% elif operator == 'greaterThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
- {% elif operator == 'lessThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
- {% elif operator == 'greaterThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
- {% elif operator == 'lessThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
- {% end %}
- {% end %}
- {% end %}
- {% end %}
- ) AS subquery
-
-
-
-NODE count_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- {% if defined(filters) %}
- {% for item in JSON(filters, '[]') %}
- {% if item.get('operand', '').startswith('metadata.') %}
- {% set metadataKey = item.get('operand', '').split('.')[1] %}
- {% set operator = item.get('operator', 'equals') %}
- {% set value = item.get('value', '') %}
-
- {% if operator == 'equals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
- {% elif operator == 'notEquals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
- {% elif operator == 'greaterThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
- {% elif operator == 'lessThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
- {% elif operator == 'greaterThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
- {% elif operator == 'lessThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
- {% end %}
- {% end %}
- {% end %}
- {% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT sales, amount, amount AS saleAmount
- FROM
- (
- SELECT COUNT(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- ) AS subquery
-
-
-
-NODE count_composite
-SQL >
-
- %
- SELECT clicks, leads, sales, amount, saleAmount
- FROM
- count_clicks,
- count_leads,
- {% if defined(saleType) %} count_sales_with_type
- {% else %} count_sales
- {% end %}
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} count_clicks
- {% elif eventType == 'leads' %} count_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} count_sales_with_type {% else %} count_sales {% end %}
- {% else %} count_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_countries.pipe b/packages/tinybird/endpoints/v2_countries.pipe
deleted file mode 100644
index 85dd144aae..0000000000
--- a/packages/tinybird/endpoints/v2_countries.pipe
+++ /dev/null
@@ -1,310 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE countries_clicks
-SQL >
-
- %
- SELECT country, COUNT(country) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND country != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY country
- ORDER BY clicks DESC
-
-
-
-NODE countries_leads
-SQL >
-
- %
- SELECT country, COUNT(country) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND country != 'Unknown'
- {% 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 %}
- GROUP BY country
- ORDER BY leads DESC
-
-
-
-NODE countries_sales
-SQL >
-
- %
- SELECT country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT country, COUNT(country) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND country != 'Unknown'
- {% 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 %}
- GROUP BY country
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE countries_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT country, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND country != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT country, COUNT(country) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY country
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE countries_composite
-SQL >
-
- %
- SELECT dce.country AS country, clicks, leads, sales, amount, saleAmount
- FROM (SELECT country, clicks FROM countries_clicks) AS dce
- LEFT JOIN (SELECT * FROM countries_leads) AS dle ON dce.country = dle.country
- LEFT JOIN
- (
- SELECT *
- FROM
- {% if defined(saleType) %} countries_sales_with_type
- {% else %} countries_sales
- {% end %}
- ) AS dse
- ON dce.country = dse.country
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} countries_clicks
- {% elif eventType == 'leads' %} countries_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} countries_sales_with_type {% else %} countries_sales {% end %}
- {% else %} countries_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_customer_events.pipe b/packages/tinybird/endpoints/v2_customer_events.pipe
deleted file mode 100644
index 2c46cfdbbc..0000000000
--- a/packages/tinybird/endpoints/v2_customer_events.pipe
+++ /dev/null
@@ -1,166 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Customer events
-
-
-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) }}
-
-
-
-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) }}
-
-
-
-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) }}
-
-
-
-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
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_devices.pipe b/packages/tinybird/endpoints/v2_devices.pipe
deleted file mode 100644
index 057700526d..0000000000
--- a/packages/tinybird/endpoints/v2_devices.pipe
+++ /dev/null
@@ -1,318 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE devices_clicks
-SQL >
-
- %
- SELECT device, COUNT(device) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND device != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY device
- ORDER BY clicks DESC
-
-
-
-NODE devices_leads
-SQL >
-
- %
- SELECT device, COUNT(device) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND device != 'Unknown'
- {% 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 %}
- GROUP BY device
- ORDER BY leads DESC
-
-
-
-NODE devices_sales
-SQL >
-
- %
- SELECT device, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT device, COUNT(device) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND device != 'Unknown'
- {% 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 %}
- GROUP BY device
- ORDER BY amount DESC
- ) subquery
-
-
-
-NODE devices_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT device, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND device != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT device, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT device, COUNT(device) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY device
- ORDER BY amount DESC
- ) subquery
-
-
-
-NODE devices_composite
-SQL >
-
- %
- SELECT dce.device AS device, clicks, leads, sales, amount
- FROM (SELECT device, clicks FROM devices_clicks) AS dce
- LEFT JOIN (SELECT * FROM devices_leads) AS dle ON dce.device = dle.device
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} devices_sales_with_type {% else %} devices_sales {% end %}
- ) AS dse
- ON dce.device = dse.device
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} devices_clicks
- {% elif eventType == 'leads' %} devices_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} devices_sales_with_type {% else %} devices_sales {% end %}
- {% else %} devices_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_events.pipe b/packages/tinybird/endpoints/v2_events.pipe
deleted file mode 100644
index d1067a1751..0000000000
--- a/packages/tinybird/endpoints/v2_events.pipe
+++ /dev/null
@@ -1,367 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id, domain, key
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE click_events
-SQL >
-
- %
- SELECT
- *,
- splitByString('?', referer_url)[1] as referer_url_processed,
- CONCAT(country, '-', region) as region_processed,
- 'click' as event
- FROM {% if defined(customerId) %} dub_click_events_id {% else %} dub_click_events_mv {% end %}
- WHERE
- timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }}
- {% if defined(customerId) %}
- AND click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% 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 %}
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
- LIMIT {{ Int32(limit, 100) }}
- {% if defined(offset) %} OFFSET {{ Int32(offset, 0) }} {% end %}
-
-
-
-NODE lead_events
-SQL >
-
- %
- SELECT
- *,
- splitByString('?', referer_url)[1] as referer_url_processed,
- CONCAT(country, '-', region) as region_processed,
- 'lead' as event
- FROM dub_lead_events_mv
- WHERE
- timestamp >= {{ DateTime(start, '2024-01-01 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2025-12-31 00:00:00') }}
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% 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(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(filters) %}
- {% for item in JSON(filters, '[]') %}
- {% if item.get('operand', '').startswith('metadata.') %}
- {% set metadataKey = item.get('operand', '').split('.')[1] %}
- {% set operator = item.get('operator', 'equals') %}
- {% set value = item.get('value', '') %}
-
- {% if operator == 'equals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
- {% elif operator == 'notEquals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
- {% elif operator == 'greaterThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
- {% elif operator == 'lessThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
- {% elif operator == 'greaterThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
- {% elif operator == 'lessThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
- {% end %}
- {% end %}
- {% end %}
- {% end %}
-
- ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
- LIMIT {{ Int32(limit, 100) }}
- {% if defined(offset) %} OFFSET {{ Int32(offset, 0) }} {% end %}
-
-
-
-NODE sale_events
-SQL >
-
- %
- SELECT
- *,
- amount as saleAmount,
- CONCAT(country, '-', region) as region_processed,
- splitByString('?', referer_url)[1] as referer_url_processed,
- 'sale' as event
- FROM dub_sale_events_mv
- WHERE
- timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2025-12-31 00:00:00') }}
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% 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(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(filters) %}
- {% for item in JSON(filters, '[]') %}
- {% if item.get('operand', '').startswith('metadata.') %}
- {% set metadataKey = item.get('operand', '').split('.')[1] %}
- {% set operator = item.get('operator', 'equals') %}
- {% set value = item.get('value', '') %}
-
- {% if operator == 'equals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
- {% elif operator == 'notEquals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
- {% elif operator == 'greaterThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
- {% elif operator == 'lessThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
- {% elif operator == 'greaterThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
- {% elif operator == 'lessThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
- {% end %}
- {% end %}
- {% end %}
- {% end %}
-
- ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
- LIMIT {{ Int32(limit, 100) }}
- {% if defined(offset) %} OFFSET {{ Int32(offset, 0) }} {% end %}
-
-
-
-NODE sale_events_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT
- *,
- amount as saleAmount,
- CONCAT(country, '-', region) as region_processed,
- splitByString('?', referer_url)[1] as referer_url_processed,
- 'sale' as event
- FROM dub_sale_events_mv
- WHERE
- timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }}
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% 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(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(filters) %}
- {% for item in JSON(filters, '[]') %}
- {% if item.get('operand', '').startswith('metadata.') %}
- {% set metadataKey = item.get('operand', '').split('.')[1] %}
- {% set operator = item.get('operator', 'equals') %}
- {% set value = item.get('value', '') %}
-
- {% if operator == 'equals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
- {% elif operator == 'notEquals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
- {% elif operator == 'greaterThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
- {% elif operator == 'lessThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
- {% elif operator == 'greaterThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
- {% elif operator == 'lessThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
- {% end %}
- {% end %}
- {% end %}
- {% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT *, CASE WHEN timestamp = first_sale_ts THEN 'new' ELSE 'recurring' END as sale_type
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp = first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
- LIMIT {{ Int32(limit, 100) }}
- {% if defined(offset) %} OFFSET {{ Int32(offset, 0) }} {% end %}
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'leads' %} lead_events
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} sale_events_with_type {% else %} sale_events {% end %}
- {% else %} click_events
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_os.pipe b/packages/tinybird/endpoints/v2_os.pipe
deleted file mode 100644
index 925fd59d11..0000000000
--- a/packages/tinybird/endpoints/v2_os.pipe
+++ /dev/null
@@ -1,317 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE os_clicks
-SQL >
-
- %
- SELECT os, COUNT(os) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND os != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY os
- ORDER BY clicks DESC
-
-
-
-NODE os_leads
-SQL >
-
- %
- SELECT os, COUNT(os) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND os != 'Unknown'
- {% 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 %}
- GROUP BY os
- ORDER BY leads DESC
-
-
-
-NODE os_sales
-SQL >
-
- %
- SELECT os, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT os, COUNT(os) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND os != 'Unknown'
- {% 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 %}
- GROUP BY os
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE os_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT os, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND os != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT os, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT os, COUNT(os) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY os
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE os_composite
-SQL >
-
- %
- SELECT dce.os AS os, clicks, leads, sales, amount, saleAmount
- FROM (SELECT os, clicks FROM os_clicks) AS dce
- LEFT JOIN (SELECT * FROM os_leads) AS dle ON dce.os = dle.os
- LEFT JOIN
- (
- SELECT * FROM {% if defined(saleType) %} os_sales_with_type {% else %} os_sales {% end %}
- ) AS dse
- ON dce.os = dse.os
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} os_clicks
- {% elif eventType == 'leads' %} os_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} os_sales_with_type {% else %} os_sales {% end %}
- {% else %} os_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_referer_urls.pipe b/packages/tinybird/endpoints/v2_referer_urls.pipe
deleted file mode 100644
index d71613063c..0000000000
--- a/packages/tinybird/endpoints/v2_referer_urls.pipe
+++ /dev/null
@@ -1,326 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE referer_urls_clicks
-SQL >
-
- %
- SELECT splitByString('?', referer_url)[1] as refererUrl, COUNT(*) as clicks
- FROM
- dub_click_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND referer != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY splitByString('?', referer_url)[1]
- ORDER BY clicks DESC
- LIMIT 5000
-
-
-
-NODE referer_urls_leads
-SQL >
-
- %
- SELECT splitByString('?', referer_url)[1] as refererUrl, COUNT(referer_url) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND referer != 'Unknown'
- {% 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 %}
- GROUP BY splitByString('?', referer_url)[1]
- ORDER BY leads DESC
- LIMIT 1000
-
-
-
-NODE referer_urls_sales
-SQL >
-
- %
- SELECT refererUrl, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT
- splitByString('?', referer_url)[1] as refererUrl,
- COUNT(referer_url) as sales,
- sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND referer != 'Unknown'
- {% 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 %}
- GROUP BY splitByString('?', referer_url)[1]
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE referer_urls_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT
- splitByString('?', referer_url)[1] as refererUrl,
- customer_id,
- link_id,
- timestamp,
- amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND referer != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT refererUrl, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT refererUrl, COUNT(refererUrl) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY refererUrl
- ORDER BY amount DESC
- LIMIT 5000
- ) as subquery
-
-
-
-NODE referer_urls_composite
-SQL >
-
- %
- SELECT dce.refererUrl as refererUrl, clicks, leads, sales, amount, saleAmount
- FROM (SELECT refererUrl, clicks FROM referer_urls_clicks) AS dce
- LEFT JOIN (SELECT * FROM referer_urls_leads) AS dle ON dce.refererUrl = dle.refererUrl
- LEFT JOIN
- (
- SELECT *
- FROM
- {% if defined(saleType) %} referer_urls_sales_with_type
- {% else %} referer_urls_sales
- {% end %}
- ) AS dse
- ON dce.refererUrl = dse.refererUrl
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} referer_urls_clicks
- {% elif eventType == 'leads' %} referer_urls_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} referer_urls_sales_with_type
- {% else %} referer_urls_sales
- {% end %}
- {% else %} referer_urls_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_referers.pipe b/packages/tinybird/endpoints/v2_referers.pipe
deleted file mode 100644
index ae0e059756..0000000000
--- a/packages/tinybird/endpoints/v2_referers.pipe
+++ /dev/null
@@ -1,307 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE referers_clicks
-SQL >
-
- %
- SELECT referer, COUNT(referer) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY referer
- ORDER BY clicks DESC
- LIMIT 1000
-
-
-
-NODE referers_leads
-SQL >
-
- %
- SELECT referer, COUNT(referer) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- GROUP BY referer
- ORDER BY leads DESC
- LIMIT 1000
-
-
-
-NODE referers_sales
-SQL >
-
- %
- SELECT referer, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT referer, COUNT(referer) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- GROUP BY referer
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE referers_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT referer, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT referer, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT referer, COUNT(referer) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY referer
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE referers_composite
-SQL >
-
- %
- SELECT dce.referer AS referer, clicks, leads, sales, amount, saleAmount
- FROM (SELECT referer, clicks FROM referers_clicks) AS dce
- LEFT JOIN (SELECT * FROM referers_leads) AS dle ON dce.referer = dle.referer
- LEFT JOIN (SELECT * FROM
- {% if defined(saleType) %} referers_sales_with_type
- {% else %} referers_sales
- {% end %}) AS dse ON dce.referer = dse.referer
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} referers_clicks
- {% elif eventType == 'leads' %} referers_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} referers_sales_with_type {% else %} referers_sales {% end %}
- {% else %} referers_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_regions.pipe b/packages/tinybird/endpoints/v2_regions.pipe
deleted file mode 100644
index 1ceaf9cfb3..0000000000
--- a/packages/tinybird/endpoints/v2_regions.pipe
+++ /dev/null
@@ -1,423 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE regions_clicks
-SQL >
-
- %
- SELECT CONCAT(country, '-', region) as region, country, clicks,
- FROM
- (
- SELECT region, country, COUNT(region) as clicks
- FROM
- dub_click_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND 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(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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY region, country
- ORDER BY clicks DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE regions_leads
-SQL >
-
- %
- SELECT CONCAT(country, '-', region) as region, country, leads,
- FROM
- (
- SELECT region, country, COUNT(region) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND 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(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 %}
- GROUP BY region, country
- ORDER BY leads DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE regions_sales
-SQL >
-
- %
- SELECT CONCAT(country, '-', region) as region, country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT region, country, COUNT(region) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND 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(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 %}
- GROUP BY region, country
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE regions_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT region, country, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND 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(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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT CONCAT(country, '-', region) as region, country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT region, country, COUNT(region) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY region, country
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE regions_composite
-SQL >
-
- %
- SELECT dce.region AS region, dce.country AS country, clicks, leads, sales, amount, saleAmount
- FROM (SELECT region, country, clicks FROM regions_clicks) AS dce
- LEFT JOIN (SELECT * FROM regions_leads) AS dle ON dce.region = dle.region
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} regions_sales_with_type {% else %} regions_sales {% end %}
- ) AS dse
- ON dce.region = dse.region
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} regions_clicks
- {% elif eventType == 'leads' %} regions_leads
- {% elif eventType == 'sales' %} {% if defined(saleType) %} regions_sales_with_type
- {% else %} regions_sales
- {% end %}
- {% else %} regions_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_timeseries.pipe b/packages/tinybird/endpoints/v2_timeseries.pipe
deleted file mode 100644
index 2856a2b750..0000000000
--- a/packages/tinybird/endpoints/v2_timeseries.pipe
+++ /dev/null
@@ -1,461 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Timeseries data
-
-
-TAGS "Dub Endpoints"
-
-NODE month_intervals
-SQL >
-
- %
- WITH
- toStartOfMonth(
- toDateTime64({{ DateTime64(start, '2024-02-24 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS start,
- toStartOfMonth(
- toDateTime64({{ DateTime64(end, '2024-05-23 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS
- end,
- dateDiff('month', start, end) + 1 AS months_diff
- SELECT
- arrayJoin(
- arrayMap(
- x -> toDateTime64(start + toIntervalMonth(x), 3, {{ String(timezone, 'UTC') }}),
- range(0, months_diff)
- )
- ) as interval
-
-
-
-NODE day_intervals
-SQL >
-
- %
- WITH
- toStartOfDay(
- toDateTime64({{ DateTime64(start, '2024-02-24 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS start,
- toStartOfDay(
- toDateTime64({{ DateTime64(end, '2024-05-23 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), toUInt32(end + 86400),
- 86400
- )
- )
- ) as interval
-
-
-
-NODE hour_intervals
-SQL >
-
- %
- WITH
- toStartOfHour(
- toDateTime64({{ DateTime64(start, '2024-05-22 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS start,
- toStartOfHour(
- toDateTime64({{ DateTime64(end, '2024-05-23 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS
- end
- SELECT
- arrayJoin(
- arrayMap(x -> toDateTime64(x, 3), range(toUInt32(start), toUInt32(end + 3600), 3600)
- )
- ) as interval
-
-
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE timeseries_clicks_data
-SQL >
-
- %
- SELECT
- {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
- {% elif granularity == "month" %}
- toDateTime64(
- toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
- 3,
- {{ String(timezone, 'UTC') }}
- )
- {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
- {% end %} AS interval,
- uniq(click_id) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE timeseries_clicks
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as start, clicks
- FROM
- {% if granularity == "minute" %} minute_intervals
- {% elif granularity == "hour" %} hour_intervals
- {% elif granularity == "month" %} month_intervals
- {% else %} day_intervals
- {% end %}
- LEFT JOIN timeseries_clicks_data USING interval
-
-
-
-NODE timeseries_leads_data
-SQL >
-
- %
- SELECT
- {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
- {% elif granularity == "month" %}
- toDateTime64(
- toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
- 3,
- {{ String(timezone, 'UTC') }}
- )
- {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
- {% end %} AS interval,
- uniq(*) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE timeseries_leads
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as start, leads
- FROM
- {% if granularity == "minute" %} minute_intervals
- {% elif granularity == "hour" %} hour_intervals
- {% elif granularity == "month" %} month_intervals
- {% else %} day_intervals
- {% end %}
- LEFT JOIN timeseries_leads_data USING interval
-
-
-
-NODE timeseries_sales_data
-DESCRIPTION >
- undefined
-
-SQL >
-
- %
- SELECT
- {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
- {% elif granularity == "month" %}
- toDateTime64(
- toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
- 3,
- {{ String(timezone, 'UTC') }}
- )
- {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
- {% end %} AS interval,
- uniq(*) as sales,
- sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE timeseries_sales_data_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT
- {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
- {% elif granularity == "month" %}
- toDateTime64(
- toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
- 3,
- {{ String(timezone, 'UTC') }}
- )
- {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
- {% end %} AS interval,
- customer_id,
- link_id,
- timestamp,
- amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT interval, uniq(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE timeseries_sales
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as start, sales, amount, amount as saleAmount
- FROM
- {% if granularity == "minute" %} minute_intervals
- {% elif granularity == "hour" %} hour_intervals
- {% elif granularity == "month" %} month_intervals
- {% else %} day_intervals
- {% end %}
- LEFT JOIN
- {% if defined(saleType) %} timeseries_sales_data_with_type
- {% else %} timeseries_sales_data
- {% end %} USING interval
-
-
-
-NODE timeseries_composite
-SQL >
-
- SELECT dce.start AS start, clicks, leads, sales, amount, saleAmount
- FROM (SELECT start, clicks FROM timeseries_clicks) AS dce
- LEFT JOIN (SELECT * FROM timeseries_leads) AS dle ON dce.start = dle.start
- LEFT JOIN (SELECT * FROM timeseries_sales) AS dse ON dce.start = dse.start
-
-
-
-NODE timeseries_billing
-SQL >
-
- SELECT
- dce.start AS start,
- clicks,
- leads,
- sales,
- amount,
- saleAmount,
- (clicks + leads + sales) AS totalEvents
- FROM (SELECT start, clicks FROM timeseries_clicks) AS dce
- LEFT JOIN (SELECT * FROM timeseries_leads) AS dle ON dce.start = dle.start
- LEFT JOIN (SELECT * FROM timeseries_sales) AS dse ON dce.start = dse.start
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} timeseries_clicks
- {% elif eventType == 'leads' %} timeseries_leads
- {% elif eventType == 'sales' %} timeseries_sales
- {% elif eventType == 'billing' %} timeseries_billing
- {% else %} timeseries_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_top_links.pipe b/packages/tinybird/endpoints/v2_top_links.pipe
deleted file mode 100644
index 0676a35696..0000000000
--- a/packages/tinybird/endpoints/v2_top_links.pipe
+++ /dev/null
@@ -1,315 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top links endpoint (most updated version with linkIds filter support)
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE top_links_clicks
-SQL >
-
- %
- SELECT link_id as link, COUNT(*) AS clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY link_id
- ORDER BY clicks DESC
- LIMIT 1000
-
-
-
-NODE top_links_leads
-SQL >
-
- %
- SELECT link_id as link, COUNT(*) AS leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY link_id
- ORDER BY leads DESC
- LIMIT 5000
-
-
-
-NODE top_links_sales
-SQL >
-
- %
- SELECT link, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT link_id as link, COUNT(*) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY link_id
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE top_links_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT link_id, customer_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT link, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT link_id as link, COUNT(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY link_id
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE top_links_composite
-SQL >
-
- %
- SELECT dce.link AS link, clicks, leads, sales, amount, saleAmount
- FROM (SELECT link, clicks FROM top_links_clicks) AS dce
- LEFT JOIN (SELECT * FROM top_links_leads) AS dle ON dce.link = dle.link
- LEFT JOIN
- (
- SELECT *
- FROM
- {% if defined(saleType) %} top_links_sales_with_type
- {% else %} top_links_sales
- {% end %}
- ) AS dse
- ON dce.link = dse.link
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} top_links_clicks
- {% elif eventType == 'leads' %} top_links_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} top_links_sales_with_type {% else %} top_links_sales {% end %}
- {% else %} top_links_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_top_partners.pipe b/packages/tinybird/endpoints/v2_top_partners.pipe
deleted file mode 100644
index 89a13811b7..0000000000
--- a/packages/tinybird/endpoints/v2_top_partners.pipe
+++ /dev/null
@@ -1,263 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-NODE partner_links
-SQL >
-
- %
- SELECT link_id, partner_id
- FROM dub_regular_links_metadata_latest FINAL
- WHERE
- deleted == 0 AND partner_id != ''
- {% 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 %}
-
-
-
-NODE top_partners_clicks
-SQL >
-
- %
- SELECT pl.partner_id as partnerId, COUNT(*) AS clicks
- FROM dub_click_events_mv AS ce
- JOIN partner_links AS pl ON ce.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND ce.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND ce.country = {{ country }} {% end %}
- {% if defined(region) %} AND ce.region = {{ region }} {% end %}
- {% if defined(city) %} AND ce.city = {{ city }} {% end %}
- {% if defined(device) %} AND ce.device = {{ device }} {% end %}
- {% if defined(browser) %} AND ce.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND ce.os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% end %}
- {% if defined(referer) %} AND ce.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', ce.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND ce.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND ce.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND ce.url
- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND ce.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND ce.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND ce.url = {{ url }} {% end %}
- {% if defined(start) %} AND ce.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND ce.timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY pl.partner_id
- ORDER BY clicks DESC
- LIMIT 5000
-
-
-
-NODE top_partners_leads
-SQL >
-
- %
- SELECT pl.partner_id as partnerId, COUNT(*) AS leads
- FROM dub_lead_events AS le
- JOIN partner_links AS pl ON le.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND le.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND le.country = {{ country }} {% end %}
- {% if defined(region) %} AND le.region = {{ region }} {% end %}
- {% if defined(city) %} AND le.city = {{ city }} {% end %}
- {% if defined(device) %} AND le.device = {{ device }} {% end %}
- {% if defined(browser) %} AND le.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND le.os = {{ os }} {% end %}
- {% if defined(referer) %} AND le.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', le.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND le.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND le.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND le.url
- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND le.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND le.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND le.url = {{ url }} {% end %}
- {% if defined(start) %} AND le.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND le.timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY pl.partner_id
- ORDER BY leads DESC
- LIMIT 5000
-
-
-
-NODE top_partners_sales
-SQL >
-
- %
- SELECT pl.partner_id as partnerId, COUNT(*) AS sales, sum(amount) as saleAmount
- FROM dub_sale_events AS se
- JOIN partner_links AS pl ON se.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND se.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND se.country = {{ country }} {% end %}
- {% if defined(region) %} AND se.region = {{ region }} {% end %}
- {% if defined(city) %} AND se.city = {{ city }} {% end %}
- {% if defined(device) %} AND se.device = {{ device }} {% end %}
- {% if defined(browser) %} AND se.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND se.os = {{ os }} {% end %}
- {% if defined(referer) %} AND se.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', se.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND se.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND se.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND se.url
- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND se.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND se.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND se.url = {{ url }} {% end %}
- {% if defined(start) %} AND se.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND se.timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY pl.partner_id
- ORDER BY saleAmount DESC, sales DESC, partnerId ASC
- LIMIT 5000
-
-
-
-NODE top_partners_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT se.customer_id, se.link_id, se.timestamp, se.amount, pl.partner_id
- FROM dub_sale_events AS se
- JOIN partner_links AS pl ON se.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND se.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND se.country = {{ country }} {% end %}
- {% if defined(region) %} AND se.region = {{ region }} {% end %}
- {% if defined(city) %} AND se.city = {{ city }} {% end %}
- {% if defined(device) %} AND se.device = {{ device }} {% end %}
- {% if defined(browser) %} AND se.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND se.os = {{ os }} {% end %}
- {% if defined(referer) %} AND se.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', se.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND se.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND se.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND se.url LIKE concat(
- '%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%'
- )
- {% end %}
- {% if defined(utm_term) %}
- AND se.url
- LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND se.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND se.url = {{ url }} {% end %}
- {% if defined(start) %} AND se.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND se.timestamp <= {{ DateTime64(end) }} {% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT pl.partner_id as partnerId, COUNT(*) AS sales, sum(amount) as saleAmount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- JOIN partner_links AS pl ON sales.link_id = pl.link_id
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY pl.partner_id
- ORDER BY saleAmount DESC, sales DESC, partnerId ASC
- LIMIT 5000
-
-
-
-NODE top_partners_composite
-SQL >
-
- %
- SELECT c.partnerId as partnerId, c.clicks as clicks, l.leads as leads, s.sales as sales, s.saleAmount as saleAmount
- FROM top_partners_clicks AS c
- LEFT JOIN top_partners_leads AS l ON c.partnerId = l.partnerId
- LEFT JOIN
- {% if defined(saleType) %} top_partners_sales_with_type
- {% else %} top_partners_sales
- {% end %} AS s ON c.partnerId = s.partnerId
- ORDER BY saleAmount DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} top_partners_clicks
- {% elif eventType == 'leads' %} top_partners_leads
- {% elif eventType == 'composite' %} top_partners_composite
- {% else %} {% if defined(saleType) %} top_partners_sales_with_type
- {% else %} top_partners_sales
- {% end %}
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_top_programs.pipe b/packages/tinybird/endpoints/v2_top_programs.pipe
deleted file mode 100644
index 19b9d644ca..0000000000
--- a/packages/tinybird/endpoints/v2_top_programs.pipe
+++ /dev/null
@@ -1,180 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Internal pipe for getting top programs on Dub
-
-
-NODE program_links
-SQL >
-
- %
- SELECT link_id, program_id
- FROM dub_regular_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
-
-
-
-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
-
-
-
-NODE top_programs_sales
-SQL >
-
- %
- SELECT pl.program_id as programId, COUNT(*) AS sales, sum(amount) as saleAmount
- FROM dub_sale_events 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
-
-
-
-NODE top_programs_composite
-SQL >
-
- SELECT c.programId as programId, clicks, leads, sales, saleAmount
- FROM top_programs_clicks AS c
- LEFT JOIN top_programs_leads AS l ON c.programId = l.programId
- LEFT JOIN top_programs_sales AS s ON c.programId = s.programId
- ORDER BY saleAmount DESC
-
-
-
-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 %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_top_tags.pipe b/packages/tinybird/endpoints/v2_top_tags.pipe
deleted file mode 100644
index 594a580d03..0000000000
--- a/packages/tinybird/endpoints/v2_top_tags.pipe
+++ /dev/null
@@ -1,289 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-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(trigger) %} AND trigger = {{ trigger }} {% 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(trigger) %} AND trigger = {{ trigger }} {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 amount 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(trigger) %} AND trigger = {{ trigger }} {% 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
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_top_urls.pipe b/packages/tinybird/endpoints/v2_top_urls.pipe
deleted file mode 100644
index b2833c9a72..0000000000
--- a/packages/tinybird/endpoints/v2_top_urls.pipe
+++ /dev/null
@@ -1,303 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE top_urls_clicks
-SQL >
-
- %
- SELECT url, 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
- url != ''
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY url
- ORDER BY clicks DESC
- LIMIT 5000
-
-
-
-NODE top_urls_leads
-SQL >
-
- %
- SELECT url, COUNT(*) AS leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY url
- ORDER BY leads DESC
- LIMIT 1000
-
-
-
-NODE top_urls_sales
-SQL >
-
- %
- SELECT url, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT url, COUNT(*) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY url
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE top_urls_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT url, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT url, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT url, COUNT(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY url
- ORDER BY amount DESC
- LIMIT 5000
- ) as subquery
-
-
-
-NODE top_urls_composite
-SQL >
-
- %
- SELECT dce.url AS url, clicks, leads, sales, amount, saleAmount
- FROM (SELECT url, clicks FROM top_urls_clicks) AS dce
- LEFT JOIN (SELECT * FROM top_urls_leads) AS dle ON dce.url = dle.url
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} top_urls_sales_with_type {% else %} top_urls_sales {% end %}
- ) AS dse
- ON dce.url = dse.url
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} top_urls_clicks
- {% elif eventType == 'leads' %} top_urls_leads
- {% elif eventType == 'sales' %} {% if defined(saleType) %} top_urls_sales_with_type
- {% else %} top_urls_sales
- {% end %}
- {% else %} top_urls_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_triggers.pipe b/packages/tinybird/endpoints/v2_triggers.pipe
deleted file mode 100644
index 342db1f510..0000000000
--- a/packages/tinybird/endpoints/v2_triggers.pipe
+++ /dev/null
@@ -1,325 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE trigger_clicks
-SQL >
-
- %
- SELECT trigger, COUNT(trigger) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY trigger
- ORDER BY clicks DESC
-
-
-
-NODE trigger_leads
-SQL >
-
- %
- SELECT CASE WHEN qr = 0 THEN 'link' WHEN qr = 1 THEN 'qr' END as trigger, COUNT(qr) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- GROUP BY qr
- ORDER BY leads DESC
-
-
-
-NODE trigger_sales
-SQL >
-
- %
- SELECT trigger, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT
- CASE WHEN qr = 0 THEN 'link' WHEN qr = 1 THEN 'qr' END as trigger,
- COUNT(qr) as sales,
- sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- GROUP BY qr
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE trigger_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT qr, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT trigger, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT
- CASE WHEN qr = 0 THEN 'link' WHEN qr = 1 THEN 'qr' END as trigger,
- COUNT(qr) as sales,
- sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY qr
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE trigger_composite
-SQL >
-
- %
- SELECT dce.trigger AS trigger, clicks, leads, sales, amount, saleAmount
- FROM (SELECT * FROM trigger_clicks) AS dce
- LEFT JOIN (SELECT * FROM trigger_leads) AS dle ON dce.trigger = dle.trigger
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} trigger_sales_with_type {% else %} trigger_sales {% end %}
- ) AS dse
- ON dce.trigger = dse.trigger
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} trigger_clicks
- {% elif eventType == 'leads' %} trigger_leads
- {% elif eventType == 'sales' %} {% if defined(saleType) %} trigger_sales_with_type
- {% else %} trigger_sales
- {% end %}
- {% else %} trigger_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_usage.pipe b/packages/tinybird/endpoints/v2_usage.pipe
deleted file mode 100644
index 8dfb2b2182..0000000000
--- a/packages/tinybird/endpoints/v2_usage.pipe
+++ /dev/null
@@ -1,176 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-DESCRIPTION >
- Timeseries data
-
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- from dub_regular_links_metadata_latest FINAL
- WHERE
- workspace_id
- = {{
- String(
- workspaceId,
- 'ws_clrei1gld0002vs9mzn93p8ik',
- description="The ID of the workspace",
- required=True,
- )
- }}
-
-
-
-NODE day_intervals
-SQL >
-
- %
- WITH
- toStartOfDay(
- toDateTime64({{ DateTime64(start, '2024-09-03 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS start,
- toStartOfDay(
- toDateTime64({{ DateTime64(end, '2024-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
-
-
-
-NODE usage_clicks_data
-SQL >
-
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- uniq(*) as clicks
- FROM
- dub_click_events_mv
- PREWHERE link_id in (SELECT link_id from workspace_links)
- WHERE
- timestamp >= {{ DateTime(start, '2024-09-03 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-10-03 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE usage_leads_data
-SQL >
-
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- uniq(*) as leads
- FROM
- dub_lead_events_mv
- PREWHERE link_id in (SELECT link_id from workspace_links)
- WHERE
- timestamp >= {{ DateTime(start, '2024-09-03 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-10-03 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE usage_events
-SQL >
-
- SELECT
- formatDateTime(di.interval, '%FT%T.000%z') as date, clicks, leads, (clicks + leads) as value
- FROM day_intervals as di
- LEFT JOIN (SELECT * FROM usage_clicks_data) AS uc ON di.interval = uc.interval
- LEFT JOIN (SELECT * FROM usage_leads_data) AS ul ON di.interval = ul.interval
-
-
-
-NODE usage_links_data
-DESCRIPTION >
- undefined
-
-SQL >
-
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- uniq(*) as links
- FROM dub_links_metadata_latest FINAL
- WHERE
- workspace_id
- = {{
- String(
- workspaceId,
- 'ws_clrei1gld0002vs9mzn93p8ik',
- description="The ID of the workspace",
- required=True,
- )
- }}
- AND created_at >= {{ DateTime(start, '2024-09-03 00:00:00') }}
- AND created_at < {{ DateTime(end, '2024-10-03 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE usage_links
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as date, links as value
- FROM day_intervals
- LEFT JOIN usage_links_data USING interval
-
-
-
-NODE usage_revenue_data
-SQL >
-
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- sum(amount) as revenue
- FROM
- dub_sale_events_mv
- PREWHERE link_id in (SELECT link_id from workspace_links)
- WHERE
- timestamp >= {{ DateTime(start, '2024-09-03 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-10-03 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE usage_revenue
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as date, revenue as value
- FROM day_intervals
- LEFT JOIN usage_revenue_data USING interval
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if resource == 'events' %} usage_events
- {% elif resource == 'revenue' %} usage_revenue
- {% else %} usage_links
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/endpoints/v2_utms.pipe b/packages/tinybird/endpoints/v2_utms.pipe
deleted file mode 100644
index 73708c6ad2..0000000000
--- a/packages/tinybird/endpoints/v2_utms.pipe
+++ /dev/null
@@ -1,368 +0,0 @@
-TOKEN dub_tinybird_token READ
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE utms_clicks
-SQL >
-
- %
- WITH
- decodeURLFormComponent(
- extractURLParameter(
- url,
- {{
- String(
- groupByUtmTag,
- 'utm_source',
- description="The UTM tag to retrieve data for",
- required=True,
- )
- }}
- )
- ) as utm
- SELECT utm, count(*) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND url != ''
- {% 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 decodeURLFormComponent(extractURLParameter(url, 'utm_source'))
- = {{ String(utm_source) }}
- {% end %}
- {% if defined(utm_medium) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_medium'))
- = {{ String(utm_medium) }}
- {% end %}
- {% if defined(utm_campaign) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_campaign'))
- = {{ String(utm_campaign) }}
- {% end %}
- {% if defined(utm_term) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_term')) = {{ String(utm_term) }}
- {% end %}
- {% if defined(utm_content) %}
- AND decodeURLFormComponent(extractURLParameter(url, '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 utm
- HAVING utm != ''
- ORDER BY clicks DESC
-
-
-
-NODE utms_leads
-SQL >
-
- %
- WITH
- decodeURLFormComponent(
- extractURLParameter(
- url,
- {{
- String(
- groupByUtmTag,
- 'utm_source',
- description="The UTM tag to retrieve data for",
- required=True,
- )
- }}
- )
- ) as utm
- SELECT utm, count(*) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 decodeURLFormComponent(extractURLParameter(url, 'utm_source'))
- = {{ String(utm_source) }}
- {% end %}
- {% if defined(utm_medium) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_medium'))
- = {{ String(utm_medium) }}
- {% end %}
- {% if defined(utm_campaign) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_campaign'))
- = {{ String(utm_campaign) }}
- {% end %}
- {% if defined(utm_term) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_term')) = {{ String(utm_term) }}
- {% end %}
- {% if defined(utm_content) %}
- AND decodeURLFormComponent(extractURLParameter(url, '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 utm
- HAVING utm != ''
- ORDER BY leads DESC
-
-
-
-NODE utms_sales
-SQL >
-
- %
- WITH
- decodeURLFormComponent(
- extractURLParameter(
- url,
- {{
- String(
- groupByUtmTag,
- 'utm_source',
- description="The UTM tag to retrieve data for",
- required=True,
- )
- }}
- )
- ) as utm
- SELECT utm, count(*) as sales, sum(amount) as saleAmount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 decodeURLFormComponent(extractURLParameter(url, 'utm_source'))
- = {{ String(utm_source) }}
- {% end %}
- {% if defined(utm_medium) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_medium'))
- = {{ String(utm_medium) }}
- {% end %}
- {% if defined(utm_campaign) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_campaign'))
- = {{ String(utm_campaign) }}
- {% end %}
- {% if defined(utm_term) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_term')) = {{ String(utm_term) }}
- {% end %}
- {% if defined(utm_content) %}
- AND decodeURLFormComponent(extractURLParameter(url, '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 utm
- HAVING utm != ''
- ORDER BY saleAmount DESC
-
-
-
-NODE utms_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT
- decodeURLFormComponent(
- extractURLParameter(
- url,
- {{
- String(
- groupByUtmTag,
- 'utm_source',
- description="The UTM tag to retrieve data for",
- required=True,
- )
- }}
- )
- ) as utm,
- customer_id,
- link_id,
- timestamp,
- amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 decodeURLFormComponent(extractURLParameter(url, 'utm_source'))
- = {{ String(utm_source) }}
- {% end %}
- {% if defined(utm_medium) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_medium'))
- = {{ String(utm_medium) }}
- {% end %}
- {% if defined(utm_campaign) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_campaign'))
- = {{ String(utm_campaign) }}
- {% end %}
- {% if defined(utm_term) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_term'))
- = {{ String(utm_term) }}
- {% end %}
- {% if defined(utm_content) %}
- AND decodeURLFormComponent(extractURLParameter(url, '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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT utm, count(*) as sales, sum(amount) as saleAmount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY utm
- HAVING utm != ''
- ORDER BY saleAmount DESC
-
-
-
-NODE utms_composite
-SQL >
-
- %
- SELECT dce.utm AS utm, dce.clicks as clicks, leads, sales, saleAmount
- FROM (SELECT utm, clicks FROM utms_clicks) AS dce
- LEFT JOIN (SELECT * FROM utms_leads) AS dle ON dce.utm = dle.utm
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} utms_sales_with_type {% else %} utms_sales {% end %}
- ) AS dse
- ON dce.utm = dse.utm
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} utms_clicks
- {% elif eventType == 'leads' %} utms_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} utms_sales_with_type {% else %} utms_sales {% end %}
- {% else %} utms_composite
- {% end %}
-
-TYPE endpoint
\ No newline at end of file
diff --git a/packages/tinybird/materializations/dub_click_events_id_pipe.pipe b/packages/tinybird/materializations/dub_click_events_id_pipe.pipe
deleted file mode 100644
index e59e06ab0d..0000000000
--- a/packages/tinybird/materializations/dub_click_events_id_pipe.pipe
+++ /dev/null
@@ -1,42 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT
- timestamp,
- click_id,
- link_id,
- url,
- continent,
- country,
- city,
- region,
- latitude,
- longitude,
- device,
- device_model,
- device_vendor,
- browser,
- browser_version,
- os,
- os_version,
- engine,
- engine_version,
- cpu_architecture,
- ua,
- bot,
- referer,
- referer_url,
- identity_hash,
- ip,
- qr,
- CASE
- WHEN trigger = '' THEN CASE WHEN qr = true THEN 'qr' ELSE 'link' END ELSE trigger
- END as trigger
- FROM dub_click_events
-
-TYPE materialized
-DATASOURCE dub_click_events_id
-
-
diff --git a/packages/tinybird/materializations/dub_click_events_pipe.pipe b/packages/tinybird/materializations/dub_click_events_pipe.pipe
deleted file mode 100644
index ccd4e4e972..0000000000
--- a/packages/tinybird/materializations/dub_click_events_pipe.pipe
+++ /dev/null
@@ -1,40 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT
- timestamp,
- click_id,
- link_id,
- url,
- continent,
- country,
- city,
- region,
- latitude,
- longitude,
- device,
- browser,
- os,
- CASE
- WHEN trigger = '' THEN
- CASE
- WHEN qr = true THEN 'qr'
- ELSE 'link'
- END
- ELSE trigger
- END as trigger,
- engine,
- ua,
- coalesce(identity_hash, '') as identity_hash,
- referer,
- referer_url,
- ip,
- qr
- FROM dub_click_events
-
-TYPE materialized
-DATASOURCE dub_click_events_mv
-
-
diff --git a/packages/tinybird/materializations/dub_lead_events_pipe.pipe b/packages/tinybird/materializations/dub_lead_events_pipe.pipe
deleted file mode 100644
index b40cfdbc6f..0000000000
--- a/packages/tinybird/materializations/dub_lead_events_pipe.pipe
+++ /dev/null
@@ -1,35 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT
- timestamp,
- event_id,
- event_name,
- click_id,
- link_id,
- customer_id,
- url,
- continent,
- country,
- city,
- region,
- latitude,
- longitude,
- device,
- browser,
- os,
- engine,
- ua,
- referer,
- referer_url,
- qr,
- ip,
- metadata
- FROM dub_lead_events
-
-TYPE materialized
-DATASOURCE dub_lead_events_mv
-
-
diff --git a/packages/tinybird/materializations/dub_links_metadata_pipe.pipe b/packages/tinybird/materializations/dub_links_metadata_pipe.pipe
deleted file mode 100644
index 96cea42280..0000000000
--- a/packages/tinybird/materializations/dub_links_metadata_pipe.pipe
+++ /dev/null
@@ -1,11 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT * FROM dub_links_metadata
-
-TYPE materialized
-DATASOURCE dub_links_metadata_latest
-
-
diff --git a/packages/tinybird/materializations/dub_regular_links_metadata_pipe.pipe b/packages/tinybird/materializations/dub_regular_links_metadata_pipe.pipe
deleted file mode 100644
index c034ca2046..0000000000
--- a/packages/tinybird/materializations/dub_regular_links_metadata_pipe.pipe
+++ /dev/null
@@ -1,19 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT *
- FROM dub_links_metadata
- WHERE
- workspace_id not in [
- 'cm05wnnpo000711ztj05wwdbu', -- buffer
- 'ws_1JYEZKSFX7RMB5M9XP4G0CCAT', -- jobber
- 'clawqph22020408jng5s9b2tp', -- cal
- 'ws_1JQ7175XGRN2ZYE2QAPVA4A26' -- homeserve
- ]
-
-TYPE materialized
-DATASOURCE dub_regular_links_metadata_latest
-
-
diff --git a/packages/tinybird/materializations/dub_sale_events_id_pipe.pipe b/packages/tinybird/materializations/dub_sale_events_id_pipe.pipe
deleted file mode 100644
index f143560596..0000000000
--- a/packages/tinybird/materializations/dub_sale_events_id_pipe.pipe
+++ /dev/null
@@ -1,11 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT * FROM dub_sale_events
-
-TYPE materialized
-DATASOURCE dub_sale_events_id
-
-
diff --git a/packages/tinybird/materializations/dub_sale_events_pipe.pipe b/packages/tinybird/materializations/dub_sale_events_pipe.pipe
deleted file mode 100644
index 0526f5a090..0000000000
--- a/packages/tinybird/materializations/dub_sale_events_pipe.pipe
+++ /dev/null
@@ -1,38 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT
- timestamp,
- event_id,
- event_name,
- click_id,
- link_id,
- customer_id,
- payment_processor,
- invoice_id,
- amount,
- url,
- continent,
- country,
- city,
- region,
- latitude,
- longitude,
- device,
- browser,
- os,
- engine,
- ua,
- referer,
- referer_url,
- qr,
- ip,
- metadata
- FROM dub_sale_events
-
-TYPE materialized
-DATASOURCE dub_sale_events_mv
-
-
diff --git a/packages/tinybird/pipes/all_stats.pipe b/packages/tinybird/pipes/all_stats.pipe
index c545951ce1..9e415b9743 100644
--- a/packages/tinybird/pipes/all_stats.pipe
+++ b/packages/tinybird/pipes/all_stats.pipe
@@ -5,7 +5,7 @@ SQL >
SELECT
(SELECT COUNT(timestamp) FROM dub_click_events_mv) AS clicks,
- (SELECT COUNT(timestamp) + 42036155 FROM dub_links_metadata_latest FINAL) AS links,
+ (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 a0c752c734..732f7c376a 100644
--- a/packages/tinybird/pipes/coordinates_all.pipe
+++ b/packages/tinybird/pipes/coordinates_all.pipe
@@ -4,20 +4,20 @@ 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
@@ -25,22 +25,22 @@ 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
@@ -48,26 +48,26 @@ 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
@@ -75,22 +75,22 @@ 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 d79c2d70a4..b10fdfec0a 100644
--- a/packages/tinybird/pipes/coordinates_sales.pipe
+++ b/packages/tinybird/pipes/coordinates_sales.pipe
@@ -4,23 +4,23 @@ 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_click_events_id_pipe.pipe b/packages/tinybird/pipes/dub_click_events_id_pipe.pipe
index e59e06ab0d..3f45d4934b 100644
--- a/packages/tinybird/pipes/dub_click_events_id_pipe.pipe
+++ b/packages/tinybird/pipes/dub_click_events_id_pipe.pipe
@@ -3,38 +3,7 @@ TAGS "Dub MV Pipes"
NODE mv
SQL >
- SELECT
- timestamp,
- click_id,
- link_id,
- url,
- continent,
- country,
- city,
- region,
- latitude,
- longitude,
- device,
- device_model,
- device_vendor,
- browser,
- browser_version,
- os,
- os_version,
- engine,
- engine_version,
- cpu_architecture,
- ua,
- bot,
- referer,
- referer_url,
- identity_hash,
- ip,
- qr,
- CASE
- WHEN trigger = '' THEN CASE WHEN qr = true THEN 'qr' ELSE 'link' END ELSE trigger
- END as trigger
- FROM dub_click_events
+ SELECT * FROM dub_click_events_mv
TYPE materialized
DATASOURCE dub_click_events_id
diff --git a/packages/tinybird/pipes/dub_click_events_pipe.pipe b/packages/tinybird/pipes/dub_click_events_pipe.pipe
index ccd4e4e972..d46cc86f10 100644
--- a/packages/tinybird/pipes/dub_click_events_pipe.pipe
+++ b/packages/tinybird/pipes/dub_click_events_pipe.pipe
@@ -6,33 +6,49 @@ SQL >
SELECT
timestamp,
click_id,
+ toLowCardinality(
+ coalesce(click_event.workspace_id, link_metadata.workspace_id)
+ ) AS workspace_id,
link_id,
+ coalesce(click_event.domain, link_metadata.domain) AS domain,
+ coalesce(click_event.key, link_metadata.key) AS key,
url,
- continent,
- country,
- city,
- region,
+ -- geolocation fields
+ toLowCardinality(continent) continent,
+ toLowCardinality(country) country,
+ toLowCardinality(city) city,
+ toLowCardinality(region) region,
latitude,
longitude,
+ -- additional fields
device,
browser,
os,
- CASE
- WHEN trigger = '' THEN
- CASE
- WHEN qr = true THEN 'qr'
- ELSE 'link'
- END
- ELSE trigger
+ CASE
+ WHEN trigger = '' THEN CASE WHEN qr = true THEN 'qr' ELSE 'link' END ELSE trigger
END as trigger,
- engine,
ua,
- coalesce(identity_hash, '') as identity_hash,
referer,
referer_url,
ip,
- qr
- FROM dub_click_events
+ coalesce(identity_hash, '') as identity_hash,
+ -- other fields from raw DS
+ device_model,
+ device_vendor,
+ browser_version,
+ os_version,
+ engine,
+ engine_version,
+ cpu_architecture,
+ qr,
+ bot
+ FROM dub_click_events AS click_event ANY
+ LEFT JOIN
+ (
+ SELECT link_id, workspace_id, domain, key
+ FROM dub_links_metadata_latest
+ WHERE link_id IN (SELECT link_id FROM dub_click_events)
+ ) AS link_metadata USING link_id
TYPE materialized
DATASOURCE dub_click_events_mv
diff --git a/packages/tinybird/pipes/dub_click_events_pipe_with_domain_key.pipe b/packages/tinybird/pipes/dub_click_events_pipe_with_domain_key.pipe
deleted file mode 100644
index 0f46b94427..0000000000
--- a/packages/tinybird/pipes/dub_click_events_pipe_with_domain_key.pipe
+++ /dev/null
@@ -1,37 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT
- dce.timestamp,
- dce.click_id,
- dce.link_id,
- coalesce(dlm.domain, '') as domain,
- coalesce(dlm.key, '') as key,
- dce.url,
- dce.continent,
- dce.country,
- dce.city,
- dce.region,
- dce.latitude,
- dce.longitude,
- dce.device,
- dce.browser,
- dce.os,
- CASE
- WHEN dce.trigger = ''
- THEN CASE WHEN dce.qr = true THEN 'qr' ELSE 'link' END
- ELSE dce.trigger
- END as trigger,
- dce.engine,
- dce.ua,
- coalesce(dce.identity_hash, '') as identity_hash,
- dce.referer,
- dce.referer_url,
- dce.ip,
- dce.qr
- FROM dub_click_events dce
- LEFT JOIN (SELECT * FROM dub_links_metadata_latest FINAL) dlm ON dce.link_id = dlm.link_id
-
-
diff --git a/packages/tinybird/pipes/dub_lead_events_pipe.pipe b/packages/tinybird/pipes/dub_lead_events_pipe.pipe
index b40cfdbc6f..c34ef0e018 100644
--- a/packages/tinybird/pipes/dub_lead_events_pipe.pipe
+++ b/packages/tinybird/pipes/dub_lead_events_pipe.pipe
@@ -5,29 +5,53 @@ SQL >
SELECT
timestamp,
- event_id,
- event_name,
click_id,
+ toLowCardinality(
+ coalesce(lead_event.workspace_id, link_metadata.workspace_id)
+ ) AS workspace_id,
link_id,
- customer_id,
+ coalesce(lead_event.domain, link_metadata.domain) AS domain,
+ coalesce(lead_event.key, link_metadata.key) AS key,
url,
- continent,
- country,
- city,
- region,
+ event_id,
+ event_name,
+ customer_id,
+ metadata,
+ -- geolocation fields
+ toLowCardinality(continent) continent,
+ toLowCardinality(country) country,
+ toLowCardinality(city) city,
+ toLowCardinality(region) region,
latitude,
longitude,
+ -- additional fields
device,
browser,
os,
- engine,
+ CASE
+ WHEN trigger = '' THEN CASE WHEN qr = true THEN 'qr' ELSE 'link' END ELSE trigger
+ END AS trigger,
ua,
referer,
referer_url,
- qr,
ip,
- metadata
- FROM dub_lead_events
+ -- other fields from raw DS
+ device_model,
+ device_vendor,
+ browser_version,
+ os_version,
+ engine,
+ engine_version,
+ cpu_architecture,
+ qr,
+ bot
+ FROM dub_lead_events AS lead_event ANY
+ LEFT JOIN
+ (
+ SELECT link_id, workspace_id, domain, key
+ FROM dub_links_metadata_latest FINAL
+ WHERE link_id IN (SELECT link_id FROM dub_lead_events)
+ ) AS link_metadata USING link_id
TYPE materialized
DATASOURCE dub_lead_events_mv
diff --git a/packages/tinybird/pipes/dub_links_metadata_pipe.pipe b/packages/tinybird/pipes/dub_links_metadata_pipe.pipe
index 96cea42280..e0bd396e6c 100644
--- a/packages/tinybird/pipes/dub_links_metadata_pipe.pipe
+++ b/packages/tinybird/pipes/dub_links_metadata_pipe.pipe
@@ -3,7 +3,27 @@ TAGS "Dub MV Pipes"
NODE mv
SQL >
- SELECT * FROM dub_links_metadata
+ SELECT
+ timestamp,
+ toLowCardinality(
+ CASE
+ WHEN startsWith(workspace_id, 'ws_c')
+ THEN replace(workspace_id, 'ws_', '')
+ ELSE workspace_id
+ END
+ ) AS workspace_id,
+ link_id,
+ domain,
+ key,
+ url,
+ toLowCardinality(program_id) program_id,
+ partner_id,
+ folder_id,
+ tag_ids,
+ tenant_id,
+ created_at,
+ deleted
+ FROM dub_links_metadata
TYPE materialized
DATASOURCE dub_links_metadata_latest
diff --git a/packages/tinybird/pipes/dub_regular_links_metadata_pipe.pipe b/packages/tinybird/pipes/dub_regular_links_metadata_pipe.pipe
deleted file mode 100644
index c034ca2046..0000000000
--- a/packages/tinybird/pipes/dub_regular_links_metadata_pipe.pipe
+++ /dev/null
@@ -1,19 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT *
- FROM dub_links_metadata
- WHERE
- workspace_id not in [
- 'cm05wnnpo000711ztj05wwdbu', -- buffer
- 'ws_1JYEZKSFX7RMB5M9XP4G0CCAT', -- jobber
- 'clawqph22020408jng5s9b2tp', -- cal
- 'ws_1JQ7175XGRN2ZYE2QAPVA4A26' -- homeserve
- ]
-
-TYPE materialized
-DATASOURCE dub_regular_links_metadata_latest
-
-
diff --git a/packages/tinybird/pipes/dub_sale_events_id_pipe.pipe b/packages/tinybird/pipes/dub_sale_events_id_pipe.pipe
deleted file mode 100644
index f143560596..0000000000
--- a/packages/tinybird/pipes/dub_sale_events_id_pipe.pipe
+++ /dev/null
@@ -1,11 +0,0 @@
-TAGS "Dub MV Pipes"
-
-NODE mv
-SQL >
-
- SELECT * FROM dub_sale_events
-
-TYPE materialized
-DATASOURCE dub_sale_events_id
-
-
diff --git a/packages/tinybird/pipes/dub_sale_events_pipe.pipe b/packages/tinybird/pipes/dub_sale_events_pipe.pipe
index 0526f5a090..16409fc42d 100644
--- a/packages/tinybird/pipes/dub_sale_events_pipe.pipe
+++ b/packages/tinybird/pipes/dub_sale_events_pipe.pipe
@@ -5,32 +5,69 @@ SQL >
SELECT
timestamp,
- event_id,
- event_name,
click_id,
+ toLowCardinality(coalesce(sale_event.workspace_id, link_metadata.workspace_id)) AS workspace_id,
link_id,
+ coalesce(sale_event.domain, link_metadata.domain) AS domain,
+ coalesce(sale_event.key, link_metadata.key) AS key,
+ url,
+
+ -- sale event fields
+ event_id,
+ event_name,
customer_id,
payment_processor,
invoice_id,
amount,
- url,
- continent,
- country,
- city,
- region,
+ -- sale_type: "new" if this sale is the earliest one for (customer_id, link_id)
+ if(timestamp = first_sale_ts, 'new', 'recurring') AS sale_type,
+ metadata,
+
+ -- geolocation fields
+ toLowCardinality(continent) AS continent,
+ toLowCardinality(country) AS country,
+ toLowCardinality(city) AS city,
+ toLowCardinality(region) AS region,
latitude,
longitude,
+
+ -- additional fields
device,
browser,
os,
- engine,
+ CASE
+ WHEN trigger = '' THEN CASE WHEN qr = true THEN 'qr' ELSE 'link' END ELSE trigger
+ END AS trigger,
ua,
referer,
referer_url,
- qr,
ip,
- metadata
- FROM dub_sale_events
+
+ -- other fields from raw DS
+ device_model,
+ device_vendor,
+ browser_version,
+ os_version,
+ engine,
+ engine_version,
+ cpu_architecture,
+ qr,
+ bot
+
+ FROM dub_sale_events AS sale_event
+ LEFT JOIN
+ (
+ -- find the first sale timestamp for each customer_id:link_id pair
+ SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
+ FROM dub_sale_events
+ GROUP BY customer_id, link_id
+ ) AS first_sales USING (customer_id, link_id)
+ LEFT JOIN
+ (
+ SELECT link_id, workspace_id, domain, key
+ FROM dub_links_metadata_latest FINAL
+ WHERE link_id IN (SELECT link_id FROM dub_sale_events)
+ ) AS link_metadata USING (link_id)
TYPE materialized
DATASOURCE dub_sale_events_mv
diff --git a/packages/tinybird/pipes/get_audit_logs.pipe b/packages/tinybird/pipes/get_audit_logs.pipe
index 558e810120..426501187b 100644
--- a/packages/tinybird/pipes/get_audit_logs.pipe
+++ b/packages/tinybird/pipes/get_audit_logs.pipe
@@ -2,27 +2,27 @@ 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 391b3485f0..66c6700c2b 100644
--- a/packages/tinybird/pipes/get_click_event.pipe
+++ b/packages/tinybird/pipes/get_click_event.pipe
@@ -2,19 +2,19 @@ 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 e7e1ed8427..c58575ab64 100644
--- a/packages/tinybird/pipes/get_framer_lead_events.pipe
+++ b/packages/tinybird/pipes/get_framer_lead_events.pipe
@@ -2,10 +2,10 @@ 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 13afda162a..1398892652 100644
--- a/packages/tinybird/pipes/get_import_error_logs.pipe
+++ b/packages/tinybird/pipes/get_import_error_logs.pipe
@@ -6,26 +6,26 @@ 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 4871c2a057..60e15fdabd 100644
--- a/packages/tinybird/pipes/get_lead_event.pipe
+++ b/packages/tinybird/pipes/get_lead_event.pipe
@@ -1,9 +1,13 @@
+DESCRIPTION >
+ internal pipe for updating lead event
+
+
NODE endpoint
SQL >
%
SELECT *
- FROM dub_lead_events
+ FROM dub_lead_events_mv
WHERE
customer_id
= {{
diff --git a/packages/tinybird/pipes/get_lead_event_by_id.pipe b/packages/tinybird/pipes/get_lead_event_by_id.pipe
deleted file mode 100644
index f1bf522d9e..0000000000
--- a/packages/tinybird/pipes/get_lead_event_by_id.pipe
+++ /dev/null
@@ -1,23 +0,0 @@
-DESCRIPTION >
- internal pipe for updating lead event
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM dub_lead_events
- WHERE
- event_id
- = {{
- String(
- eventId,
- "nLvob3FdmsYuI1BI",
- description="The unique event ID.",
- required=True,
- )
- }}
- ORDER BY timestamp DESC
-
-
diff --git a/packages/tinybird/pipes/get_lead_events.pipe b/packages/tinybird/pipes/get_lead_events.pipe
index 0502e950b0..7e329df633 100644
--- a/packages/tinybird/pipes/get_lead_events.pipe
+++ b/packages/tinybird/pipes/get_lead_events.pipe
@@ -2,11 +2,11 @@ NODE endpoint
SQL >
%
- SELECT *
- FROM dub_lead_events
- 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_sale_event.pipe b/packages/tinybird/pipes/get_sale_event.pipe
deleted file mode 100644
index 8e53e249b9..0000000000
--- a/packages/tinybird/pipes/get_sale_event.pipe
+++ /dev/null
@@ -1,18 +0,0 @@
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM dub_sale_events_id
- WHERE
- event_id
- = {{
- String(
- eventId,
- "O9Q8fKbfY809HXBp",
- description="The unique event ID.",
- required=True,
- )
- }}
-
-
diff --git a/packages/tinybird/pipes/get_webhook_events.pipe b/packages/tinybird/pipes/get_webhook_events.pipe
index ebb55afb3c..d6ad446634 100644
--- a/packages/tinybird/pipes/get_webhook_events.pipe
+++ b/packages/tinybird/pipes/get_webhook_events.pipe
@@ -6,19 +6,19 @@ 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_browsers.pipe b/packages/tinybird/pipes/v2_browsers.pipe
deleted file mode 100644
index 362f18af4e..0000000000
--- a/packages/tinybird/pipes/v2_browsers.pipe
+++ /dev/null
@@ -1,316 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE browsers_clicks
-SQL >
-
- %
- SELECT browser, COUNT(browser) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND browser != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY browser
- ORDER BY clicks DESC
-
-
-
-NODE browsers_leads
-SQL >
-
- %
- SELECT browser, COUNT(browser) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND browser != 'Unknown'
- {% 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 %}
- GROUP BY browser
- ORDER BY leads DESC
-
-
-
-NODE browsers_sales
-SQL >
-
- %
- SELECT browser, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT browser, COUNT(*) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND browser != 'Unknown'
- {% 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 %}
- GROUP BY browser
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE browsers_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT browser, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND browser != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT browser, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT browser, COUNT(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY browser
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE browsers_composite
-SQL >
-
- %
- SELECT dce.browser AS browser, clicks, leads, sales, amount, saleAmount
- FROM (SELECT * FROM browsers_clicks) AS dce
- LEFT JOIN (SELECT * FROM browsers_leads) AS dle ON dce.browser = dle.browser
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} browsers_sales_with_type {% else %} browsers_sales {% end %}
- ) AS dse
- ON dce.browser = dse.browser
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} browsers_clicks
- {% elif eventType == 'leads' %} browsers_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} browsers_sales_with_type {% else %} browsers_sales {% end %}
- {% else %} browsers_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_cities.pipe b/packages/tinybird/pipes/v2_cities.pipe
deleted file mode 100644
index d74d974605..0000000000
--- a/packages/tinybird/pipes/v2_cities.pipe
+++ /dev/null
@@ -1,416 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE cities_clicks
-SQL >
-
- %
- SELECT city, CONCAT(country, '-', region) as region, country, COUNT(city) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND city != 'Unknown'
- AND region NOT IN (
- 'Unknown',
- 'arn1',
- 'bom1',
- 'cdg1',
- 'cle1',
- 'cpt1',
- 'dub1',
- 'fra1',
- 'gru1',
- 'hkg1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'lhr1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1'
- )
- {% if defined(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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY city, region, country
- ORDER BY clicks DESC
- LIMIT 1000
-
-
-
-NODE cities_leads
-SQL >
-
- %
- SELECT city, CONCAT(country, '-', region) as region, country, COUNT(city) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND city != 'Unknown'
- AND region NOT IN (
- 'Unknown',
- 'arn1',
- 'bom1',
- 'cdg1',
- 'cle1',
- 'cpt1',
- 'dub1',
- 'fra1',
- 'gru1',
- 'hkg1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'lhr1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1'
- )
- {% if defined(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 %}
- GROUP BY city, region, country
- ORDER BY leads DESC
- LIMIT 1000
-
-
-
-NODE cities_sales
-SQL >
-
- %
- SELECT city, CONCAT(country, '-', region) as region, country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT city, region, country, COUNT(city) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND city != 'Unknown'
- AND region NOT IN (
- 'Unknown',
- 'arn1',
- 'bom1',
- 'cdg1',
- 'cle1',
- 'cpt1',
- 'dub1',
- 'fra1',
- 'gru1',
- 'hkg1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'lhr1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1'
- )
- {% if defined(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 %}
- GROUP BY city, region, country
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE cities_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT city, region, country, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND city != 'Unknown'
- AND region NOT IN (
- 'Unknown',
- 'arn1',
- 'bom1',
- 'cdg1',
- 'cle1',
- 'cpt1',
- 'dub1',
- 'fra1',
- 'gru1',
- 'hkg1',
- 'hnd1',
- 'iad1',
- 'icn1',
- 'kix1',
- 'lhr1',
- 'pdx1',
- 'sfo1',
- 'sin1',
- 'syd1'
- )
- {% if defined(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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT city, CONCAT(country, '-', region) as region, country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT city, region, country, COUNT(city) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY city, region, country
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE cities_composite
-SQL >
-
- %
- SELECT
- dce.city AS city,
- dce.region AS region,
- dce.country AS country,
- clicks,
- leads,
- sales,
- amount,
- saleAmount
- FROM (SELECT city, region, country, clicks FROM cities_clicks) AS dce
- LEFT JOIN (SELECT * FROM cities_leads) AS dle ON dce.city = dle.city AND dce.region = dle.region
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} cities_sales_with_type {% else %} cities_sales {% end %}
- ) AS dse
- ON dce.city = dse.city
- AND dce.region = dse.region
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} cities_clicks
- {% elif eventType == 'leads' %} cities_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} cities_sales_with_type {% else %} cities_sales {% end %}
- {% else %} cities_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_continents.pipe b/packages/tinybird/pipes/v2_continents.pipe
deleted file mode 100644
index a9cb129485..0000000000
--- a/packages/tinybird/pipes/v2_continents.pipe
+++ /dev/null
@@ -1,319 +0,0 @@
-DESCRIPTION >
- Top continents
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE continents_clicks
-SQL >
-
- %
- SELECT continent, COUNT(continent) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND continent != ''
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY continent
- ORDER BY clicks DESC
-
-
-
-NODE continents_leads
-SQL >
-
- %
- SELECT continent, COUNT(continent) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND continent != ''
- {% 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 %}
- GROUP BY continent
- ORDER BY leads DESC
-
-
-
-NODE continents_sales
-SQL >
-
- %
- SELECT continent, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT continent, COUNT(continent) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND continent != ''
- {% 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 %}
- GROUP BY continent
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE continents_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT continent, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND continent != ''
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT continent, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT continent, COUNT(continent) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY continent
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE continents_composite
-SQL >
-
- %
- SELECT dce.continent AS continent, clicks, leads, sales, amount, saleAmount
- FROM (SELECT continent, clicks FROM continents_clicks) AS dce
- LEFT JOIN (SELECT * FROM continents_leads) AS dle ON dce.continent = dle.continent
- LEFT JOIN
- (
- SELECT *
- FROM
- {% if defined(saleType) %} continents_sales_with_type
- {% else %} continents_sales
- {% end %}
- ) AS dse
- ON dce.continent = dse.continent
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} continents_clicks
- {% elif eventType == 'leads' %} continents_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} continents_sales_with_type {% else %} continents_sales {% end %}
- {% else %} continents_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_countries.pipe b/packages/tinybird/pipes/v2_countries.pipe
deleted file mode 100644
index aca78d3cf0..0000000000
--- a/packages/tinybird/pipes/v2_countries.pipe
+++ /dev/null
@@ -1,308 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE countries_clicks
-SQL >
-
- %
- SELECT country, COUNT(country) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND country != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY country
- ORDER BY clicks DESC
-
-
-
-NODE countries_leads
-SQL >
-
- %
- SELECT country, COUNT(country) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND country != 'Unknown'
- {% 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 %}
- GROUP BY country
- ORDER BY leads DESC
-
-
-
-NODE countries_sales
-SQL >
-
- %
- SELECT country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT country, COUNT(country) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND country != 'Unknown'
- {% 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 %}
- GROUP BY country
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE countries_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT country, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND country != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT country, COUNT(country) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY country
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE countries_composite
-SQL >
-
- %
- SELECT dce.country AS country, clicks, leads, sales, amount, saleAmount
- FROM (SELECT country, clicks FROM countries_clicks) AS dce
- LEFT JOIN (SELECT * FROM countries_leads) AS dle ON dce.country = dle.country
- LEFT JOIN
- (
- SELECT *
- FROM
- {% if defined(saleType) %} countries_sales_with_type
- {% else %} countries_sales
- {% end %}
- ) AS dse
- ON dce.country = dse.country
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} countries_clicks
- {% elif eventType == 'leads' %} countries_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} countries_sales_with_type {% else %} countries_sales {% end %}
- {% else %} countries_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_customer_events.pipe b/packages/tinybird/pipes/v2_customer_events.pipe
index f23af53c4a..8589c91b57 100644
--- a/packages/tinybird/pipes/v2_customer_events.pipe
+++ b/packages/tinybird/pipes/v2_customer_events.pipe
@@ -8,46 +8,46 @@ 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) }}
@@ -55,34 +55,34 @@ 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) }}
@@ -90,48 +90,48 @@ 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) }}
@@ -139,26 +139,26 @@ 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_devices.pipe b/packages/tinybird/pipes/v2_devices.pipe
deleted file mode 100644
index 078650166d..0000000000
--- a/packages/tinybird/pipes/v2_devices.pipe
+++ /dev/null
@@ -1,316 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE devices_clicks
-SQL >
-
- %
- SELECT device, COUNT(device) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND device != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY device
- ORDER BY clicks DESC
-
-
-
-NODE devices_leads
-SQL >
-
- %
- SELECT device, COUNT(device) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND device != 'Unknown'
- {% 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 %}
- GROUP BY device
- ORDER BY leads DESC
-
-
-
-NODE devices_sales
-SQL >
-
- %
- SELECT device, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT device, COUNT(device) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND device != 'Unknown'
- {% 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 %}
- GROUP BY device
- ORDER BY amount DESC
- ) subquery
-
-
-
-NODE devices_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT device, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND device != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT device, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT device, COUNT(device) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY device
- ORDER BY amount DESC
- ) subquery
-
-
-
-NODE devices_composite
-SQL >
-
- %
- SELECT dce.device AS device, clicks, leads, sales, amount
- FROM (SELECT device, clicks FROM devices_clicks) AS dce
- LEFT JOIN (SELECT * FROM devices_leads) AS dle ON dce.device = dle.device
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} devices_sales_with_type {% else %} devices_sales {% end %}
- ) AS dse
- ON dce.device = dse.device
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} devices_clicks
- {% elif eventType == 'leads' %} devices_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} devices_sales_with_type {% else %} devices_sales {% end %}
- {% else %} devices_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_os.pipe b/packages/tinybird/pipes/v2_os.pipe
deleted file mode 100644
index 53958f915e..0000000000
--- a/packages/tinybird/pipes/v2_os.pipe
+++ /dev/null
@@ -1,315 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE os_clicks
-SQL >
-
- %
- SELECT os, COUNT(os) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND os != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY os
- ORDER BY clicks DESC
-
-
-
-NODE os_leads
-SQL >
-
- %
- SELECT os, COUNT(os) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND os != 'Unknown'
- {% 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 %}
- GROUP BY os
- ORDER BY leads DESC
-
-
-
-NODE os_sales
-SQL >
-
- %
- SELECT os, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT os, COUNT(os) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND os != 'Unknown'
- {% 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 %}
- GROUP BY os
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE os_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT os, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND os != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT os, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT os, COUNT(os) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY os
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE os_composite
-SQL >
-
- %
- SELECT dce.os AS os, clicks, leads, sales, amount, saleAmount
- FROM (SELECT os, clicks FROM os_clicks) AS dce
- LEFT JOIN (SELECT * FROM os_leads) AS dle ON dce.os = dle.os
- LEFT JOIN
- (
- SELECT * FROM {% if defined(saleType) %} os_sales_with_type {% else %} os_sales {% end %}
- ) AS dse
- ON dce.os = dse.os
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} os_clicks
- {% elif eventType == 'leads' %} os_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} os_sales_with_type {% else %} os_sales {% end %}
- {% else %} os_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_referer_urls.pipe b/packages/tinybird/pipes/v2_referer_urls.pipe
deleted file mode 100644
index f06e218fd7..0000000000
--- a/packages/tinybird/pipes/v2_referer_urls.pipe
+++ /dev/null
@@ -1,324 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE referer_urls_clicks
-SQL >
-
- %
- SELECT splitByString('?', referer_url)[1] as refererUrl, COUNT(*) as clicks
- FROM
- dub_click_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND referer != 'Unknown'
- {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY splitByString('?', referer_url)[1]
- ORDER BY clicks DESC
- LIMIT 5000
-
-
-
-NODE referer_urls_leads
-SQL >
-
- %
- SELECT splitByString('?', referer_url)[1] as refererUrl, COUNT(referer_url) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND referer != 'Unknown'
- {% 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 %}
- GROUP BY splitByString('?', referer_url)[1]
- ORDER BY leads DESC
- LIMIT 1000
-
-
-
-NODE referer_urls_sales
-SQL >
-
- %
- SELECT refererUrl, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT
- splitByString('?', referer_url)[1] as refererUrl,
- COUNT(referer_url) as sales,
- sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND referer != 'Unknown'
- {% 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 %}
- GROUP BY splitByString('?', referer_url)[1]
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE referer_urls_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT
- splitByString('?', referer_url)[1] as refererUrl,
- customer_id,
- link_id,
- timestamp,
- amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND referer != 'Unknown'
- {% 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT refererUrl, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT refererUrl, COUNT(refererUrl) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY refererUrl
- ORDER BY amount DESC
- LIMIT 5000
- ) as subquery
-
-
-
-NODE referer_urls_composite
-SQL >
-
- %
- SELECT dce.refererUrl as refererUrl, clicks, leads, sales, amount, saleAmount
- FROM (SELECT refererUrl, clicks FROM referer_urls_clicks) AS dce
- LEFT JOIN (SELECT * FROM referer_urls_leads) AS dle ON dce.refererUrl = dle.refererUrl
- LEFT JOIN
- (
- SELECT *
- FROM
- {% if defined(saleType) %} referer_urls_sales_with_type
- {% else %} referer_urls_sales
- {% end %}
- ) AS dse
- ON dce.refererUrl = dse.refererUrl
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} referer_urls_clicks
- {% elif eventType == 'leads' %} referer_urls_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} referer_urls_sales_with_type
- {% else %} referer_urls_sales
- {% end %}
- {% else %} referer_urls_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_referers.pipe b/packages/tinybird/pipes/v2_referers.pipe
deleted file mode 100644
index b58c0c5851..0000000000
--- a/packages/tinybird/pipes/v2_referers.pipe
+++ /dev/null
@@ -1,305 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE referers_clicks
-SQL >
-
- %
- SELECT referer, COUNT(referer) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY referer
- ORDER BY clicks DESC
- LIMIT 1000
-
-
-
-NODE referers_leads
-SQL >
-
- %
- SELECT referer, COUNT(referer) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- GROUP BY referer
- ORDER BY leads DESC
- LIMIT 1000
-
-
-
-NODE referers_sales
-SQL >
-
- %
- SELECT referer, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT referer, COUNT(referer) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- GROUP BY referer
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE referers_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT referer, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT referer, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT referer, COUNT(referer) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY referer
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE referers_composite
-SQL >
-
- %
- SELECT dce.referer AS referer, clicks, leads, sales, amount, saleAmount
- FROM (SELECT referer, clicks FROM referers_clicks) AS dce
- LEFT JOIN (SELECT * FROM referers_leads) AS dle ON dce.referer = dle.referer
- LEFT JOIN (SELECT * FROM
- {% if defined(saleType) %} referers_sales_with_type
- {% else %} referers_sales
- {% end %}) AS dse ON dce.referer = dse.referer
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} referers_clicks
- {% elif eventType == 'leads' %} referers_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} referers_sales_with_type {% else %} referers_sales {% end %}
- {% else %} referers_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_regions.pipe b/packages/tinybird/pipes/v2_regions.pipe
deleted file mode 100644
index dca68494a0..0000000000
--- a/packages/tinybird/pipes/v2_regions.pipe
+++ /dev/null
@@ -1,421 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE regions_clicks
-SQL >
-
- %
- SELECT CONCAT(country, '-', region) as region, country, clicks,
- FROM
- (
- SELECT region, country, COUNT(region) as clicks
- FROM
- dub_click_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND 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(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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY region, country
- ORDER BY clicks DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE regions_leads
-SQL >
-
- %
- SELECT CONCAT(country, '-', region) as region, country, leads,
- FROM
- (
- SELECT region, country, COUNT(region) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND 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(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 %}
- GROUP BY region, country
- ORDER BY leads DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE regions_sales
-SQL >
-
- %
- SELECT CONCAT(country, '-', region) as region, country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT region, country, COUNT(region) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND 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(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 %}
- GROUP BY region, country
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE regions_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT region, country, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND 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(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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT CONCAT(country, '-', region) as region, country, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT region, country, COUNT(region) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY region, country
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE regions_composite
-SQL >
-
- %
- SELECT dce.region AS region, dce.country AS country, clicks, leads, sales, amount, saleAmount
- FROM (SELECT region, country, clicks FROM regions_clicks) AS dce
- LEFT JOIN (SELECT * FROM regions_leads) AS dle ON dce.region = dle.region
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} regions_sales_with_type {% else %} regions_sales {% end %}
- ) AS dse
- ON dce.region = dse.region
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} regions_clicks
- {% elif eventType == 'leads' %} regions_leads
- {% elif eventType == 'sales' %} {% if defined(saleType) %} regions_sales_with_type
- {% else %} regions_sales
- {% end %}
- {% else %} regions_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_timeseries.pipe b/packages/tinybird/pipes/v2_timeseries.pipe
deleted file mode 100644
index b8b971dec5..0000000000
--- a/packages/tinybird/pipes/v2_timeseries.pipe
+++ /dev/null
@@ -1,459 +0,0 @@
-DESCRIPTION >
- Timeseries data
-
-
-TAGS "Dub Endpoints"
-
-NODE month_intervals
-SQL >
-
- %
- WITH
- toStartOfMonth(
- toDateTime64({{ DateTime64(start, '2024-02-24 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS start,
- toStartOfMonth(
- toDateTime64({{ DateTime64(end, '2024-05-23 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS
- end,
- dateDiff('month', start, end) + 1 AS months_diff
- SELECT
- arrayJoin(
- arrayMap(
- x -> toDateTime64(start + toIntervalMonth(x), 3, {{ String(timezone, 'UTC') }}),
- range(0, months_diff)
- )
- ) as interval
-
-
-
-NODE day_intervals
-SQL >
-
- %
- WITH
- toStartOfDay(
- toDateTime64({{ DateTime64(start, '2024-02-24 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS start,
- toStartOfDay(
- toDateTime64({{ DateTime64(end, '2024-05-23 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), toUInt32(end + 86400),
- 86400
- )
- )
- ) as interval
-
-
-
-NODE hour_intervals
-SQL >
-
- %
- WITH
- toStartOfHour(
- toDateTime64({{ DateTime64(start, '2024-05-22 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS start,
- toStartOfHour(
- toDateTime64({{ DateTime64(end, '2024-05-23 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS
- end
- SELECT
- arrayJoin(
- arrayMap(x -> toDateTime64(x, 3), range(toUInt32(start), toUInt32(end + 3600), 3600)
- )
- ) as interval
-
-
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE timeseries_clicks_data
-SQL >
-
- %
- SELECT
- {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
- {% elif granularity == "month" %}
- toDateTime64(
- toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
- 3,
- {{ String(timezone, 'UTC') }}
- )
- {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
- {% end %} AS interval,
- uniq(click_id) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE timeseries_clicks
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as start, clicks
- FROM
- {% if granularity == "minute" %} minute_intervals
- {% elif granularity == "hour" %} hour_intervals
- {% elif granularity == "month" %} month_intervals
- {% else %} day_intervals
- {% end %}
- LEFT JOIN timeseries_clicks_data USING interval
-
-
-
-NODE timeseries_leads_data
-SQL >
-
- %
- SELECT
- {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
- {% elif granularity == "month" %}
- toDateTime64(
- toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
- 3,
- {{ String(timezone, 'UTC') }}
- )
- {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
- {% end %} AS interval,
- uniq(*) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE timeseries_leads
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as start, leads
- FROM
- {% if granularity == "minute" %} minute_intervals
- {% elif granularity == "hour" %} hour_intervals
- {% elif granularity == "month" %} month_intervals
- {% else %} day_intervals
- {% end %}
- LEFT JOIN timeseries_leads_data USING interval
-
-
-
-NODE timeseries_sales_data
-DESCRIPTION >
- undefined
-
-SQL >
-
- %
- SELECT
- {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
- {% elif granularity == "month" %}
- toDateTime64(
- toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
- 3,
- {{ String(timezone, 'UTC') }}
- )
- {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
- {% end %} AS interval,
- uniq(*) as sales,
- sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE timeseries_sales_data_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT
- {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
- {% elif granularity == "month" %}
- toDateTime64(
- toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
- 3,
- {{ String(timezone, 'UTC') }}
- )
- {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
- {% end %} AS interval,
- customer_id,
- link_id,
- timestamp,
- amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT interval, uniq(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE timeseries_sales
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as start, sales, amount, amount as saleAmount
- FROM
- {% if granularity == "minute" %} minute_intervals
- {% elif granularity == "hour" %} hour_intervals
- {% elif granularity == "month" %} month_intervals
- {% else %} day_intervals
- {% end %}
- LEFT JOIN
- {% if defined(saleType) %} timeseries_sales_data_with_type
- {% else %} timeseries_sales_data
- {% end %} USING interval
-
-
-
-NODE timeseries_composite
-SQL >
-
- SELECT dce.start AS start, clicks, leads, sales, amount, saleAmount
- FROM (SELECT start, clicks FROM timeseries_clicks) AS dce
- LEFT JOIN (SELECT * FROM timeseries_leads) AS dle ON dce.start = dle.start
- LEFT JOIN (SELECT * FROM timeseries_sales) AS dse ON dce.start = dse.start
-
-
-
-NODE timeseries_billing
-SQL >
-
- SELECT
- dce.start AS start,
- clicks,
- leads,
- sales,
- amount,
- saleAmount,
- (clicks + leads + sales) AS totalEvents
- FROM (SELECT start, clicks FROM timeseries_clicks) AS dce
- LEFT JOIN (SELECT * FROM timeseries_leads) AS dle ON dce.start = dle.start
- LEFT JOIN (SELECT * FROM timeseries_sales) AS dse ON dce.start = dse.start
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} timeseries_clicks
- {% elif eventType == 'leads' %} timeseries_leads
- {% elif eventType == 'sales' %} timeseries_sales
- {% elif eventType == 'billing' %} timeseries_billing
- {% else %} timeseries_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_top_links.pipe b/packages/tinybird/pipes/v2_top_links.pipe
deleted file mode 100644
index ee90240303..0000000000
--- a/packages/tinybird/pipes/v2_top_links.pipe
+++ /dev/null
@@ -1,313 +0,0 @@
-DESCRIPTION >
- Top links endpoint (most updated version with linkIds filter support)
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE top_links_clicks
-SQL >
-
- %
- SELECT link_id as link, COUNT(*) AS clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY link_id
- ORDER BY clicks DESC
- LIMIT 1000
-
-
-
-NODE top_links_leads
-SQL >
-
- %
- SELECT link_id as link, COUNT(*) AS leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY link_id
- ORDER BY leads DESC
- LIMIT 5000
-
-
-
-NODE top_links_sales
-SQL >
-
- %
- SELECT link, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT link_id as link, COUNT(*) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY link_id
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE top_links_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT link_id, customer_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT link, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT link_id as link, COUNT(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY link_id
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE top_links_composite
-SQL >
-
- %
- SELECT dce.link AS link, clicks, leads, sales, amount, saleAmount
- FROM (SELECT link, clicks FROM top_links_clicks) AS dce
- LEFT JOIN (SELECT * FROM top_links_leads) AS dle ON dce.link = dle.link
- LEFT JOIN
- (
- SELECT *
- FROM
- {% if defined(saleType) %} top_links_sales_with_type
- {% else %} top_links_sales
- {% end %}
- ) AS dse
- ON dce.link = dse.link
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} top_links_clicks
- {% elif eventType == 'leads' %} top_links_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} top_links_sales_with_type {% else %} top_links_sales {% end %}
- {% else %} top_links_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_top_partners.pipe b/packages/tinybird/pipes/v2_top_partners.pipe
deleted file mode 100644
index bff392e1cb..0000000000
--- a/packages/tinybird/pipes/v2_top_partners.pipe
+++ /dev/null
@@ -1,261 +0,0 @@
-NODE partner_links
-SQL >
-
- %
- SELECT link_id, partner_id
- FROM dub_regular_links_metadata_latest FINAL
- WHERE
- deleted == 0 AND partner_id != ''
- {% 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 %}
-
-
-
-NODE top_partners_clicks
-SQL >
-
- %
- SELECT pl.partner_id as partnerId, COUNT(*) AS clicks
- FROM dub_click_events_mv AS ce
- JOIN partner_links AS pl ON ce.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND ce.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND ce.country = {{ country }} {% end %}
- {% if defined(region) %} AND ce.region = {{ region }} {% end %}
- {% if defined(city) %} AND ce.city = {{ city }} {% end %}
- {% if defined(device) %} AND ce.device = {{ device }} {% end %}
- {% if defined(browser) %} AND ce.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND ce.os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% end %}
- {% if defined(referer) %} AND ce.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', ce.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND ce.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND ce.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND ce.url
- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND ce.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND ce.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND ce.url = {{ url }} {% end %}
- {% if defined(start) %} AND ce.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND ce.timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY pl.partner_id
- ORDER BY clicks DESC
- LIMIT 5000
-
-
-
-NODE top_partners_leads
-SQL >
-
- %
- SELECT pl.partner_id as partnerId, COUNT(*) AS leads
- FROM dub_lead_events AS le
- JOIN partner_links AS pl ON le.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND le.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND le.country = {{ country }} {% end %}
- {% if defined(region) %} AND le.region = {{ region }} {% end %}
- {% if defined(city) %} AND le.city = {{ city }} {% end %}
- {% if defined(device) %} AND le.device = {{ device }} {% end %}
- {% if defined(browser) %} AND le.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND le.os = {{ os }} {% end %}
- {% if defined(referer) %} AND le.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', le.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND le.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND le.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND le.url
- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND le.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND le.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND le.url = {{ url }} {% end %}
- {% if defined(start) %} AND le.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND le.timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY pl.partner_id
- ORDER BY leads DESC
- LIMIT 5000
-
-
-
-NODE top_partners_sales
-SQL >
-
- %
- SELECT pl.partner_id as partnerId, COUNT(*) AS sales, sum(amount) as saleAmount
- FROM dub_sale_events AS se
- JOIN partner_links AS pl ON se.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND se.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND se.country = {{ country }} {% end %}
- {% if defined(region) %} AND se.region = {{ region }} {% end %}
- {% if defined(city) %} AND se.city = {{ city }} {% end %}
- {% if defined(device) %} AND se.device = {{ device }} {% end %}
- {% if defined(browser) %} AND se.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND se.os = {{ os }} {% end %}
- {% if defined(referer) %} AND se.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', se.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND se.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND se.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND se.url
- LIKE concat('%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%')
- {% end %}
- {% if defined(utm_term) %}
- AND se.url LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND se.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND se.url = {{ url }} {% end %}
- {% if defined(start) %} AND se.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND se.timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY pl.partner_id
- ORDER BY saleAmount DESC, sales DESC, partnerId ASC
- LIMIT 5000
-
-
-
-NODE top_partners_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT se.customer_id, se.link_id, se.timestamp, se.amount, pl.partner_id
- FROM dub_sale_events AS se
- JOIN partner_links AS pl ON se.link_id = pl.link_id
- WHERE
- 1
- {% if defined(continent) %} AND se.continent = {{ continent }} {% end %}
- {% if defined(country) %} AND se.country = {{ country }} {% end %}
- {% if defined(region) %} AND se.region = {{ region }} {% end %}
- {% if defined(city) %} AND se.city = {{ city }} {% end %}
- {% if defined(device) %} AND se.device = {{ device }} {% end %}
- {% if defined(browser) %} AND se.browser = {{ browser }} {% end %}
- {% if defined(os) %} AND se.os = {{ os }} {% end %}
- {% if defined(referer) %} AND se.referer = {{ referer }} {% end %}
- {% if defined(refererUrl) %}
- AND splitByString('?', se.referer_url)[1] = {{ refererUrl }}
- {% end %}
- {% if defined(utm_source) %}
- AND se.url
- LIKE concat('%utm_source=', encodeURLFormComponent({{ String(utm_source) }}), '%')
- {% end %}
- {% if defined(utm_medium) %}
- AND se.url
- LIKE concat('%utm_medium=', encodeURLFormComponent({{ String(utm_medium) }}), '%')
- {% end %}
- {% if defined(utm_campaign) %}
- AND se.url LIKE concat(
- '%utm_campaign=', encodeURLFormComponent({{ String(utm_campaign) }}), '%'
- )
- {% end %}
- {% if defined(utm_term) %}
- AND se.url
- LIKE concat('%utm_term=', encodeURLFormComponent({{ String(utm_term) }}), '%')
- {% end %}
- {% if defined(utm_content) %}
- AND se.url
- LIKE concat('%utm_content=', encodeURLFormComponent({{ String(utm_content) }}), '%')
- {% end %}
- {% if defined(url) %} AND se.url = {{ url }} {% end %}
- {% if defined(start) %} AND se.timestamp >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND se.timestamp <= {{ DateTime64(end) }} {% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT pl.partner_id as partnerId, COUNT(*) AS sales, sum(amount) as saleAmount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- JOIN partner_links AS pl ON sales.link_id = pl.link_id
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY pl.partner_id
- ORDER BY saleAmount DESC, sales DESC, partnerId ASC
- LIMIT 5000
-
-
-
-NODE top_partners_composite
-SQL >
-
- %
- SELECT c.partnerId as partnerId, c.clicks as clicks, l.leads as leads, s.sales as sales, s.saleAmount as saleAmount
- FROM top_partners_clicks AS c
- LEFT JOIN top_partners_leads AS l ON c.partnerId = l.partnerId
- LEFT JOIN
- {% if defined(saleType) %} top_partners_sales_with_type
- {% else %} top_partners_sales
- {% end %} AS s ON c.partnerId = s.partnerId
- ORDER BY saleAmount DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} top_partners_clicks
- {% elif eventType == 'leads' %} top_partners_leads
- {% elif eventType == 'composite' %} top_partners_composite
- {% else %} {% if defined(saleType) %} top_partners_sales_with_type
- {% else %} top_partners_sales
- {% end %}
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_top_programs.pipe b/packages/tinybird/pipes/v2_top_programs.pipe
index a125a14527..a0cd1c1449 100644
--- a/packages/tinybird/pipes/v2_top_programs.pipe
+++ b/packages/tinybird/pipes/v2_top_programs.pipe
@@ -6,9 +6,9 @@ NODE program_links
SQL >
%
- SELECT link_id, program_id
- FROM dub_regular_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 != ''
@@ -16,43 +16,43 @@ 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
@@ -60,47 +60,47 @@ 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
@@ -108,47 +108,47 @@ NODE top_programs_sales
SQL >
%
- SELECT pl.program_id as programId, COUNT(*) AS sales, sum(amount) as saleAmount
- FROM dub_sale_events 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 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
@@ -167,12 +167,12 @@ 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/v2_top_tags.pipe b/packages/tinybird/pipes/v2_top_tags.pipe
deleted file mode 100644
index c4f9fcd527..0000000000
--- a/packages/tinybird/pipes/v2_top_tags.pipe
+++ /dev/null
@@ -1,287 +0,0 @@
-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(trigger) %} AND trigger = {{ trigger }} {% 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(trigger) %} AND trigger = {{ trigger }} {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 amount 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(trigger) %} AND trigger = {{ trigger }} {% 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.pipe
deleted file mode 100644
index 38b78cb5de..0000000000
--- a/packages/tinybird/pipes/v2_top_urls.pipe
+++ /dev/null
@@ -1,301 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE top_urls_clicks
-SQL >
-
- %
- SELECT url, 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
- url != ''
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY url
- ORDER BY clicks DESC
- LIMIT 5000
-
-
-
-NODE top_urls_leads
-SQL >
-
- %
- SELECT url, COUNT(*) AS leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY url
- ORDER BY leads DESC
- LIMIT 1000
-
-
-
-NODE top_urls_sales
-SQL >
-
- %
- SELECT url, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT url, COUNT(*) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- GROUP BY url
- ORDER BY amount DESC
- LIMIT 1000
- ) as subquery
-
-
-
-NODE top_urls_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT url, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 >= {{ DateTime64(start) }} {% end %}
- {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT url, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT url, COUNT(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY url
- ORDER BY amount DESC
- LIMIT 5000
- ) as subquery
-
-
-
-NODE top_urls_composite
-SQL >
-
- %
- SELECT dce.url AS url, clicks, leads, sales, amount, saleAmount
- FROM (SELECT url, clicks FROM top_urls_clicks) AS dce
- LEFT JOIN (SELECT * FROM top_urls_leads) AS dle ON dce.url = dle.url
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} top_urls_sales_with_type {% else %} top_urls_sales {% end %}
- ) AS dse
- ON dce.url = dse.url
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} top_urls_clicks
- {% elif eventType == 'leads' %} top_urls_leads
- {% elif eventType == 'sales' %} {% if defined(saleType) %} top_urls_sales_with_type
- {% else %} top_urls_sales
- {% end %}
- {% else %} top_urls_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_triggers.pipe b/packages/tinybird/pipes/v2_triggers.pipe
deleted file mode 100644
index 3941e74424..0000000000
--- a/packages/tinybird/pipes/v2_triggers.pipe
+++ /dev/null
@@ -1,323 +0,0 @@
-DESCRIPTION >
- Top countries
-
-
-TAGS "Dub Endpoints"
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE trigger_clicks
-SQL >
-
- %
- SELECT trigger, COUNT(trigger) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
- {% if defined(continent) %} AND continent = {{ continent }} {% end %}
- {% if defined(country) %} AND country = {{ country }} {% end %}
- {% if defined(region) %} AND region = {{ region }} {% end %}
- {% if defined(city) %} AND city = {{ city }} {% end %}
- {% if defined(device) %} AND device = {{ device }} {% end %}
- {% if defined(browser) %} AND browser = {{ browser }} {% end %}
- {% if defined(os) %} AND os = {{ os }} {% end %}
- {% if defined(trigger) %} AND trigger = {{ trigger }} {% 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 %}
- GROUP BY trigger
- ORDER BY clicks DESC
-
-
-
-NODE trigger_leads
-SQL >
-
- %
- SELECT CASE WHEN qr = 0 THEN 'link' WHEN qr = 1 THEN 'qr' END as trigger, COUNT(qr) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- GROUP BY qr
- ORDER BY leads DESC
-
-
-
-NODE trigger_sales
-SQL >
-
- %
- SELECT trigger, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT
- CASE WHEN qr = 0 THEN 'link' WHEN qr = 1 THEN 'qr' END as trigger,
- COUNT(qr) as sales,
- sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- GROUP BY qr
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE trigger_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT qr, customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT trigger, sales, amount, amount AS saleAmount
- FROM
- (
- SELECT
- CASE WHEN qr = 0 THEN 'link' WHEN qr = 1 THEN 'qr' END as trigger,
- COUNT(qr) as sales,
- sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY qr
- ORDER BY amount DESC
- ) as subquery
-
-
-
-NODE trigger_composite
-SQL >
-
- %
- SELECT dce.trigger AS trigger, clicks, leads, sales, amount, saleAmount
- FROM (SELECT * FROM trigger_clicks) AS dce
- LEFT JOIN (SELECT * FROM trigger_leads) AS dle ON dce.trigger = dle.trigger
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} trigger_sales_with_type {% else %} trigger_sales {% end %}
- ) AS dse
- ON dce.trigger = dse.trigger
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} trigger_clicks
- {% elif eventType == 'leads' %} trigger_leads
- {% elif eventType == 'sales' %} {% if defined(saleType) %} trigger_sales_with_type
- {% else %} trigger_sales
- {% end %}
- {% else %} trigger_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_usage.pipe b/packages/tinybird/pipes/v2_usage.pipe
deleted file mode 100644
index 7c9917349e..0000000000
--- a/packages/tinybird/pipes/v2_usage.pipe
+++ /dev/null
@@ -1,174 +0,0 @@
-DESCRIPTION >
- Timeseries data
-
-
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- from dub_regular_links_metadata_latest FINAL
- WHERE
- workspace_id
- = {{
- String(
- workspaceId,
- 'ws_clrei1gld0002vs9mzn93p8ik',
- description="The ID of the workspace",
- required=True,
- )
- }}
-
-
-
-NODE day_intervals
-SQL >
-
- %
- WITH
- toStartOfDay(
- toDateTime64({{ DateTime64(start, '2024-09-03 00:00:00.000') }}, 3),
- {{ String(timezone, 'UTC') }}
- ) AS start,
- toStartOfDay(
- toDateTime64({{ DateTime64(end, '2024-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
-
-
-
-NODE usage_clicks_data
-SQL >
-
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- uniq(*) as clicks
- FROM
- dub_click_events_mv
- PREWHERE link_id in (SELECT link_id from workspace_links)
- WHERE
- timestamp >= {{ DateTime(start, '2024-09-03 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-10-03 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE usage_leads_data
-SQL >
-
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- uniq(*) as leads
- FROM
- dub_lead_events_mv
- PREWHERE link_id in (SELECT link_id from workspace_links)
- WHERE
- timestamp >= {{ DateTime(start, '2024-09-03 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-10-03 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE usage_events
-SQL >
-
- SELECT
- formatDateTime(di.interval, '%FT%T.000%z') as date, clicks, leads, (clicks + leads) as value
- FROM day_intervals as di
- LEFT JOIN (SELECT * FROM usage_clicks_data) AS uc ON di.interval = uc.interval
- LEFT JOIN (SELECT * FROM usage_leads_data) AS ul ON di.interval = ul.interval
-
-
-
-NODE usage_links_data
-DESCRIPTION >
- undefined
-
-SQL >
-
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- uniq(*) as links
- FROM dub_links_metadata_latest FINAL
- WHERE
- workspace_id
- = {{
- String(
- workspaceId,
- 'ws_clrei1gld0002vs9mzn93p8ik',
- description="The ID of the workspace",
- required=True,
- )
- }}
- AND created_at >= {{ DateTime(start, '2024-09-03 00:00:00') }}
- AND created_at < {{ DateTime(end, '2024-10-03 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE usage_links
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as date, links as value
- FROM day_intervals
- LEFT JOIN usage_links_data USING interval
-
-
-
-NODE usage_revenue_data
-SQL >
-
- %
- SELECT
- toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
- sum(amount) as revenue
- FROM
- dub_sale_events_mv
- PREWHERE link_id in (SELECT link_id from workspace_links)
- WHERE
- timestamp >= {{ DateTime(start, '2024-09-03 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-10-03 00:00:00') }}
- GROUP BY interval
- ORDER BY interval
-
-
-
-NODE usage_revenue
-SQL >
-
- %
- SELECT formatDateTime(interval, '%FT%T.000%z') as date, revenue as value
- FROM day_intervals
- LEFT JOIN usage_revenue_data USING interval
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if resource == 'events' %} usage_events
- {% elif resource == 'revenue' %} usage_revenue
- {% else %} usage_links
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_utms.pipe b/packages/tinybird/pipes/v2_utms.pipe
deleted file mode 100644
index b8d0fc40fb..0000000000
--- a/packages/tinybird/pipes/v2_utms.pipe
+++ /dev/null
@@ -1,366 +0,0 @@
-NODE workspace_links
-SQL >
-
- %
- SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
- WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
- {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
- {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
- {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
- {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
- {% elif defined(folderId) %} AND folder_id = {{ folderId }}
- {% end %}
- {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
- {% if defined(tagIds) %}
- AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
- {% end %}
- {% if defined(root) %}
- {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
- {% end %}
-
-
-
-NODE utms_clicks
-SQL >
-
- %
- WITH
- decodeURLFormComponent(
- extractURLParameter(
- url,
- {{
- String(
- groupByUtmTag,
- 'utm_source',
- description="The UTM tag to retrieve data for",
- required=True,
- )
- }}
- )
- ) as utm
- SELECT utm, count(*) as clicks
- FROM
- {% if defined(customerId) %} dub_click_events_id
- {% else %} dub_click_events_mv
- {% end %}
- {% if defined(customerId) %}
- PREWHERE click_id IN (
- SELECT DISTINCT click_id
- FROM dub_lead_events_mv
- WHERE customer_id = {{ String(customerId) }}
- )
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %}
- AND url != ''
- {% 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 decodeURLFormComponent(extractURLParameter(url, 'utm_source'))
- = {{ String(utm_source) }}
- {% end %}
- {% if defined(utm_medium) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_medium'))
- = {{ String(utm_medium) }}
- {% end %}
- {% if defined(utm_campaign) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_campaign'))
- = {{ String(utm_campaign) }}
- {% end %}
- {% if defined(utm_term) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_term')) = {{ String(utm_term) }}
- {% end %}
- {% if defined(utm_content) %}
- AND decodeURLFormComponent(extractURLParameter(url, '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 utm
- HAVING utm != ''
- ORDER BY clicks DESC
-
-
-
-NODE utms_leads
-SQL >
-
- %
- WITH
- decodeURLFormComponent(
- extractURLParameter(
- url,
- {{
- String(
- groupByUtmTag,
- 'utm_source',
- description="The UTM tag to retrieve data for",
- required=True,
- )
- }}
- )
- ) as utm
- SELECT utm, count(*) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 decodeURLFormComponent(extractURLParameter(url, 'utm_source'))
- = {{ String(utm_source) }}
- {% end %}
- {% if defined(utm_medium) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_medium'))
- = {{ String(utm_medium) }}
- {% end %}
- {% if defined(utm_campaign) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_campaign'))
- = {{ String(utm_campaign) }}
- {% end %}
- {% if defined(utm_term) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_term')) = {{ String(utm_term) }}
- {% end %}
- {% if defined(utm_content) %}
- AND decodeURLFormComponent(extractURLParameter(url, '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 utm
- HAVING utm != ''
- ORDER BY leads DESC
-
-
-
-NODE utms_sales
-SQL >
-
- %
- WITH
- decodeURLFormComponent(
- extractURLParameter(
- url,
- {{
- String(
- groupByUtmTag,
- 'utm_source',
- description="The UTM tag to retrieve data for",
- required=True,
- )
- }}
- )
- ) as utm
- SELECT utm, count(*) as sales, sum(amount) as saleAmount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 decodeURLFormComponent(extractURLParameter(url, 'utm_source'))
- = {{ String(utm_source) }}
- {% end %}
- {% if defined(utm_medium) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_medium'))
- = {{ String(utm_medium) }}
- {% end %}
- {% if defined(utm_campaign) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_campaign'))
- = {{ String(utm_campaign) }}
- {% end %}
- {% if defined(utm_term) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_term')) = {{ String(utm_term) }}
- {% end %}
- {% if defined(utm_content) %}
- AND decodeURLFormComponent(extractURLParameter(url, '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 utm
- HAVING utm != ''
- ORDER BY saleAmount DESC
-
-
-
-NODE utms_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT
- decodeURLFormComponent(
- extractURLParameter(
- url,
- {{
- String(
- groupByUtmTag,
- 'utm_source',
- description="The UTM tag to retrieve data for",
- required=True,
- )
- }}
- )
- ) as utm,
- customer_id,
- link_id,
- timestamp,
- amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ linkId }}
- {% end %} AND url != ''
- {% 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 decodeURLFormComponent(extractURLParameter(url, 'utm_source'))
- = {{ String(utm_source) }}
- {% end %}
- {% if defined(utm_medium) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_medium'))
- = {{ String(utm_medium) }}
- {% end %}
- {% if defined(utm_campaign) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_campaign'))
- = {{ String(utm_campaign) }}
- {% end %}
- {% if defined(utm_term) %}
- AND decodeURLFormComponent(extractURLParameter(url, 'utm_term'))
- = {{ String(utm_term) }}
- {% end %}
- {% if defined(utm_content) %}
- AND decodeURLFormComponent(extractURLParameter(url, '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 %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT utm, count(*) as sales, sum(amount) as saleAmount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
- GROUP BY utm
- HAVING utm != ''
- ORDER BY saleAmount DESC
-
-
-
-NODE utms_composite
-SQL >
-
- %
- SELECT dce.utm AS utm, dce.clicks as clicks, leads, sales, saleAmount
- FROM (SELECT utm, clicks FROM utms_clicks) AS dce
- LEFT JOIN (SELECT * FROM utms_leads) AS dle ON dce.utm = dle.utm
- LEFT JOIN
- (
- SELECT *
- FROM {% if defined(saleType) %} utms_sales_with_type {% else %} utms_sales {% end %}
- ) AS dse
- ON dce.utm = dse.utm
- ORDER BY clicks DESC
-
-
-
-NODE endpoint
-SQL >
-
- %
- SELECT *
- FROM
- {% if eventType == 'clicks' %} utms_clicks
- {% elif eventType == 'leads' %} utms_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} utms_sales_with_type {% else %} utms_sales {% end %}
- {% else %} utms_composite
- {% end %}
-
-
diff --git a/packages/tinybird/pipes/v2_count.pipe b/packages/tinybird/pipes/v3_count.pipe
similarity index 58%
rename from packages/tinybird/pipes/v2_count.pipe
rename to packages/tinybird/pipes/v3_count.pipe
index 86db1a0a45..37bd6a39db 100644
--- a/packages/tinybird/pipes/v2_count.pipe
+++ b/packages/tinybird/pipes/v3_count.pipe
@@ -9,13 +9,18 @@ SQL >
%
SELECT link_id
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
+ FROM dub_links_metadata_latest FINAL
WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'cl7pj5kq4006835rbjlt2ofka',
+ description="The unique ID for the workspace",
+ required=True,
+ )
+ }}
+ AND deleted == 0
{% if defined(programId) %} AND program_id = {{ programId }} {% end %}
{% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
{% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
@@ -36,7 +41,7 @@ NODE count_clicks
SQL >
%
- SELECT COUNT(*) as clicks
+ SELECT 'count' as groupByField, COUNT(*) as clicks
FROM
{% if defined(customerId) %} dub_click_events_id
{% else %} dub_click_events_mv
@@ -47,16 +52,17 @@ SQL >
FROM dub_lead_events_mv
WHERE customer_id = {{ String(customerId) }}
)
- {% elif not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
{% end %}
WHERE
true
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
{% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
{% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ 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 %}
{% if defined(country) %} AND country = {{ country }} {% end %}
{% if defined(region) %} AND region = {{ region }} {% end %}
@@ -93,20 +99,19 @@ NODE count_leads
SQL >
%
- SELECT COUNT(*) as leads
- FROM
- dub_lead_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links)
- {% end %}
+ SELECT 'count' as groupByField, COUNT(*) as leads
+ FROM dub_lead_events_mv
WHERE
true
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
{% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
{% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id in (SELECT link_id from workspace_links)
{% 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 %}
@@ -116,11 +121,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 >= {{ DateTime(start) }} {% end %}
{% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %}
@@ -130,7 +146,6 @@ SQL >
{% set metadataKey = item.get('operand', '').split('.')[1] %}
{% set operator = item.get('operator', 'equals') %}
{% set value = item.get('value', '') %}
-
{% if operator == 'equals' %}
AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
{% elif operator == 'notEquals' %}
@@ -154,103 +169,23 @@ NODE count_sales
SQL >
%
- SELECT sales, amount, amount AS saleAmount
+ SELECT 'count' as groupByField, sales, amount, amount AS saleAmount
FROM
(
SELECT COUNT(*) as sales, sum(amount) as amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
- WHERE
- true
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% elif defined(linkId) %} AND link_id = {{ 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 %}
- {% if defined(filters) %}
- {% for item in JSON(filters, '[]') %}
- {% if item.get('operand', '').startswith('metadata.') %}
- {% set metadataKey = item.get('operand', '').split('.')[1] %}
- {% set operator = item.get('operator', 'equals') %}
- {% set value = item.get('value', '') %}
-
- {% if operator == 'equals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
- {% elif operator == 'notEquals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
- {% elif operator == 'greaterThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
- {% elif operator == 'lessThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
- {% elif operator == 'greaterThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
- {% elif operator == 'lessThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
- {% end %}
- {% end %}
- {% end %}
- {% end %}
- ) AS subquery
-
-
-
-NODE count_sales_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT customer_id, link_id, timestamp, amount
- FROM
- dub_sale_events_mv
- {% if not defined(linkId) and not defined(linkIds) and (
- defined(workspaceId) or defined(partnerId) or defined(programId)
- ) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %}
+ FROM dub_sale_events_mv
WHERE
true
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
{% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
{% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id in (SELECT link_id from workspace_links)
{% end %}
{% if defined(customerId) %} AND customer_id = {{ String(customerId) }} {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
+ {% if defined(saleType) %} AND sale_type = {{ String(saleType) }} {% end %}
{% if defined(continent) %} AND continent = {{ continent }} {% end %}
{% if defined(country) %} AND country = {{ country }} {% end %}
{% if defined(region) %} AND region = {{ region }} {% end %}
@@ -292,7 +227,6 @@ SQL >
{% set metadataKey = item.get('operand', '').split('.')[1] %}
{% set operator = item.get('operator', 'equals') %}
{% set value = item.get('value', '') %}
-
{% if operator == 'equals' %}
AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
{% elif operator == 'notEquals' %}
@@ -309,27 +243,6 @@ SQL >
{% end %}
{% end %}
{% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT sales, amount, amount AS saleAmount
- FROM
- (
- SELECT COUNT(*) as sales, sum(amount) as amount
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp <= first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
) AS subquery
@@ -338,13 +251,8 @@ NODE count_composite
SQL >
%
- SELECT clicks, leads, sales, amount, saleAmount
- FROM
- count_clicks,
- count_leads,
- {% if defined(saleType) %} count_sales_with_type
- {% else %} count_sales
- {% end %}
+ SELECT 'count' as groupByField, clicks, leads, sales, amount, saleAmount
+ FROM count_clicks, count_leads, count_sales
@@ -356,9 +264,9 @@ SQL >
FROM
{% if eventType == 'clicks' %} count_clicks
{% elif eventType == 'leads' %} count_leads
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} count_sales_with_type {% else %} count_sales {% end %}
- {% else %} count_composite
+ {% elif eventType == 'sales' %} count_sales
+ {% elif eventType == 'composite' %} count_composite
+ {% else %} count_clicks
{% end %}
diff --git a/packages/tinybird/pipes/v2_events.pipe b/packages/tinybird/pipes/v3_events.pipe
similarity index 58%
rename from packages/tinybird/pipes/v2_events.pipe
rename to packages/tinybird/pipes/v3_events.pipe
index 25fc13fbdf..06e0cd73fa 100644
--- a/packages/tinybird/pipes/v2_events.pipe
+++ b/packages/tinybird/pipes/v3_events.pipe
@@ -8,14 +8,19 @@ NODE workspace_links
SQL >
%
- SELECT link_id, domain, key
- FROM
- {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest
- {% else %} dub_regular_links_metadata_latest
- {% end %} FINAL
+ SELECT link_id
+ FROM dub_links_metadata_latest FINAL
WHERE
- deleted == 0
- {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'cl7pj5kq4006835rbjlt2ofka',
+ description="The unique ID for the workspace",
+ required=True,
+ )
+ }}
+ AND deleted == 0
{% if defined(programId) %} AND program_id = {{ programId }} {% end %}
{% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
{% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
@@ -41,22 +46,27 @@ SQL >
splitByString('?', referer_url)[1] as referer_url_processed,
CONCAT(country, '-', region) as region_processed,
'click' as event
- FROM {% if defined(customerId) %} dub_click_events_id {% else %} dub_click_events_mv {% end %}
- WHERE
- timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }}
+ FROM
+ {% if defined(customerId) %} dub_click_events_id
+ {% else %} dub_click_events_mv
+ {% end %}
{% if defined(customerId) %}
- AND click_id IN (
+ PREWHERE click_id IN (
SELECT DISTINCT click_id
FROM dub_lead_events_mv
WHERE customer_id = {{ String(customerId) }}
)
- {% elif defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% 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 %}
+ WHERE
+ true
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
+ {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id in (SELECT link_id from workspace_links)
+ {% end %}
{% if defined(continent) %} AND continent = {{ continent }} {% end %}
{% if defined(country) %} AND country = {{ country }} {% end %}
{% if defined(region) %} AND region = {{ region }} {% end %}
@@ -84,6 +94,8 @@ SQL >
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 %}
ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
LIMIT {{ Int32(limit, 100) }}
{% if defined(offset) %} OFFSET {{ Int32(offset, 0) }} {% end %}
@@ -101,15 +113,16 @@ SQL >
'lead' as event
FROM dub_lead_events_mv
WHERE
- timestamp >= {{ DateTime(start, '2024-01-01 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2025-12-31 00:00:00') }}
+ true
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
{% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% 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)
+ {% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id in (SELECT link_id from workspace_links)
{% 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 %}
@@ -136,14 +149,14 @@ SQL >
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 %}
{% if defined(filters) %}
{% for item in JSON(filters, '[]') %}
{% if item.get('operand', '').startswith('metadata.') %}
{% set metadataKey = item.get('operand', '').split('.')[1] %}
{% set operator = item.get('operator', 'equals') %}
{% set value = item.get('value', '') %}
-
{% if operator == 'equals' %}
AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
{% elif operator == 'notEquals' %}
@@ -160,7 +173,6 @@ SQL >
{% end %}
{% end %}
{% end %}
-
ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
LIMIT {{ Int32(limit, 100) }}
{% if defined(offset) %} OFFSET {{ Int32(offset, 0) }} {% end %}
@@ -179,15 +191,17 @@ SQL >
'sale' as event
FROM dub_sale_events_mv
WHERE
- timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2025-12-31 00:00:00') }}
+ true
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
{% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% 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)
+ {% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id in (SELECT link_id from workspace_links)
{% end %}
{% if defined(customerId) %} AND customer_id = {{ String(customerId) }} {% end %}
- {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %}
+ {% if defined(saleType) %} AND sale_type = {{ String(saleType) }} {% end %}
{% if defined(continent) %} AND continent = {{ continent }} {% end %}
{% if defined(country) %} AND country = {{ country }} {% end %}
{% if defined(region) %} AND region = {{ region }} {% end %}
@@ -214,14 +228,14 @@ SQL >
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 %}
{% if defined(filters) %}
{% for item in JSON(filters, '[]') %}
{% if item.get('operand', '').startswith('metadata.') %}
{% set metadataKey = item.get('operand', '').split('.')[1] %}
{% set operator = item.get('operator', 'equals') %}
{% set value = item.get('value', '') %}
-
{% if operator == 'equals' %}
AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
{% elif operator == 'notEquals' %}
@@ -238,112 +252,6 @@ SQL >
{% end %}
{% end %}
{% end %}
-
- ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
- LIMIT {{ Int32(limit, 100) }}
- {% if defined(offset) %} OFFSET {{ Int32(offset, 0) }} {% end %}
-
-
-
-NODE sale_events_with_type
-SQL >
-
- %
- WITH
- sales AS (
- SELECT
- *,
- amount as saleAmount,
- CONCAT(country, '-', region) as region_processed,
- splitByString('?', referer_url)[1] as referer_url_processed,
- 'sale' as event
- FROM dub_sale_events_mv
- WHERE
- timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }}
- AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }}
- {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
- {% 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(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(filters) %}
- {% for item in JSON(filters, '[]') %}
- {% if item.get('operand', '').startswith('metadata.') %}
- {% set metadataKey = item.get('operand', '').split('.')[1] %}
- {% set operator = item.get('operator', 'equals') %}
- {% set value = item.get('value', '') %}
-
- {% if operator == 'equals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
- {% elif operator == 'notEquals' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
- {% elif operator == 'greaterThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
- {% elif operator == 'lessThan' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
- {% elif operator == 'greaterThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
- {% elif operator == 'lessThanOrEqual' %}
- AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
- {% end %}
- {% end %}
- {% end %}
- {% end %}
- ),
- distinct_sales AS (SELECT DISTINCT customer_id, link_id FROM sales),
- min_timestamps AS (
- SELECT customer_id, link_id, min(timestamp) AS first_sale_ts
- FROM dub_sale_events_mv
- WHERE (customer_id, link_id) IN distinct_sales
- GROUP BY customer_id, link_id
- )
- SELECT *, CASE WHEN timestamp = first_sale_ts THEN 'new' ELSE 'recurring' END as sale_type
- FROM sales
- INNER JOIN min_timestamps USING (customer_id, link_id)
- WHERE
- 1 = 1
- {% if defined(saleType) %}
- {% if saleType == 'new' %} AND timestamp = first_sale_ts
- {% elif saleType == 'recurring' %} AND timestamp > first_sale_ts
- {% end %}
- {% end %}
ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %}
LIMIT {{ Int32(limit, 100) }}
{% if defined(offset) %} OFFSET {{ Int32(offset, 0) }} {% end %}
@@ -354,12 +262,12 @@ NODE endpoint
SQL >
%
- SELECT *
- FROM
- {% if eventType == 'leads' %} lead_events
- {% elif eventType == 'sales' %}
- {% if defined(saleType) %} sale_events_with_type {% else %} sale_events {% end %}
- {% else %} click_events
- {% end %}
+ SELECT *
+ FROM
+ {% if eventType == 'leads' %} lead_events
+ {% elif eventType == 'sales' %}
+ {% if defined(saleType) %} sale_events_with_type {% else %} sale_events {% end %}
+ {% else %} click_events
+ {% end %}
diff --git a/packages/tinybird/pipes/v3_group_by.pipe b/packages/tinybird/pipes/v3_group_by.pipe
new file mode 100644
index 0000000000..3a294c2821
--- /dev/null
+++ b/packages/tinybird/pipes/v3_group_by.pipe
@@ -0,0 +1,443 @@
+DESCRIPTION >
+ Top countries
+
+
+TAGS "Dub Endpoints"
+
+NODE workspace_links
+SQL >
+
+ %
+ SELECT link_id
+ FROM dub_links_metadata_latest FINAL
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'cl7pj5kq4006835rbjlt2ofka',
+ description="The unique ID for the workspace",
+ required=True,
+ )
+ }}
+ AND deleted == 0
+ {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
+ {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
+ {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
+ {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
+ {% elif defined(folderId) %} AND folder_id = {{ folderId }}
+ {% end %}
+ {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
+ {% if defined(tagIds) %}
+ AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
+ {% end %}
+ {% if defined(root) %}
+ {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
+ {% end %}
+
+
+
+NODE group_by_clicks
+SQL >
+
+ %
+ SELECT
+ multiIf(
+ {{ String(groupBy) }} = 'top_links',
+ link_id,
+ {{ String(groupBy) }} = 'top_urls',
+ url,
+ {{ String(groupBy) }} = 'referers',
+ referer,
+ {{ String(groupBy) }} = 'referer_urls',
+ splitByString('?', referer_url)[1],
+ {{ String(groupBy) }} = 'utm_sources',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_source')),
+ {{ String(groupBy) }} = 'utm_mediums',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_medium')),
+ {{ String(groupBy) }} = 'utm_campaigns',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_campaign')),
+ {{ String(groupBy) }} = 'utm_terms',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_term')),
+ {{ String(groupBy) }} = 'utm_contents',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_content')),
+ {{ String(groupBy) }} = 'ref',
+ decodeURLFormComponent(extractURLParameter(url, 'ref')),
+ {{ String(groupBy) }} = 'countries',
+ country,
+ {{ String(groupBy) }} = 'regions',
+ CONCAT(country, '-', region) as region,
+ {{ String(groupBy) }} = 'cities',
+ city,
+ {{ String(groupBy) }} = 'continents',
+ continent,
+ {{ String(groupBy) }} = 'devices',
+ device,
+ {{ String(groupBy) }} = 'browsers',
+ browser,
+ {{ String(groupBy) }} = 'os',
+ os,
+ {{ String(groupBy) }} = 'triggers',
+ trigger,
+ link_id
+ ) AS groupByField,
+ {% if String(groupBy) == 'cities' %} country, CONCAT(country, '-', region) as region,
+ {% elif String(groupBy) == 'regions' %} country,
+ {% end %}
+ COUNT(*) AS clicks
+ FROM
+ {% if defined(customerId) %} dub_click_events_id
+ {% else %} dub_click_events_mv
+ {% end %}
+ {% if defined(customerId) %}
+ PREWHERE click_id IN (
+ SELECT DISTINCT click_id
+ FROM dub_lead_events_mv
+ WHERE customer_id = {{ String(customerId) }}
+ )
+ {% end %}
+ WHERE
+ groupByField != '' AND groupByField != 'Unknown'
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
+ {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id IN (SELECT link_id FROM workspace_links)
+ {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
+ GROUP BY
+ groupByField
+ {% if String(groupBy) == 'cities' %}, country, region
+ {% elif String(groupBy) == 'regions' %}, country
+ {% end %}
+ ORDER BY clicks DESC
+ LIMIT 5000
+
+
+
+NODE group_by_leads
+SQL >
+
+ %
+ SELECT
+ multiIf(
+ {{ String(groupBy) }} = 'top_links',
+ link_id,
+ {{ String(groupBy) }} = 'top_urls',
+ url,
+ {{ String(groupBy) }} = 'referers',
+ referer,
+ {{ String(groupBy) }} = 'referer_urls',
+ splitByString('?', referer_url)[1],
+ {{ String(groupBy) }} = 'utm_sources',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_source')),
+ {{ String(groupBy) }} = 'utm_mediums',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_medium')),
+ {{ String(groupBy) }} = 'utm_campaigns',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_campaign')),
+ {{ String(groupBy) }} = 'utm_terms',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_term')),
+ {{ String(groupBy) }} = 'utm_contents',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_content')),
+ {{ String(groupBy) }} = 'ref',
+ decodeURLFormComponent(extractURLParameter(url, 'ref')),
+ {{ String(groupBy) }} = 'countries',
+ country,
+ {{ String(groupBy) }} = 'regions',
+ CONCAT(country, '-', region) as region,
+ {{ String(groupBy) }} = 'cities',
+ city,
+ {{ String(groupBy) }} = 'continents',
+ continent,
+ {{ String(groupBy) }} = 'devices',
+ device,
+ {{ String(groupBy) }} = 'browsers',
+ browser,
+ {{ String(groupBy) }} = 'os',
+ os,
+ {{ String(groupBy) }} = 'triggers',
+ trigger,
+ link_id
+ ) AS groupByField,
+ {% if String(groupBy) == 'cities' %} country, CONCAT(country, '-', region) as region,
+ {% elif String(groupBy) == 'regions' %} country,
+ {% end %}
+ COUNT(*) as leads
+ FROM dub_lead_events_mv
+ WHERE
+ groupByField != '' AND groupByField != 'Unknown'
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
+ {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id in (SELECT link_id from workspace_links)
+ {% end %}
+ {% 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 >= {{ DateTime(start) }} {% end %}
+ {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %}
+ {% if defined(filters) %}
+ {% for item in JSON(filters, '[]') %}
+ {% if item.get('operand', '').startswith('metadata.') %}
+ {% set metadataKey = item.get('operand', '').split('.')[1] %}
+ {% set operator = item.get('operator', 'equals') %}
+ {% set value = item.get('value', '') %}
+ {% if operator == 'equals' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
+ {% elif operator == 'notEquals' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
+ {% elif operator == 'greaterThan' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
+ {% elif operator == 'lessThan' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
+ {% elif operator == 'greaterThanOrEqual' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
+ {% elif operator == 'lessThanOrEqual' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
+ {% end %}
+ {% end %}
+ {% end %}
+ {% end %}
+ GROUP BY
+ groupByField
+ {% if String(groupBy) == 'cities' %}, country, region
+ {% elif String(groupBy) == 'regions' %}, country
+ {% end %}
+ ORDER BY leads DESC
+ LIMIT 5000
+
+
+
+NODE group_by_sales
+SQL >
+
+ %
+ SELECT
+ multiIf(
+ {{ String(groupBy) }} = 'top_links',
+ link_id,
+ {{ String(groupBy) }} = 'top_urls',
+ url,
+ {{ String(groupBy) }} = 'referers',
+ referer,
+ {{ String(groupBy) }} = 'referer_urls',
+ splitByString('?', referer_url)[1],
+ {{ String(groupBy) }} = 'utm_sources',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_source')),
+ {{ String(groupBy) }} = 'utm_mediums',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_medium')),
+ {{ String(groupBy) }} = 'utm_campaigns',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_campaign')),
+ {{ String(groupBy) }} = 'utm_terms',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_term')),
+ {{ String(groupBy) }} = 'utm_contents',
+ decodeURLFormComponent(extractURLParameter(url, 'utm_content')),
+ {{ String(groupBy) }} = 'ref',
+ decodeURLFormComponent(extractURLParameter(url, 'ref')),
+ {{ String(groupBy) }} = 'countries',
+ country,
+ {{ String(groupBy) }} = 'regions',
+ CONCAT(country, '-', region) as region,
+ {{ String(groupBy) }} = 'cities',
+ city,
+ {{ String(groupBy) }} = 'continents',
+ continent,
+ {{ String(groupBy) }} = 'devices',
+ device,
+ {{ String(groupBy) }} = 'browsers',
+ browser,
+ {{ String(groupBy) }} = 'os',
+ os,
+ {{ String(groupBy) }} = 'triggers',
+ trigger,
+ link_id
+ ) AS groupByField,
+ {% if String(groupBy) == 'cities' %} country, CONCAT(country, '-', region) as region,
+ {% elif String(groupBy) == 'regions' %} country,
+ {% end %}
+ COUNT(*) AS sales,
+ SUM(amount) AS saleAmount
+ FROM dub_sale_events_mv
+ WHERE
+ groupByField != '' AND groupByField != 'Unknown'
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
+ {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id IN (SELECT link_id FROM workspace_links)
+ {% end %}
+ {% if defined(customerId) %} AND customer_id = {{ String(customerId) }} {% end %}
+ {% if defined(saleType) %} AND sale_type = {{ String(saleType) }} {% 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 %}
+ {% if defined(filters) %}
+ {% for item in JSON(filters, '[]') %}
+ {% if item.get('operand', '').startswith('metadata.') %}
+ {% set metadataKey = item.get('operand', '').split('.')[1] %}
+ {% set operator = item.get('operator', 'equals') %}
+ {% set value = item.get('value', '') %}
+ {% if operator == 'equals' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) = {{ value }}
+ {% elif operator == 'notEquals' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) != {{ value }}
+ {% elif operator == 'greaterThan' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) > {{ value }}
+ {% elif operator == 'lessThan' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) < {{ value }}
+ {% elif operator == 'greaterThanOrEqual' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) >= {{ value }}
+ {% elif operator == 'lessThanOrEqual' %}
+ AND JSONExtractString(metadata, {{ metadataKey }}) <= {{ value }}
+ {% end %}
+ {% end %}
+ {% end %}
+ {% end %}
+ GROUP BY
+ groupByField
+ {% if String(groupBy) == 'cities' %}, country, region
+ {% elif String(groupBy) == 'regions' %}, country
+ {% end %}
+ ORDER BY saleAmount DESC
+ LIMIT 5000
+
+
+
+NODE group_by_composite
+SQL >
+
+ %
+ SELECT
+ dce.groupByField as groupByField,
+ clicks,
+ leads,
+ sales,
+ saleAmount
+ {% if String(groupBy) == 'cities' %}, dce.country as country, dce.region as region{% end %}
+ {% if String(groupBy) == 'regions' %}, dce.country as country{% end %}
+ FROM
+ (
+ SELECT
+ dce.groupByField,
+ dce.clicks,
+ COALESCE(dle.leads, 0) AS leads,
+ COALESCE(dse.sales, 0) AS sales,
+ COALESCE(dse.saleAmount, 0) AS saleAmount
+ {% if String(groupBy) == 'cities' %}, dce.country, dce.region{% end %}
+ {% if String(groupBy) == 'regions' %}, dce.country{% end %}
+ FROM group_by_clicks dce
+ LEFT JOIN
+ group_by_leads dle ON dce.groupByField = dle.groupByField
+ {% if String(groupBy) == 'cities' %}
+ AND dce.country = dle.country AND dce.region = dle.region
+ {% end %}
+ {% if String(groupBy) == 'regions' %} AND dce.country = dle.country{% end %}
+ LEFT JOIN
+ group_by_sales dse ON dce.groupByField = dse.groupByField
+ {% if String(groupBy) == 'cities' %}
+ AND dce.country = dse.country AND dce.region = dse.region
+ {% end %}
+ {% if String(groupBy) == 'regions' %} AND dce.country = dse.country{% end %}
+ )
+ ORDER BY clicks DESC
+
+
+
+NODE endpoint
+SQL >
+
+ %
+ SELECT *
+ FROM
+ {% if eventType == 'clicks' %} group_by_clicks
+ {% elif eventType == 'leads' %} group_by_leads
+ {% elif eventType == 'sales' %}group_by_sales
+ {% elif eventType == 'composite' %}group_by_composite
+ {% else %} group_by_clicks
+ {% end %}
+
+
diff --git a/packages/tinybird/pipes/v3_group_by_link_metadata.pipe b/packages/tinybird/pipes/v3_group_by_link_metadata.pipe
new file mode 100644
index 0000000000..37c60d0727
--- /dev/null
+++ b/packages/tinybird/pipes/v3_group_by_link_metadata.pipe
@@ -0,0 +1,248 @@
+NODE workspace_links
+SQL >
+
+ %
+ SELECT
+ link_id,
+ -- here we split tag_ids out of the multiIf because arrayJoin explodes rows
+ if(
+ {{ String(groupBy) }} = 'top_tags',
+ arrayJoin(tag_ids),
+ multiIf(
+ {{ String(groupBy) }} = 'top_partners',
+ partner_id,
+ {{ String(groupBy) }} = 'top_folders',
+ folder_id,
+ partner_id
+ )
+ ) AS groupByField
+ FROM dub_links_metadata_latest FINAL
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'cl7pj5kq4006835rbjlt2ofka',
+ description="The unique ID for the workspace",
+ required=True,
+ )
+ }}
+ AND deleted == 0
+ AND multiIf(
+ {{ String(groupBy) }} = 'top_partners',
+ partner_id != '',
+ {{ String(groupBy) }} = 'top_folders',
+ folder_id != '',
+ {{ String(groupBy) }} = 'top_tags',
+ length(tag_ids) > 0,
+ partner_id != ''
+ )
+ {% 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(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
+ {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
+ {% elif defined(folderId) %} AND folder_id = {{ folderId }}
+ {% end %}
+ {% if defined(tagIds) %}
+ AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
+ {% end %}
+ {% if defined(root) %}
+ {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
+ {% end %}
+
+
+
+NODE group_by_link_metadata_clicks
+SQL >
+
+ %
+ SELECT wl.groupByField as groupByField, COUNT(*) AS clicks
+ FROM dub_click_events_mv AS ce
+ JOIN workspace_links AS wl ON ce.link_id = wl.link_id
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'cl7pj5kq4006835rbjlt2ofka',
+ description="The unique ID for the workspace",
+ required=True,
+ )
+ }}
+ {% if defined(linkIds) %} AND ce.link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND ce.link_id = {{ linkId }}
+ {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
+ GROUP BY wl.groupByField
+ ORDER BY clicks DESC
+ LIMIT 5000
+
+
+
+NODE group_by_link_metadata_leads
+SQL >
+
+ %
+ SELECT wl.groupByField as groupByField, COUNT(*) AS leads
+ FROM dub_lead_events_mv AS le
+ JOIN workspace_links AS wl ON le.link_id = wl.link_id
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'cl7pj5kq4006835rbjlt2ofka',
+ description="The unique ID for the workspace",
+ required=True,
+ )
+ }}
+ {% if defined(linkIds) %} AND le.link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND le.link_id = {{ linkId }}
+ {% end %}
+ {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
+ GROUP BY wl.groupByField
+ ORDER BY leads DESC
+ LIMIT 5000
+
+
+
+NODE group_by_link_metadata_sales
+SQL >
+
+ %
+ SELECT wl.groupByField as groupByField, COUNT(*) AS sales, SUM(amount) as saleAmount
+ FROM dub_sale_events_mv AS se
+ JOIN workspace_links AS wl ON se.link_id = wl.link_id
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'cl7pj5kq4006835rbjlt2ofka',
+ description="The unique ID for the workspace",
+ required=True,
+ )
+ }}
+ {% if defined(linkIds) %} AND se.link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND se.link_id = {{ linkId }}
+ {% end %}
+ {% if defined(customerId) %} AND customer_id = {{ String(customerId) }} {% end %}
+ {% if defined(saleType) %} AND sale_type = {{ String(saleType) }} {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
+ GROUP BY wl.groupByField
+ ORDER BY saleAmount DESC
+ LIMIT 5000
+
+
+
+NODE group_by_link_metadata_composite
+SQL >
+
+ %
+ SELECT c.groupByField as groupByField, c.clicks as clicks, l.leads as leads, s.sales as sales, s.saleAmount as saleAmount
+ FROM group_by_link_metadata_clicks AS c
+ LEFT JOIN group_by_link_metadata_leads AS l ON c.groupByField = l.groupByField
+ LEFT JOIN group_by_link_metadata_sales AS s ON c.groupByField = s.groupByField
+ ORDER BY saleAmount DESC
+
+
+
+NODE endpoint
+SQL >
+
+ %
+ SELECT *
+ FROM
+ {% if eventType == 'clicks' %} group_by_link_metadata_clicks
+ {% elif eventType == 'leads' %} group_by_link_metadata_leads
+ {% elif eventType == 'sales' %}group_by_link_metadata_sales
+ {% else %} group_by_link_metadata_clicks
+ {% end %}
+
+
diff --git a/packages/tinybird/pipes/v3_timeseries.pipe b/packages/tinybird/pipes/v3_timeseries.pipe
new file mode 100644
index 0000000000..78f71fbb1d
--- /dev/null
+++ b/packages/tinybird/pipes/v3_timeseries.pipe
@@ -0,0 +1,379 @@
+DESCRIPTION >
+ Timeseries data
+
+
+TAGS "Dub Endpoints"
+
+NODE month_intervals
+SQL >
+
+ %
+ WITH
+ toStartOfMonth(
+ toDateTime64({{ DateTime64(start, '2024-02-24 00:00:00.000') }}, 3),
+ {{ String(timezone, 'UTC') }}
+ ) AS start,
+ toStartOfMonth(
+ toDateTime64({{ DateTime64(end, '2024-05-23 00:00:00.000') }}, 3),
+ {{ String(timezone, 'UTC') }}
+ ) AS
+ end,
+ dateDiff('month', start, end) + 1 AS months_diff
+ SELECT
+ arrayJoin(
+ arrayMap(
+ x -> toDateTime64(start + toIntervalMonth(x), 3, {{ String(timezone, 'UTC') }}),
+ range(0, months_diff)
+ )
+ ) as interval
+
+
+
+NODE day_intervals
+SQL >
+
+ %
+ WITH
+ toStartOfDay(
+ toDateTime64({{ DateTime64(start, '2024-02-24 00:00:00.000') }}, 3),
+ {{ String(timezone, 'UTC') }}
+ ) AS start,
+ toStartOfDay(
+ toDateTime64({{ DateTime64(end, '2024-05-23 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), toUInt32(end + 86400),
+ 86400
+ )
+ )
+ ) as interval
+
+
+
+NODE hour_intervals
+SQL >
+
+ %
+ WITH
+ toStartOfHour(
+ toDateTime64({{ DateTime64(start, '2024-05-22 00:00:00.000') }}, 3),
+ {{ String(timezone, 'UTC') }}
+ ) AS start,
+ toStartOfHour(
+ toDateTime64({{ DateTime64(end, '2024-05-23 00:00:00.000') }}, 3),
+ {{ String(timezone, 'UTC') }}
+ ) AS
+ end
+ SELECT
+ arrayJoin(
+ arrayMap(x -> toDateTime64(x, 3), range(toUInt32(start), toUInt32(end + 3600), 3600)
+ )
+ ) as interval
+
+
+
+NODE workspace_links
+SQL >
+
+ %
+ SELECT link_id
+ FROM dub_links_metadata_latest FINAL
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'cl7pj5kq4006835rbjlt2ofka',
+ description="The unique ID for the workspace",
+ required=True,
+ )
+ }}
+ AND deleted == 0
+ {% if defined(programId) %} AND program_id = {{ programId }} {% end %}
+ {% if defined(partnerId) %} AND partner_id = {{ partnerId }} {% end %}
+ {% if defined(tenantId) %} AND tenant_id = {{ tenantId }} {% end %}
+ {% if defined(folderIds) %} AND folder_id IN {{ Array(folderIds, 'String') }}
+ {% elif defined(folderId) %} AND folder_id = {{ folderId }}
+ {% end %}
+ {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
+ {% if defined(tagIds) %}
+ AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != []
+ {% end %}
+ {% if defined(root) %}
+ {% if Boolean(root) == 1 %} AND key = '_root' {% else %} AND key != '_root' {% end %}
+ {% end %}
+
+
+
+NODE timeseries_clicks_data
+SQL >
+
+ %
+ SELECT
+ {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
+ {% elif granularity == "month" %}
+ toDateTime64(
+ toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
+ 3,
+ {{ String(timezone, 'UTC') }}
+ )
+ {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
+ {% end %} AS interval,
+ uniq(click_id) as clicks
+ FROM
+ {% if defined(customerId) %} dub_click_events_id
+ {% else %} dub_click_events_mv
+ {% end %}
+ {% if defined(customerId) %}
+ PREWHERE click_id IN (
+ SELECT DISTINCT click_id
+ FROM dub_lead_events_mv
+ WHERE customer_id = {{ String(customerId) }}
+ )
+ {% end %}
+ WHERE
+ true
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
+ {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id in (SELECT link_id from workspace_links)
+ {% 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(trigger) %} AND trigger = {{ trigger }} {% 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 %}
+ GROUP BY interval
+ ORDER BY interval
+
+
+
+NODE timeseries_clicks
+SQL >
+
+ %
+ SELECT formatDateTime(interval, '%FT%T.000%z') as groupByField, clicks
+ FROM
+ {% if granularity == "minute" %} minute_intervals
+ {% elif granularity == "hour" %} hour_intervals
+ {% elif granularity == "month" %} month_intervals
+ {% else %} day_intervals
+ {% end %}
+ LEFT JOIN timeseries_clicks_data USING interval
+
+
+
+NODE timeseries_leads_data
+SQL >
+
+ %
+ SELECT
+ {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
+ {% elif granularity == "month" %}
+ toDateTime64(
+ toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
+ 3,
+ {{ String(timezone, 'UTC') }}
+ )
+ {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
+ {% end %} AS interval,
+ uniq(*) as leads
+ FROM dub_lead_events_mv
+ WHERE
+ true
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
+ {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id in (SELECT link_id from workspace_links)
+ {% end %}
+ {% 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 %}
+ GROUP BY interval
+ ORDER BY interval
+
+
+
+NODE timeseries_leads
+SQL >
+
+ %
+ SELECT formatDateTime(interval, '%FT%T.000%z') as groupByField, leads
+ FROM
+ {% if granularity == "minute" %} minute_intervals
+ {% elif granularity == "hour" %} hour_intervals
+ {% elif granularity == "month" %} month_intervals
+ {% else %} day_intervals
+ {% end %}
+ LEFT JOIN timeseries_leads_data USING interval
+
+
+
+NODE timeseries_sales_data
+DESCRIPTION >
+ undefined
+
+SQL >
+
+ %
+ SELECT
+ {% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
+ {% elif granularity == "month" %}
+ toDateTime64(
+ toStartOfMonth(timestamp, {{ String(timezone, 'UTC') }}),
+ 3,
+ {{ String(timezone, 'UTC') }}
+ )
+ {% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
+ {% end %} AS interval,
+ uniq(*) as sales,
+ sum(amount) as amount
+ FROM dub_sale_events_mv
+ WHERE
+ true
+ {% if defined(workspaceId) %} AND workspace_id = {{ workspaceId }} {% end %}
+ {% if defined(linkIds) %} AND link_id IN {{ Array(linkIds, 'String') }}
+ {% elif defined(linkId) %} AND link_id = {{ linkId }}
+ {% elif defined(programId) or defined(partnerId) or defined(folderIds) or defined(
+ folderId
+ ) or defined(domain) or defined(tagIds) or defined(root) %}
+ AND link_id in (SELECT link_id from workspace_links)
+ {% end %}
+ {% if defined(customerId) %} AND customer_id = {{ String(customerId) }} {% end %}
+ {% if defined(saleType) %} AND sale_type = {{ String(saleType) }} {% 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 %}
+ GROUP BY interval
+ ORDER BY interval
+
+
+
+NODE timeseries_sales
+SQL >
+
+ %
+ SELECT formatDateTime(interval, '%FT%T.000%z') as groupByField, sales, amount, amount as saleAmount
+ FROM
+ {% if granularity == "minute" %} minute_intervals
+ {% elif granularity == "hour" %} hour_intervals
+ {% elif granularity == "month" %} month_intervals
+ {% else %} day_intervals
+ {% end %}
+ LEFT JOIN
+ {% if defined(saleType) %} timeseries_sales_data_with_type
+ {% else %} timeseries_sales_data
+ {% end %} USING interval
+
+
+
+NODE timeseries_composite
+SQL >
+
+ SELECT dce.groupByField AS groupByField, clicks, leads, sales, amount, saleAmount
+ FROM (SELECT groupByField, clicks FROM timeseries_clicks) AS dce
+ LEFT JOIN (SELECT * FROM timeseries_leads) AS dle ON dce.groupByField = dle.groupByField
+ LEFT JOIN (SELECT * FROM timeseries_sales) AS dse ON dce.groupByField = dse.groupByField
+
+
+
+NODE endpoint
+SQL >
+
+ %
+ SELECT *
+ FROM
+ {% if eventType == 'clicks' %} timeseries_clicks
+ {% elif eventType == 'leads' %} timeseries_leads
+ {% elif eventType == 'sales' %} timeseries_sales
+ {% elif eventType == 'composite' %} timeseries_composite
+ {% else %} timeseries_clicks
+ {% end %}
+
+
diff --git a/packages/tinybird/pipes/v3_usage.pipe b/packages/tinybird/pipes/v3_usage.pipe
new file mode 100644
index 0000000000..70855f30ee
--- /dev/null
+++ b/packages/tinybird/pipes/v3_usage.pipe
@@ -0,0 +1,138 @@
+DESCRIPTION >
+ Timeseries data
+
+
+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
+ )
+ )
+ ) as interval
+
+
+
+NODE usage_events_data
+SQL >
+
+ %
+ SELECT
+ toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
+ uniq(*) AS events
+ FROM
+ (
+ -- Click events
+ SELECT timestamp
+ FROM dub_click_events_mv
+ 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') }}
+
+ UNION ALL
+
+ -- Lead events
+ SELECT timestamp
+ FROM dub_lead_events_mv
+ 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') }}
+
+ UNION ALL
+
+ -- Sale events
+ SELECT timestamp
+ FROM dub_sale_events_mv
+ 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') }}
+ )
+ GROUP BY interval
+ ORDER BY interval
+
+
+
+NODE usage_events
+SQL >
+
+ %
+ SELECT formatDateTime(interval, '%FT%T.000%z') as date, events as value
+ FROM day_intervals
+ LEFT JOIN usage_events_data USING interval
+
+
+
+NODE usage_links_data
+DESCRIPTION >
+ undefined
+
+SQL >
+
+ %
+ SELECT
+ toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3) AS interval,
+ uniq(*) as links
+ FROM dub_links_metadata_latest FINAL
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'clrei1gld0002vs9mzn93p8ik',
+ description="The ID of the workspace",
+ required=True,
+ )
+ }}
+ AND created_at >= {{ DateTime(start, '2025-09-03 00:00:00') }}
+ AND created_at < {{ 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
+ ORDER BY interval
+
+
+
+NODE usage_links
+SQL >
+
+ %
+ SELECT formatDateTime(interval, '%FT%T.000%z') as date, 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 %}
+
+