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.

Create v1_continents.pipe

Steven Tey308507ae3f71
diff --git a/packages/tinybird/pipes/v1_continents.pipe b/packages/tinybird/pipes/v1_continents.pipe
new file mode 100644
index 0000000000..58c4a9a8c1
--- /dev/null
+++ b/packages/tinybird/pipes/v1_continents.pipe
@@ -0,0 +1,169 @@
+DESCRIPTION >
+ Top continents
+
+
+TOKEN "v1_continents_endpoint_read_1406" READ
+
+NODE workspace_links
+SQL >
+
+ %
+ SELECT link_id
+ from dub_links_metadata_latest FINAL
+ WHERE
+ workspace_id
+ = {{
+ String(
+ workspaceId,
+ 'ws_cl7pj5kq4006835rbjlt2ofka',
+ description="The ID of the workspace",
+ required=True,
+ )
+ }}
+ AND deleted == 0
+ {% if defined(domain) %} AND domain IN {{ Array(domain, 'String') }} {% end %}
+ {% if defined(tagId) %} AND has(tag_ids, {{ tagId }}) {% 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
+ dub_click_events_mv
+ {% if not defined(linkId) and defined(workspaceId) %}
+ PREWHERE link_id in (SELECT link_id from workspace_links)
+ {% end %}
+ WHERE
+ continent != ''
+ {% if defined(linkId) %}
+ AND link_id
+ = {{
+ String(
+ linkId,
+ 'clsdzhhlq0003vskwcaz6nm39',
+ description="The ID of the link",
+ )
+ }}
+ {% 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(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(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 defined(workspaceId) %}
+ PREWHERE link_id in (SELECT link_id from workspace_links)
+ {% end %}
+ WHERE
+ continent != ''
+ {% if defined(linkId) %}
+ AND link_id
+ = {{
+ String(
+ linkId,
+ 'clsdzhhlq0003vskwcaz6nm39',
+ description="The ID of the link",
+ )
+ }}
+ {% 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(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(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, COUNT(continent) as sales, sum(amount) as amount
+ FROM
+ dub_sale_events_mv
+ {% if not defined(linkId) and defined(workspaceId) %}
+ PREWHERE link_id in (SELECT link_id from workspace_links)
+ {% end %}
+ WHERE
+ continent != ''
+ {% if defined(linkId) %}
+ AND link_id
+ = {{
+ String(
+ linkId,
+ 'clsdzhhlq0003vskwcaz6nm39',
+ description="The ID of the link",
+ )
+ }}
+ {% 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(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(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 sales DESC
+
+
+
+NODE continents_composite
+SQL >
+
+ SELECT dce.continent AS continent, clicks, leads, sales, amount
+ 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 continents_sales) 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' %} continents_sales
+ {% else %} continents_composite
+ {% end %}
+
+