The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
Create v2_partners.pipe
Kiran K0b07423caff4
diff --git a/packages/tinybird/pipes/v2_partners.pipe b/packages/tinybird/pipes/v2_partners.pipenew file mode 100644index 0000000000..5c9fb156b1--- /dev/null+++ b/packages/tinybird/pipes/v2_partners.pipe@@ -0,0 +1,174 @@+NODE workspace_links+SQL >++ %+ SELECT link_id, partner_id+ FROM+ {% if defined(isMegaFolder) and Boolean(isMegaFolder) == 1 %} dub_links_metadata_latest+ {% else %} dub_regular_links_metadata_latest+ {% end %} 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 %}+ {% 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 wl.partner_id, COUNT(*) AS clicks+ FROM dub_click_events_mv AS ce+ JOIN workspace_links AS wl ON ce.link_id = wl.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(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 wl.partner_id+ ORDER BY clicks DESC+ LIMIT 5000++NODE count_leads+SQL >++ %+ SELECT wl.partner_id, COUNT(*) AS leads+ FROM dub_lead_events AS le+ JOIN workspace_links AS wl ON le.link_id = wl.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 wl.partner_id+ ORDER BY leads DESC+ LIMIT 5000++NODE count_sales+SQL >++ %+ SELECT wl.partner_id, COUNT(*) AS sales+ FROM dub_sale_events AS se+ JOIN workspace_links AS wl ON se.link_id = wl.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 wl.partner_id+ ORDER BY sales DESC+ LIMIT 5000++NODE count_composite+SQL >++ SELECT c.partner_id as partner_id, clicks, leads, sales+ FROM count_clicks AS c+ LEFT JOIN count_leads AS l ON c.partner_id = l.partner_id+ LEFT JOIN count_sales AS s ON c.partner_id = s.partner_id+ ORDER BY c.clicks DESC++NODE endpoint+SQL >++ SELECT * FROM count_composite++