diff --git a/packages/tinybird/pipes/v2_browsers.pipe b/packages/tinybird/pipes/v2_browsers.pipe index 57496b1655..12ad08294f 100644 --- a/packages/tinybird/pipes/v2_browsers.pipe +++ b/packages/tinybird/pipes/v2_browsers.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_browsers_endpoint_read_1118" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT browser, COUNT(browser) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -53,6 +50,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -68,7 +70,7 @@ SQL > SELECT browser, COUNT(browser) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -84,6 +86,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -105,7 +112,7 @@ SQL > SELECT browser, COUNT(*) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -121,6 +128,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -153,4 +165,3 @@ SQL > {% else %} browsers_composite {% end %} - diff --git a/packages/tinybird/pipes/v2_cities.pipe b/packages/tinybird/pipes/v2_cities.pipe index 56a6d57320..1f338958d9 100644 --- a/packages/tinybird/pipes/v2_cities.pipe +++ b/packages/tinybird/pipes/v2_cities.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_cities_endpoint_read_6984" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT city, country, COUNT(city) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -53,6 +50,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -68,7 +70,7 @@ SQL > SELECT city, country, COUNT(city) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -84,6 +86,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -106,7 +113,7 @@ SQL > SELECT city, country, COUNT(city) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -122,6 +129,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_continents.pipe b/packages/tinybird/pipes/v2_continents.pipe index cca0d7bc39..020a434bbc 100644 --- a/packages/tinybird/pipes/v2_continents.pipe +++ b/packages/tinybird/pipes/v2_continents.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_continents_endpoint_read_0662" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT continent, COUNT(continent) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -62,6 +59,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -77,7 +79,7 @@ SQL > SELECT continent, COUNT(continent) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -102,6 +104,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -123,7 +130,7 @@ SQL > SELECT continent, COUNT(continent) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -148,6 +155,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_count.pipe b/packages/tinybird/pipes/v2_count.pipe index d1a7a4c306..87d1223ff9 100644 --- a/packages/tinybird/pipes/v2_count.pipe +++ b/packages/tinybird/pipes/v2_count.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_count_endpoint_read_0115" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT COUNT(*) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -53,6 +50,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -66,7 +68,7 @@ SQL > SELECT COUNT(*) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -82,6 +84,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -100,7 +107,7 @@ SQL > SELECT COUNT(*) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -116,6 +123,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -142,4 +154,3 @@ SQL > {% else %} count_composite {% end %} - diff --git a/packages/tinybird/pipes/v2_countries.pipe b/packages/tinybird/pipes/v2_countries.pipe index 35c0a81df1..fcdd2f2e60 100644 --- a/packages/tinybird/pipes/v2_countries.pipe +++ b/packages/tinybird/pipes/v2_countries.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_countries_endpoint_read_6734" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT country, COUNT(country) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -62,6 +59,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -77,7 +79,7 @@ SQL > SELECT country, COUNT(country) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -102,6 +104,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -123,7 +130,7 @@ SQL > SELECT country, COUNT(country) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -148,6 +155,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -180,4 +192,3 @@ SQL > {% else %} countries_composite {% end %} - diff --git a/packages/tinybird/pipes/v2_devices.pipe b/packages/tinybird/pipes/v2_devices.pipe index 8f043c4206..0c98d07c24 100644 --- a/packages/tinybird/pipes/v2_devices.pipe +++ b/packages/tinybird/pipes/v2_devices.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_devices_endpoint_read_4705" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT device, COUNT(device) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -53,6 +50,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -68,7 +70,7 @@ SQL > SELECT device, COUNT(device) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -84,6 +86,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -105,7 +112,7 @@ SQL > SELECT device, COUNT(device) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -121,6 +128,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_events.pipe b/packages/tinybird/pipes/v2_events.pipe index b3d017295a..644781ce05 100644 --- a/packages/tinybird/pipes/v2_events.pipe +++ b/packages/tinybird/pipes/v2_events.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_events_endpoint_read_6623" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ SQL > SELECT link_id, domain, key from dub_links_metadata_latest FINAL WHERE - workspace_id - = {{ - String( - workspaceId, - 'ws_cl7pj5kq4006835rbjlt2ofka', - description="The ID of the workspace", - required=True, - ) - }} - AND deleted == 0 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -44,7 +41,8 @@ SQL > timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }} AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }} {% if defined(linkId) %} AND link_id = {{ String(linkId) }} - {% elif defined(workspaceId) %} AND link_id IN (SELECT link_id FROM workspace_links) + {% 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 %} @@ -56,6 +54,21 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} + AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') + {% end %} + {% if defined(utm_medium) %} + AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') + {% end %} + {% if defined(utm_campaign) %} + AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') + {% end %} + {% if defined(utm_term) %} + AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') + {% end %} + {% if defined(utm_content) %} + AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') + {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %} LIMIT {{ Int32(limit, 100) }} @@ -77,7 +90,9 @@ SQL > timestamp >= {{ DateTime(start, '2024-06-01 00:00:00') }} AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }} {% if defined(linkId) %} AND link_id = {{ String(linkId) }} - {% elif defined(workspaceId) %} AND link_id IN (SELECT link_id FROM workspace_links) + {% elif defined(customerId) %} AND customer_id = {{ String(customerId) }} + {% 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 %} @@ -89,6 +104,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %} LIMIT {{ Int32(limit, 100) }} @@ -112,7 +132,8 @@ SQL > AND timestamp < {{ DateTime(end, '2024-06-07 00:00:00') }} {% if defined(linkId) %} AND link_id = {{ String(linkId) }} {% elif defined(customerId) %} AND customer_id = {{ String(customerId) }} - {% elif defined(workspaceId) %} AND link_id IN (SELECT link_id FROM workspace_links) + {% 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 %} @@ -124,6 +145,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} ORDER BY timestamp {% if order == 'asc' %} ASC {% else %} DESC {% end %} LIMIT {{ Int32(limit, 100) }} diff --git a/packages/tinybird/pipes/v2_os.pipe b/packages/tinybird/pipes/v2_os.pipe index 497f3e6762..577cae12a5 100644 --- a/packages/tinybird/pipes/v2_os.pipe +++ b/packages/tinybird/pipes/v2_os.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_os_endpoint_read_0301" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT os, COUNT(os) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -53,6 +50,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -68,7 +70,7 @@ SQL > SELECT os, COUNT(os) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -84,6 +86,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -105,7 +112,7 @@ SQL > SELECT os, COUNT(os) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -121,6 +128,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_referer_urls.pipe b/packages/tinybird/pipes/v2_referer_urls.pipe index 4a51739729..901bddfe80 100644 --- a/packages/tinybird/pipes/v2_referer_urls.pipe +++ b/packages/tinybird/pipes/v2_referer_urls.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_referer_urls_endpoint_read_1826" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -39,7 +36,7 @@ SQL > COUNT(*) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -55,6 +52,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -71,7 +73,7 @@ SQL > SELECT splitByString('?', referer_url)[1] as refererUrl, COUNT(referer_url) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -87,6 +89,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -109,7 +116,7 @@ SQL > 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 defined(workspaceId) %} + {% 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 @@ -125,6 +132,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_referers.pipe b/packages/tinybird/pipes/v2_referers.pipe index cd970a66f1..7ec6508dbd 100644 --- a/packages/tinybird/pipes/v2_referers.pipe +++ b/packages/tinybird/pipes/v2_referers.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_referers_endpoint_read_1177" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT referer, COUNT(referer) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -53,6 +50,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -68,7 +70,7 @@ SQL > SELECT referer, COUNT(referer) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -84,6 +86,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -105,7 +112,7 @@ SQL > SELECT referer, COUNT(referer) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -121,6 +128,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_regions.pipe b/packages/tinybird/pipes/v2_regions.pipe index d7266eafd5..da0324a63c 100644 --- a/packages/tinybird/pipes/v2_regions.pipe +++ b/packages/tinybird/pipes/v2_regions.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_regions_endpoint_read_9112" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -42,7 +39,7 @@ SQL > SELECT region, country, COUNT(region) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -59,6 +56,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -80,7 +82,7 @@ SQL > SELECT region, country, COUNT(region) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -97,6 +99,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -120,7 +127,7 @@ SQL > SELECT region, country, COUNT(city) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -137,6 +144,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_timeseries.pipe b/packages/tinybird/pipes/v2_timeseries.pipe index f91f83f618..cb4f69a50a 100644 --- a/packages/tinybird/pipes/v2_timeseries.pipe +++ b/packages/tinybird/pipes/v2_timeseries.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_timeseries_endpoint_read_8675" READ +TAGS "Dub Endpoints" + NODE month_intervals SQL > @@ -84,17 +86,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -120,7 +117,7 @@ SQL > uniq(*) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -136,6 +133,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(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') }} @@ -176,7 +178,7 @@ SQL > uniq(*) as leads FROM dub_lead_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -192,6 +194,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(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') }} @@ -236,7 +243,7 @@ SQL > sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -252,6 +259,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} AND timestamp >= {{ DateTime(start, '2024-04-25 00:00:00') }} AND timestamp < {{ DateTime(end, '2024-05-23 00:00:00') }} diff --git a/packages/tinybird/pipes/v2_top_links.pipe b/packages/tinybird/pipes/v2_top_links.pipe index 63d1ab7372..021435ad7b 100644 --- a/packages/tinybird/pipes/v2_top_links.pipe +++ b/packages/tinybird/pipes/v2_top_links.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_top_links_endpoint_read_5142" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT link_id as link, COUNT(*) AS clicks FROM dub_click_events_mv - {% if defined(workspaceId) %} + {% if defined(workspaceId) or defined(partnerId) or defined(programId) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %} WHERE @@ -53,6 +50,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -69,7 +71,7 @@ SQL > SELECT link_id as link, COUNT(*) AS leads FROM dub_lead_events_mv - {% if defined(workspaceId) %} + {% if defined(workspaceId) or defined(partnerId) or defined(programId) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %} WHERE @@ -85,6 +87,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -107,7 +114,7 @@ SQL > SELECT link_id as link, COUNT(*) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if defined(workspaceId) %} + {% if defined(workspaceId) or defined(partnerId) or defined(programId) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %} WHERE @@ -123,6 +130,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_top_urls.pipe b/packages/tinybird/pipes/v2_top_urls.pipe index 6a35843b1d..fd8a368937 100644 --- a/packages/tinybird/pipes/v2_top_urls.pipe +++ b/packages/tinybird/pipes/v2_top_urls.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_top_urls_endpoint_read_4482" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT url, COUNT(*) AS clicks FROM dub_click_events_mv - {% if defined(workspaceId) %} + {% if defined(workspaceId) or defined(partnerId) or defined(programId) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %} WHERE @@ -53,6 +50,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -69,7 +71,7 @@ SQL > SELECT url, COUNT(*) AS leads FROM dub_lead_events_mv - {% if defined(workspaceId) %} + {% if defined(workspaceId) or defined(partnerId) or defined(programId) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %} WHERE @@ -85,6 +87,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -107,7 +114,7 @@ SQL > SELECT url, COUNT(*) as sales, sum(amount) as amount FROM dub_sale_events_mv - {% if defined(workspaceId) %} + {% if defined(workspaceId) or defined(partnerId) or defined(programId) %} PREWHERE link_id in (SELECT link_id from workspace_links) {% end %} WHERE @@ -123,6 +130,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_triggers.pipe b/packages/tinybird/pipes/v2_triggers.pipe index e06c7be22f..7097375fcb 100644 --- a/packages/tinybird/pipes/v2_triggers.pipe +++ b/packages/tinybird/pipes/v2_triggers.pipe @@ -4,6 +4,8 @@ DESCRIPTION > TOKEN "v2_triggers_endpoint_read_4261" READ +TAGS "Dub Endpoints" + NODE workspace_links SQL > @@ -11,17 +13,12 @@ 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 + 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(tagIds) %} AND arrayIntersect(tag_ids, {{ Array(tagIds, 'String') }}) != [] {% end %} {% if defined(root) %} @@ -37,7 +34,7 @@ SQL > SELECT CASE WHEN qr = 0 THEN 'link' WHEN qr = 1 THEN 'qr' END as trigger, COUNT(qr) as clicks FROM dub_click_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -53,6 +50,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} @@ -68,7 +70,7 @@ 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 defined(workspaceId) %} + {% 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 @@ -84,6 +86,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} @@ -108,7 +115,7 @@ SQL > sum(amount) as amount FROM dub_sale_events_mv - {% if not defined(linkId) and defined(workspaceId) %} + {% 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 @@ -124,6 +131,11 @@ SQL > {% if defined(os) %} AND os = {{ os }} {% end %} {% if defined(referer) %} AND referer = {{ referer }} {% end %} {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} {% if defined(url) %} AND url = {{ url }} {% end %} {% if defined(start) %} AND timestamp >= {{ DateTime(start) }} {% end %} {% if defined(end) %} AND timestamp <= {{ DateTime(end) }} {% end %} diff --git a/packages/tinybird/pipes/v2_usage.pipe b/packages/tinybird/pipes/v2_usage.pipe index 8018834a08..8784169fa9 100644 --- a/packages/tinybird/pipes/v2_usage.pipe +++ b/packages/tinybird/pipes/v2_usage.pipe @@ -2,7 +2,7 @@ DESCRIPTION > Timeseries data -TOKEN "v2_usage_endpoint_read_1647" READ +TOKEN "v1_usage_endpoint_read_1647" READ NODE day_intervals SQL > @@ -46,7 +46,6 @@ SQL > required=True, ) }} - AND deleted = 0 diff --git a/packages/tinybird/pipes/v2_utms.pipe b/packages/tinybird/pipes/v2_utms.pipe new file mode 100644 index 0000000000..d713070bff --- /dev/null +++ b/packages/tinybird/pipes/v2_utms.pipe @@ -0,0 +1,194 @@ +TOKEN "v2_utms_endpoint_read_8196" READ + +NODE workspace_links +SQL > + + % + SELECT link_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(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 + extractURLParameter( + url, + {{ + String( + groupByUtmTag, + 'utm_source', + description="The UTM tag to retrieve data for", + required=True, + ) + }} + ) as utm + SELECT utm, 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(linkId) %} AND link_id = {{ String(linkId) }} {% end %} + {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %} + {% if defined(continent) %} AND continent = {{ continent }} {% end %} + {% if defined(country) %} AND country = {{ country }} {% end %} + {% if defined(region) %} AND region = {{ region }} {% end %} + {% if defined(city) %} AND city = {{ city }} {% end %} + {% if defined(device) %} AND device = {{ device }} {% end %} + {% if defined(browser) %} AND browser = {{ browser }} {% end %} + {% if defined(os) %} AND os = {{ os }} {% end %} + {% if defined(referer) %} AND referer = {{ referer }} {% end %} + {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} + {% if defined(url) %} AND url = {{ url }} {% end %} + {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} + {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} + GROUP BY utm + HAVING utm != '' + ORDER BY clicks DESC + + + +NODE utms_leads +SQL > + + % + WITH + 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 (defined(workspaceId) or defined(partnerId) or defined(programId)) %} + PREWHERE link_id in (SELECT link_id from workspace_links) + {% end %} + WHERE + url != '' + {% if defined(linkId) %} AND link_id = {{ String(linkId) }} {% end %} + {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %} + {% if defined(continent) %} AND continent = {{ continent }} {% end %} + {% if defined(country) %} AND country = {{ country }} {% end %} + {% if defined(region) %} AND region = {{ region }} {% end %} + {% if defined(city) %} AND city = {{ city }} {% end %} + {% if defined(device) %} AND device = {{ device }} {% end %} + {% if defined(browser) %} AND browser = {{ browser }} {% end %} + {% if defined(os) %} AND os = {{ os }} {% end %} + {% if defined(referer) %} AND referer = {{ referer }} {% end %} + {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} + {% if defined(url) %} AND url = {{ url }} {% end %} + {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} + {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} + GROUP BY utm + HAVING utm != '' + ORDER BY leads DESC + + + +NODE utms_sales +SQL > + + % + WITH + 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 (defined(workspaceId) or defined(partnerId) or defined(programId)) %} + PREWHERE link_id in (SELECT link_id from workspace_links) + {% end %} + WHERE + url != '' + {% if defined(linkId) %} AND link_id = {{ String(linkId) }} {% end %} + {% if defined(qr) %} AND qr = {{ Boolean(qr) }} {% end %} + {% if defined(continent) %} AND continent = {{ continent }} {% end %} + {% if defined(country) %} AND country = {{ country }} {% end %} + {% if defined(region) %} AND region = {{ region }} {% end %} + {% if defined(city) %} AND city = {{ city }} {% end %} + {% if defined(device) %} AND device = {{ device }} {% end %} + {% if defined(browser) %} AND browser = {{ browser }} {% end %} + {% if defined(os) %} AND os = {{ os }} {% end %} + {% if defined(referer) %} AND referer = {{ referer }} {% end %} + {% if defined(refererUrl) %} AND splitByString('?', referer_url)[1] = {{ refererUrl }} {% end %} + {% if defined(utm_source) %} AND url LIKE concat('%utm_source=', {{ String(utm_source) }}, '%') {% end %} + {% if defined(utm_medium) %} AND url LIKE concat('%utm_medium=', {{ String(utm_medium) }}, '%') {% end %} + {% if defined(utm_campaign) %} AND url LIKE concat('%utm_campaign=', {{ String(utm_campaign) }}, '%') {% end %} + {% if defined(utm_term) %} AND url LIKE concat('%utm_term=', {{ String(utm_term) }}, '%') {% end %} + {% if defined(utm_content) %} AND url LIKE concat('%utm_content=', {{ String(utm_content) }}, '%') {% end %} + {% if defined(url) %} AND url = {{ url }} {% end %} + {% if defined(start) %} AND timestamp >= {{ DateTime64(start) }} {% end %} + {% if defined(end) %} AND timestamp <= {{ DateTime64(end) }} {% end %} + GROUP BY utm + HAVING utm != '' + ORDER BY sales 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 utms_sales) 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' %} utms_sales + {% else %} utms_composite + {% end %} + +