:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(marketing-analytics): count source-only and click-id pageviews as touchpoints (#86141)
Javier Bahamondes678274c294cd
diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambrindex b80dbc5d269b..b8ad2dce0f61 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor.ambr@@ -6,7 +6,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -63,20 +63,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'user signed up'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'user signed up'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'user signed up'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'user signed up'), greaterOrEquals(events.timestamp, toDateTime('2025-06-06')), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2025-06-06'), toIntervalSecond(15552000))), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))))+ or(and(equals(events.event, 'user signed up'), greaterOrEquals(events.timestamp, toDateTime('2025-06-06')), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2025-06-06'), toIntervalSecond(15552000))), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))))GROUP BYevents.person_idHAVING@@ -96,7 +96,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -153,20 +153,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'user signed up'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'user signed up'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'user signed up'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'user signed up'), greaterOrEquals(events.timestamp, toDateTime('2025-06-06')), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2025-06-06'), toIntervalSecond(15552000))), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))))+ or(and(equals(events.event, 'user signed up'), greaterOrEquals(events.timestamp, toDateTime('2025-06-06')), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2025-06-06'), toIntervalSecond(15552000))), lessOrEquals(events.timestamp, toDateTime('2025-07-07'))))GROUP BYevents.person_idHAVING@@ -186,7 +186,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -243,20 +243,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-20'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-20'), toIntervalSecond(7776000)))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-20'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-20'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVING@@ -276,7 +276,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -333,20 +333,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVING@@ -366,7 +366,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -423,20 +423,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'sign_up'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'sign_up'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'sign_up'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(event, 'sign_up'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000)))))+ or(and(equals(event, 'sign_up'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVING@@ -456,7 +456,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -513,20 +513,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'sign_up'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'sign_up'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'sign_up'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(event, 'sign_up'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01')), lessOrEquals(events.timestamp, toDateTime('2023-05-03'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-05-03'))))+ or(and(equals(event, 'sign_up'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01')), lessOrEquals(events.timestamp, toDateTime('2023-05-03'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-05-03'))))GROUP BYevents.person_idHAVING@@ -546,7 +546,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -603,20 +603,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'sign_up'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'sign_up'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'sign_up'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'sign_up'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000)))))+ or(and(equals(events.event, 'sign_up'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVING@@ -636,7 +636,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_1FROM(@@ -693,20 +693,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(or(equals(event, 'sign_up'), equals(event, 'activate_account')), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(or(equals(event, 'sign_up'), equals(event, 'activate_account')), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(or(equals(event, 'sign_up'), equals(event, 'activate_account')), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(or(equals(event, 'sign_up'), equals(event, 'activate_account')), greaterOrEquals(events.timestamp, toDateTime('2023-06-01')), lessOrEquals(events.timestamp, toDateTime('2023-06-02'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-06-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-06-02'))))+ or(and(or(equals(event, 'sign_up'), equals(event, 'activate_account')), greaterOrEquals(events.timestamp, toDateTime('2023-06-01')), lessOrEquals(events.timestamp, toDateTime('2023-06-02'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-06-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-06-02'))))GROUP BYevents.person_idHAVING@@ -726,7 +726,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,coalesce(sum(conversion_value), 0) AS conversion_0FROM(@@ -783,20 +783,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000)))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVING@@ -816,7 +816,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,coalesce(sum(conversion_value), 0) AS conversion_0FROM(@@ -899,20 +899,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))GROUP BYevents.person_idHAVING@@ -933,7 +933,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,coalesce(sum(conversion_value), 0) AS conversion_0FROM(@@ -1016,20 +1016,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))GROUP BYevents.person_idHAVING@@ -1050,7 +1050,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,coalesce(sum(conversion_value), 0) AS conversion_0FROM(@@ -1133,20 +1133,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))GROUP BYevents.person_idHAVING@@ -1167,7 +1167,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,coalesce(sum(conversion_value), 0) AS conversion_0FROM(@@ -1250,20 +1250,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-03-01')), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-03-01'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-03-31'))))GROUP BYevents.person_idHAVING@@ -1284,7 +1284,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -1341,20 +1341,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-04-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-04-01'), toIntervalSecond(7776000)))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-04-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-04-01'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVING@@ -1374,7 +1374,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -1431,20 +1431,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVING@@ -1464,7 +1464,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -1521,20 +1521,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-12-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-12-01'), toIntervalSecond(31536000)))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-12-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-12-01'), toIntervalSecond(31536000)))))GROUP BYevents.person_idHAVING@@ -1554,7 +1554,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -1611,20 +1611,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVING@@ -1644,7 +1644,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -1701,20 +1701,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVING@@ -1734,7 +1734,7 @@if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key,if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -1791,20 +1791,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))+ or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-05-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-05-01'), toIntervalSecond(7776000)))))GROUP BYevents.person_idHAVINGdiff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambrindex aeb008c84dd6..30c7f6fa406a 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goal_processor_refactor.ambr@@ -2,7 +2,7 @@# name: TestConversionGoalProcessorRefactor.test_snapshot_funnel_query_multi_touch_linear'''- SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key, if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source, coalesce(sum(conversion_value), 0) AS conversion_0+ SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key, if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source, coalesce(sum(conversion_value), 0) AS conversion_0FROM (SELECT person_id, if(notEmpty(conversion_campaign), conversion_campaign, if(notEmpty(fallback_campaign), fallback_campaign, '')) AS campaign_name, if(notEmpty(conversion_source), conversion_source, if(notEmpty(fallback_source), fallback_source, '')) AS source_name, if(notEmpty(conversion_medium), conversion_medium, if(notEmpty(fallback_medium), fallback_medium, '')) AS medium_name, if(notEmpty(conversion_content), conversion_content, if(notEmpty(fallback_content), fallback_content, '')) AS content_name, if(notEmpty(conversion_term), conversion_term, if(notEmpty(fallback_term), fallback_term, '')) AS term_name, if(notEmpty(conversion_referring_domain), conversion_referring_domain, if(notEmpty(fallback_referring_domain), fallback_referring_domain, '')) AS referring_domain_name, if(notEmpty(conversion_gclid), conversion_gclid, if(notEmpty(fallback_gclid), fallback_gclid, '')) AS gclid_name, if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name, if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name, '-' AS campaign_id, multiply(1, attribution_weight) AS conversion_value, attribution_weightFROM (@@ -10,9 +10,9 @@FROM (SELECT person_id, conversion_timestamps[i] AS conversion_time, conversion_math_values[i] AS conversion_math_value, conversion_campaigns[i] AS conversion_campaign, conversion_sources[i] AS conversion_source, conversion_mediums[i] AS conversion_medium, conversion_contents[i] AS conversion_content, conversion_terms[i] AS conversion_term, conversion_referring_domains[i] AS conversion_referring_domain, conversion_gclids[i] AS conversion_gclid, conversion_fbclids[i] AS conversion_fbclid, conversion_gad_sources[i] AS conversion_gad_source, arrayFilter(x -> and(lessOrEquals(x, conversion_timestamps[i]), greaterOrEquals(x, minus(conversion_timestamps[i], 7776000))), utm_timestamps) AS filtered_utm_timestamps, arrayMap(idx -> utm_campaigns[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_campaigns, arrayMap(idx -> utm_sources[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_sources, arrayMap(idx -> utm_mediums[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_mediums, arrayMap(idx -> utm_contents[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_contents, arrayMap(idx -> utm_terms[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_terms, arrayMap(idx -> utm_referring_domains[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_referring_domains, arrayMap(idx -> utm_gclids[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_gclids, arrayMap(idx -> utm_fbclids[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_fbclids, arrayMap(idx -> utm_gad_sources[idx], arrayFilter(j -> and(lessOrEquals(utm_timestamps[j], conversion_timestamps[i]), greaterOrEquals(utm_timestamps[j], minus(conversion_timestamps[i], 7776000))), arrayEnumerate(utm_timestamps))) AS filtered_utm_gad_sources, arrayMap(_x -> divide(1.0, greatest(toFloat(length(filtered_utm_timestamps)), 1.0)), filtered_utm_timestamps) AS attribution_weightsFROM (- SELECT events.person_id, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toUnixTimestamp(events.timestamp), 0))) AS conversion_timestamps, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toFloat(1), 0))) AS conversion_math_values, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_campaign, '')), ''))) AS conversion_campaigns, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_source, '')), ''))) AS conversion_sources, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_medium, '')), ''))) AS conversion_mediums, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_content, '')), ''))) AS conversion_contents, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_term, '')), ''))) AS conversion_terms, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.$referring_domain, '')), ''))) AS conversion_referring_domains, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources, arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ SELECT events.person_id, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toUnixTimestamp(events.timestamp), 0))) AS conversion_timestamps, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toFloat(1), 0))) AS conversion_math_values, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_campaign, '')), ''))) AS conversion_campaigns, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_source, '')), ''))) AS conversion_sources, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_medium, '')), ''))) AS conversion_mediums, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_content, '')), ''))) AS conversion_contents, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_term, '')), ''))) AS conversion_terms, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.$referring_domain, '')), ''))) AS conversion_referring_domains, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources, arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROM events- WHERE or(equals(events.event, 'purchase'), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))))+ WHERE or(equals(events.event, 'purchase'), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))))GROUP BY events.person_idHAVING greater(length(conversion_timestamps), 0)) ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i) ARRAY JOIN arrayEnumerate(attribution_weights) AS tp_idx)) AS attributed_conversionsGROUP BY campaign, id, source@@ -22,15 +22,15 @@# name: TestConversionGoalProcessorRefactor.test_snapshot_funnel_query_single_touch_default'''- SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key, if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source, count() AS conversion_0+ SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key, if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source, count() AS conversion_0FROM (SELECT person_id, if(notEmpty(conversion_campaign), conversion_campaign, if(notEmpty(fallback_campaign), fallback_campaign, '')) AS campaign_name, if(notEmpty(conversion_source), conversion_source, if(notEmpty(fallback_source), fallback_source, '')) AS source_name, if(notEmpty(conversion_medium), conversion_medium, if(notEmpty(fallback_medium), fallback_medium, '')) AS medium_name, if(notEmpty(conversion_content), conversion_content, if(notEmpty(fallback_content), fallback_content, '')) AS content_name, if(notEmpty(conversion_term), conversion_term, if(notEmpty(fallback_term), fallback_term, '')) AS term_name, if(notEmpty(conversion_referring_domain), conversion_referring_domain, if(notEmpty(fallback_referring_domain), fallback_referring_domain, '')) AS referring_domain_name, if(notEmpty(conversion_gclid), conversion_gclid, if(notEmpty(fallback_gclid), fallback_gclid, '')) AS gclid_name, if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name, if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name, '-' AS campaign_id, 1 AS conversion_valueFROM (SELECT person_id, conversion_timestamps[i] AS conversion_time, conversion_math_values[i] AS conversion_math_value, conversion_campaigns[i] AS conversion_campaign, conversion_sources[i] AS conversion_source, conversion_mediums[i] AS conversion_medium, conversion_contents[i] AS conversion_content, conversion_terms[i] AS conversion_term, conversion_referring_domains[i] AS conversion_referring_domain, conversion_gclids[i] AS conversion_gclid, conversion_fbclids[i] AS conversion_fbclid, conversion_gad_sources[i] AS conversion_gad_source, arrayMax(arrayFilter(x -> and(lessOrEquals(x, conversion_timestamps[i]), greaterOrEquals(x, minus(conversion_timestamps[i], 7776000))), utm_timestamps)) AS last_utm_timestamp, if(isNotNull(last_utm_timestamp), utm_campaigns[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_campaign, if(isNotNull(last_utm_timestamp), utm_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_source, if(isNotNull(last_utm_timestamp), utm_mediums[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_medium, if(isNotNull(last_utm_timestamp), utm_contents[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_content, if(isNotNull(last_utm_timestamp), utm_terms[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_term, if(isNotNull(last_utm_timestamp), utm_referring_domains[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_referring_domain, if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid, if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid, if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_sourceFROM (- SELECT events.person_id, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toUnixTimestamp(events.timestamp), 0))) AS conversion_timestamps, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toFloat(1), 0))) AS conversion_math_values, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_campaign, '')), ''))) AS conversion_campaigns, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_source, '')), ''))) AS conversion_sources, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_medium, '')), ''))) AS conversion_mediums, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_content, '')), ''))) AS conversion_contents, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_term, '')), ''))) AS conversion_terms, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.$referring_domain, '')), ''))) AS conversion_referring_domains, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources, arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ SELECT events.person_id, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toUnixTimestamp(events.timestamp), 0))) AS conversion_timestamps, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toFloat(1), 0))) AS conversion_math_values, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_campaign, '')), ''))) AS conversion_campaigns, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_source, '')), ''))) AS conversion_sources, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_medium, '')), ''))) AS conversion_mediums, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_content, '')), ''))) AS conversion_contents, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_term, '')), ''))) AS conversion_terms, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.$referring_domain, '')), ''))) AS conversion_referring_domains, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources, arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROM events- WHERE or(equals(events.event, 'purchase'), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))))+ WHERE or(equals(events.event, 'purchase'), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))))GROUP BY events.person_idHAVING greater(length(conversion_timestamps), 0)) ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversionsGROUP BY campaign, id, source@@ -40,15 +40,15 @@# name: TestConversionGoalProcessorRefactor.test_snapshot_funnel_query_with_property_filter'''- SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key, if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source, count() AS conversion_0+ SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS match_key, if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source, count() AS conversion_0FROM (SELECT person_id, if(notEmpty(conversion_campaign), conversion_campaign, if(notEmpty(fallback_campaign), fallback_campaign, '')) AS campaign_name, if(notEmpty(conversion_source), conversion_source, if(notEmpty(fallback_source), fallback_source, '')) AS source_name, if(notEmpty(conversion_medium), conversion_medium, if(notEmpty(fallback_medium), fallback_medium, '')) AS medium_name, if(notEmpty(conversion_content), conversion_content, if(notEmpty(fallback_content), fallback_content, '')) AS content_name, if(notEmpty(conversion_term), conversion_term, if(notEmpty(fallback_term), fallback_term, '')) AS term_name, if(notEmpty(conversion_referring_domain), conversion_referring_domain, if(notEmpty(fallback_referring_domain), fallback_referring_domain, '')) AS referring_domain_name, if(notEmpty(conversion_gclid), conversion_gclid, if(notEmpty(fallback_gclid), fallback_gclid, '')) AS gclid_name, if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name, if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name, '-' AS campaign_id, 1 AS conversion_valueFROM (SELECT person_id, conversion_timestamps[i] AS conversion_time, conversion_math_values[i] AS conversion_math_value, conversion_campaigns[i] AS conversion_campaign, conversion_sources[i] AS conversion_source, conversion_mediums[i] AS conversion_medium, conversion_contents[i] AS conversion_content, conversion_terms[i] AS conversion_term, conversion_referring_domains[i] AS conversion_referring_domain, conversion_gclids[i] AS conversion_gclid, conversion_fbclids[i] AS conversion_fbclid, conversion_gad_sources[i] AS conversion_gad_source, arrayMax(arrayFilter(x -> and(lessOrEquals(x, conversion_timestamps[i]), greaterOrEquals(x, minus(conversion_timestamps[i], 7776000))), utm_timestamps)) AS last_utm_timestamp, if(isNotNull(last_utm_timestamp), utm_campaigns[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_campaign, if(isNotNull(last_utm_timestamp), utm_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_source, if(isNotNull(last_utm_timestamp), utm_mediums[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_medium, if(isNotNull(last_utm_timestamp), utm_contents[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_content, if(isNotNull(last_utm_timestamp), utm_terms[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_term, if(isNotNull(last_utm_timestamp), utm_referring_domains[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_referring_domain, if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid, if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid, if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_sourceFROM (- SELECT events.person_id, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toUnixTimestamp(events.timestamp), 0))) AS conversion_timestamps, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toFloat(1), 0))) AS conversion_math_values, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_campaign, '')), ''))) AS conversion_campaigns, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_source, '')), ''))) AS conversion_sources, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_medium, '')), ''))) AS conversion_mediums, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_content, '')), ''))) AS conversion_contents, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_term, '')), ''))) AS conversion_terms, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.$referring_domain, '')), ''))) AS conversion_referring_domains, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources, arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ SELECT events.person_id, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toUnixTimestamp(events.timestamp), 0))) AS conversion_timestamps, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toFloat(1), 0))) AS conversion_math_values, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_campaign, '')), ''))) AS conversion_campaigns, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_source, '')), ''))) AS conversion_sources, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_medium, '')), ''))) AS conversion_mediums, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_content, '')), ''))) AS conversion_contents, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_term, '')), ''))) AS conversion_terms, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.$referring_domain, '')), ''))) AS conversion_referring_domains, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources, arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROM events- WHERE and(or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000))))), equals(properties.plan, 'pro'))+ WHERE and(or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01'), toIntervalSecond(7776000))))), equals(properties.plan, 'pro'))GROUP BY events.person_idHAVING greater(length(conversion_timestamps), 0)) ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversionsGROUP BY campaign, id, sourcediff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goals_aggregator.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goals_aggregator.ambrindex 0e790e34d84d..8ce548afdff1 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goals_aggregator.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_conversion_goals_aggregator.ambr@@ -13,7 +13,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -175,7 +175,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -337,7 +337,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -499,7 +499,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -663,7 +663,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0,0 AS conversion_1,0 AS conversion_2@@ -810,7 +810,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,0 AS conversion_0,count() AS conversion_1,0 AS conversion_2@@ -957,7 +957,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,0 AS conversion_0,0 AS conversion_1,count() AS conversion_2@@ -1122,7 +1122,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0,0 AS conversion_1FROM@@ -1268,7 +1268,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,0 AS conversion_0,count() AS conversion_1FROMdiff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_aggregated_query_runner.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_aggregated_query_runner.ambrindex c73dbc932472..6fcd70322a49 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_aggregated_query_runner.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_aggregated_query_runner.ambr@@ -8,15 +8,15 @@GROUP BY campaign, id, source), ucg AS (SELECT conv.campaign AS campaign, conv.id AS id, conv.source AS source, conv.campaign AS match_key, sum(conv.conversion_0) AS conversion_0FROM (- SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source, count() AS conversion_0+ SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source, count() AS conversion_0FROM (SELECT person_id, if(notEmpty(conversion_campaign), conversion_campaign, if(notEmpty(fallback_campaign), fallback_campaign, '')) AS campaign_name, if(notEmpty(conversion_source), conversion_source, if(notEmpty(fallback_source), fallback_source, '')) AS source_name, if(notEmpty(conversion_medium), conversion_medium, if(notEmpty(fallback_medium), fallback_medium, '')) AS medium_name, if(notEmpty(conversion_content), conversion_content, if(notEmpty(fallback_content), fallback_content, '')) AS content_name, if(notEmpty(conversion_term), conversion_term, if(notEmpty(fallback_term), fallback_term, '')) AS term_name, if(notEmpty(conversion_referring_domain), conversion_referring_domain, if(notEmpty(fallback_referring_domain), fallback_referring_domain, '')) AS referring_domain_name, if(notEmpty(conversion_gclid), conversion_gclid, if(notEmpty(fallback_gclid), fallback_gclid, '')) AS gclid_name, if(notEmpty(conversion_fbclid), conversion_fbclid, if(notEmpty(fallback_fbclid), fallback_fbclid, '')) AS fbclid_name, if(notEmpty(conversion_gad_source), conversion_gad_source, if(notEmpty(fallback_gad_source), fallback_gad_source, '')) AS gad_source_name, '-' AS campaign_id, 1 AS conversion_valueFROM (SELECT person_id, conversion_timestamps[i] AS conversion_time, conversion_math_values[i] AS conversion_math_value, conversion_campaigns[i] AS conversion_campaign, conversion_sources[i] AS conversion_source, conversion_mediums[i] AS conversion_medium, conversion_contents[i] AS conversion_content, conversion_terms[i] AS conversion_term, conversion_referring_domains[i] AS conversion_referring_domain, conversion_gclids[i] AS conversion_gclid, conversion_fbclids[i] AS conversion_fbclid, conversion_gad_sources[i] AS conversion_gad_source, arrayMax(arrayFilter(x -> and(lessOrEquals(x, conversion_timestamps[i]), greaterOrEquals(x, minus(conversion_timestamps[i], 7776000))), utm_timestamps)) AS last_utm_timestamp, if(isNotNull(last_utm_timestamp), utm_campaigns[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_campaign, if(isNotNull(last_utm_timestamp), utm_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_source, if(isNotNull(last_utm_timestamp), utm_mediums[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_medium, if(isNotNull(last_utm_timestamp), utm_contents[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_content, if(isNotNull(last_utm_timestamp), utm_terms[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_term, if(isNotNull(last_utm_timestamp), utm_referring_domains[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_referring_domain, if(isNotNull(last_utm_timestamp), utm_gclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gclid, if(isNotNull(last_utm_timestamp), utm_fbclids[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_fbclid, if(isNotNull(last_utm_timestamp), utm_gad_sources[indexOf(utm_timestamps, last_utm_timestamp)], '') AS fallback_gad_sourceFROM (- SELECT events.person_id, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toUnixTimestamp(events.timestamp), 0))) AS conversion_timestamps, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toFloat(1), 0))) AS conversion_math_values, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_campaign, '')), ''))) AS conversion_campaigns, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_source, '')), ''))) AS conversion_sources, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_medium, '')), ''))) AS conversion_mediums, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_content, '')), ''))) AS conversion_contents, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_term, '')), ''))) AS conversion_terms, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.$referring_domain, '')), ''))) AS conversion_referring_domains, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources, arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ SELECT events.person_id, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toUnixTimestamp(events.timestamp), 0))) AS conversion_timestamps, arrayFilter(x -> greater(x, 0), groupArray(if(equals(events.event, 'purchase'), toFloat(1), 0))) AS conversion_math_values, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_campaign, '')), ''))) AS conversion_campaigns, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_source, '')), ''))) AS conversion_sources, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_medium, '')), ''))) AS conversion_mediums, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_content, '')), ''))) AS conversion_contents, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.utm_term, '')), ''))) AS conversion_terms, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.$referring_domain, '')), ''))) AS conversion_referring_domains, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids, arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(events.event, 'purchase'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources, arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids, arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROM events- WHERE or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2023-01-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-01-31 23:59:59'))))+ WHERE or(and(equals(events.event, 'purchase'), greaterOrEquals(events.timestamp, toDateTime('2023-01-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2023-01-31 23:59:59'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2023-01-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2023-01-31 23:59:59'))))GROUP BY events.person_idHAVING greater(length(conversion_timestamps), 0)) ARRAY JOIN arrayEnumerate(conversion_timestamps) AS i)) AS attributed_conversionsGROUP BY campaign, id, source) AS convdiff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_business.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_business.ambrindex abda04309a85..867879a0bfe0 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_business.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_business.ambr@@ -100,7 +100,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -157,20 +157,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-01-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-01-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))))+ or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-01-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-01-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))))GROUP BYevents.person_idHAVINGdiff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_compare.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_compare.ambrindex 2f7409d01b9f..d346408cf68f 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_compare.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_analytics_table_query_runner_compare.ambr@@ -135,7 +135,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -192,20 +192,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-11-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-11-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))))+ or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-11-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-11-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))))GROUP BYevents.person_idHAVING@@ -299,7 +299,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -356,20 +356,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-09-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-09-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))))+ or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-09-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-09-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))))GROUP BYevents.person_idHAVING@@ -494,7 +494,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -551,20 +551,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-11-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-11-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))))+ or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-11-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-11-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-12-31 23:59:59'))))GROUP BYevents.person_idHAVING@@ -658,7 +658,7 @@SELECTif(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,if(notEmpty(campaign_id), campaign_id, '-') AS id,- if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, 'organic'))))) AS source,+ if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,count() AS conversion_0FROM(@@ -715,20 +715,20 @@arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gclid, '')), ''))) AS conversion_gclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.fbclid, '')), ''))) AS conversion_fbclids,arrayFilter(x -> notEmpty(toString(x)), groupArray(if(equals(event, 'test_event'), toString(ifNull(events.properties.gad_source, '')), ''))) AS conversion_gad_sources,- arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,- arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, '')))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sources+ arrayFilter(x -> greater(x, 0), groupArray(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0))) AS utm_timestamps,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_campaign, '')), ''))))) AS utm_campaigns,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_source, '')), ''))))) AS utm_sources,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_medium, '')), ''))))) AS utm_mediums,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_content, '')), ''))))) AS utm_contents,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.utm_term, '')), ''))))) AS utm_terms,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.$referring_domain, '')), ''))))) AS utm_referring_domains,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gclid, '')), ''))))) AS utm_gclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.fbclid, '')), ''))))) AS utm_fbclids,+ arrayMap(_tp -> _tp.2, arrayFilter(_tp -> greater(_tp.1, 0), groupArray(tuple(if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toUnixTimestamp(events.timestamp), 0), if(and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, ''))))), toString(ifNull(events.properties.gad_source, '')), ''))))) AS utm_gad_sourcesFROMeventsWHERE- or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-09-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))), and(equals(events.event, '$pageview'), notEmpty(toString(ifNull(events.properties.utm_campaign, ''))), notEmpty(toString(ifNull(events.properties.utm_source, ''))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-09-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))))+ or(and(equals(event, 'test_event'), greaterOrEquals(events.timestamp, toDateTime('2024-09-01 00:00:00')), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))), and(equals(events.event, '$pageview'), or(notEmpty(toString(ifNull(events.properties.utm_source, ''))), notEmpty(toString(ifNull(events.properties.gclid, ''))), notEmpty(toString(ifNull(events.properties.gad_source, '')))), greaterOrEquals(events.timestamp, minus(toDateTime('2024-09-01 00:00:00'), toIntervalSecond(7776000))), lessOrEquals(events.timestamp, toDateTime('2024-10-31 23:59:59'))))GROUP BYevents.person_idHAVINGdiff --git a/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py b/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.pyindex 3d246d962518..181a4f77647f 100644--- a/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py+++ b/products/marketing_analytics/backend/hogql_queries/conversion_goal_processor.py@@ -26,6 +26,7 @@ from posthog.hogql.database.schema.exchange_rate import convert_currency_callfrom posthog.hogql.modifiers import create_default_modifiers_for_teamfrom posthog.hogql.timings import HogQLTimings+from posthog.dataclasses import frozenfrom posthog.models import PropertyDefinition, Team, Userfrom products.access_control.backend.property_access_control import get_restricted_property_names@@ -60,7 +61,8 @@ PRECOMPUTE_TTL_SECONDS = {"0d": 15 * 60, "1d": 60 * 60, "7d": 24 * 60 * 60, "deflogger = structlog.get_logger(__name__)-@dataclass+# kw_only off: the TRACKED_FIELDS table below reads as a table, one positional row per field.+@frozen(kw_only=False)class TrackedField:"""A field tracked through the conversion attribution pipeline for channel classification."""@@ -68,6 +70,8 @@ class TrackedField:event_property: str # Default event property name (e.g., "utm_campaign", "$referring_domain")schema_map_key: str | None = None # Key in schema_map for DataWarehouse custom mappingdefault_value: str = "" # Default when field is empty/missing in organic context+ click_identifier: bool = False # Ad click id (gclid, fbclid, …): on its own it marks a paid touchpoint+ click_id_source: str = "" # Ad network this click id names when the pageview carries no utm_source@propertydef conversion_array(self) -> str:@@ -91,7 +95,7 @@ class TrackedField:# Fields tracked through the 4-stage attribution pipeline.-# The first two (campaign, source) are also used as the pageview UTM filter criteria.+# source (plus the click identifiers) gates whether a pageview counts as a paid touchpoint.TRACKED_FIELDS: list[TrackedField] = [TrackedField("campaign", "utm_campaign", "utm_campaign_name"),TrackedField("source", "utm_source", "utm_source_name"),@@ -102,11 +106,52 @@ TRACKED_FIELDS: list[TrackedField] = [# Unprefixed: these are the names the SDK writes on the event (see CAMPAIGN_PROPERTIES# in posthog/taxonomy/taxonomy.py). The `$initial_*` forms channel_type reads are# person-scoped copies derived from these, and `$gclid` exists nowhere at all.- TrackedField("gclid", "gclid"),+ TrackedField("gclid", "gclid", click_identifier=True, click_id_source="google"),+ # Not a click identifier: Facebook appends fbclid to every outbound link, organic posts+ # included, so it names the network without saying the click was paid. `channel_type`'s paid+ # branch and `attribution_health`'s paid counter both exclude it for that reason; treating it+ # as evidence here would admit organic Facebook traffic as a paid touchpoint and then have+ # channel_type call the same row organic.TrackedField("fbclid", "fbclid"),- TrackedField("gad_source", "gad_source"),+ TrackedField("gad_source", "gad_source", click_identifier=True, click_id_source="google"),]+# Property names of the ad click identifiers. A pageview that carries one of these is a paid+# touchpoint even with no utm_source. Deliberately only the Google Ads pair — see fbclid above.+# referring_domain is out too: it defaults to $direct on organic traffic, so it is not evidence+# of an ad click.+CLICK_ID_PROPERTIES: list[str] = [f.event_property for f in TRACKED_FIELDS if f.click_identifier]++CLICK_ID_FIELDS: list[TrackedField] = [f for f in TRACKED_FIELDS if f.click_identifier]+++def build_pageview_touchpoint_condition(source_field: str) -> ast.Expr:+ """A pageview is a paid touchpoint when it carries utm_source or any ad click identifier.++ utm_campaign is optional — a source alone is enough. The precompute path+ (build_touchpoints_precompute_query) and the fallback path (_build_pageview_event_filter,+ _build_utm_pageview_array) must all gate on this same rule, or the two disagree and one+ window's touchpoints go missing.+ """++ def not_empty(event_property: str) -> ast.Expr:+ return ast.Call(+ name="notEmpty",+ args=[+ ast.Call(+ name="toString",+ args=[+ ast.Call(+ name="ifNull",+ args=[ast.Field(chain=["events", "properties", event_property]), ast.Constant(value="")],+ )+ ],+ )+ ],+ )++ return ast.Or(exprs=[not_empty(source_field), *[not_empty(p) for p in CLICK_ID_PROPERTIES]])+def build_touchpoints_precompute_query() -> ast.SelectQuery:"""Config-agnostic touchpoint precompute: one row per UTM-tagged pageview, independent of any@@ -134,8 +179,8 @@ def build_touchpoints_precompute_query() -> ast.SelectQuery:for tracked in TRACKED_FIELDS:select_columns.append(ast.Alias(alias=tracked.attributed_name, expr=_prop_to_string(tracked.event_property)))- # Mirror the fallback's touchpoint definition (_build_pageview_event_filter): a UTM pageview- # requires BOTH campaign and source non-empty — keep these in lockstep.+ # Touchpoint definition shared with the fallback path (build_pageview_touchpoint_condition):+ # utm_source or any click id, campaign optional — keep the two paths in lockstep.return ast.SelectQuery(select=select_columns,select_from=ast.JoinExpr(table=ast.Field(chain=["events"])),@@ -156,8 +201,7 @@ def build_touchpoints_precompute_query() -> ast.SelectQuery:op=ast.CompareOperationOp.LtEq,right=ast.Placeholder(expr=ast.Field(chain=["time_window_max"])),),- ast.Call(name="notEmpty", args=[_prop_to_string("utm_campaign")]),- ast.Call(name="notEmpty", args=[_prop_to_string("utm_source")]),+ build_pageview_touchpoint_condition("utm_source"),]),)@@ -968,13 +1012,10 @@ class ConversionGoalProcessor:) -> ast.SelectQuery:"""Build subquery that collects arrays of conversion and UTM data per person"""resolved = {f.name: self._resolve_field_name(f) for f in TRACKED_FIELDS}- utm_campaign_field = resolved["campaign"]utm_source_field = resolved["source"]# Build WHERE clause with clean separation of concerns- final_where = self._build_comprehensive_where_clause(- conversion_event, where_conditions, utm_campaign_field, utm_source_field- )+ final_where = self._build_comprehensive_where_clause(conversion_event, where_conditions, utm_source_field)# Build SELECT columnsselect_columns: list[ast.Expr] = [@@ -990,14 +1031,10 @@ class ConversionGoalProcessor:)# Add pageview UTM arrays (timestamps + each tracked field)- select_columns.append(- self._build_utm_pageview_array("utm_timestamps", utm_campaign_field, utm_source_field, "timestamp")- )+ select_columns.append(self._build_utm_pageview_array("utm_timestamps", utm_source_field, "timestamp"))for field in TRACKED_FIELDS:select_columns.append(- self._build_utm_pageview_array(- field.utm_array, utm_campaign_field, utm_source_field, resolved[field.name]- )+ self._build_utm_pageview_array(field.utm_array, utm_source_field, resolved[field.name]))# Build HAVING clause@@ -1019,7 +1056,6 @@ class ConversionGoalProcessor:self,conversion_event: Optional[str],input_conditions: list[ast.Expr],- utm_campaign_field: str,utm_source_field: str,) -> ast.Expr:"""Build complete WHERE clause with proper condition separation"""@@ -1039,20 +1075,20 @@ class ConversionGoalProcessor:if conversion_event == "$pageview":# For pageview conversions, we only need attribution pageviews (with UTM data).# No need for separate conversion filter since conversion IS the pageview.- event_filter = self._build_pageview_event_filter(date_conditions, utm_campaign_field, utm_source_field)+ event_filter = self._build_pageview_event_filter(date_conditions, utm_source_field)else:# For non-pageview conversions, use both filters (no overlap possible)event_filter = ast.Or(exprs=[self._build_conversion_event_filter(conversion_event, date_conditions),- self._build_pageview_event_filter(date_conditions, utm_campaign_field, utm_source_field),+ self._build_pageview_event_filter(date_conditions, utm_source_field),])elif self.goal.kind == "ActionsNode" and self.config.attribution_window_days > 0:# For ActionsNode with attribution, we need both action events and pageview eventsaction_conditions = self.get_base_where_conditions()action_filter = self._build_action_event_filter(action_conditions, date_conditions)- pageview_filter = self._build_pageview_event_filter(date_conditions, utm_campaign_field, utm_source_field)+ pageview_filter = self._build_pageview_event_filter(date_conditions, utm_source_field)event_filter = ast.Or(exprs=[action_filter, pageview_filter])else:# For general queries, apply date conditions to all events@@ -1107,9 +1143,7 @@ class ConversionGoalProcessor:return ast.And(exprs=conditions)- def _build_pageview_event_filter(- self, date_conditions: list[ast.Expr], utm_campaign_field: str, utm_source_field: str- ) -> ast.Expr:+ def _build_pageview_event_filter(self, date_conditions: list[ast.Expr], utm_source_field: str) -> ast.Expr:"""Build filter for pageview events with UTM requirements and extended date range"""conditions = [ast.CompareOperation(@@ -1117,8 +1151,7 @@ class ConversionGoalProcessor:op=ast.CompareOperationOp.Eq,right=ast.Constant(value="$pageview"),),- self._build_utm_not_empty_condition(utm_campaign_field),- self._build_utm_not_empty_condition(utm_source_field),+ build_pageview_touchpoint_condition(utm_source_field),]# Apply extended date conditions for pageviews (attribution window)@@ -1169,26 +1202,6 @@ class ConversionGoalProcessor:return ast.And(exprs=conditions) if conditions else ast.Constant(value=True)- def _build_utm_not_empty_condition(self, utm_field: str) -> ast.Call:- """Build UTM not empty condition"""- return ast.Call(- name="notEmpty",- args=[- ast.Call(- name="toString",- args=[- ast.Call(- name="ifNull",- args=[- ast.Field(chain=["events", "properties", utm_field]),- ast.Constant(value=""),- ],- )- ],- )- ],- )-def _build_conversion_timestamps_array(self, conversion_event: Optional[str]) -> ast.Alias:"""Build conversion timestamps array.@@ -1337,19 +1350,17 @@ class ConversionGoalProcessor:),)- def _build_utm_pageview_array(- self, alias: str, utm_campaign_field: str, utm_source_field: str, return_field: str- ) -> ast.Alias:+ def _build_utm_pageview_array(self, alias: str, utm_source_field: str, return_field: str) -> ast.Alias:"""Build array for UTM pageview data.Every array this builds is read positionally against `utm_timestamps`(`_build_filtered_utm_field_expr`, `_build_single_touch_fallback_expr`), so all of them mustkeep exactly one element per UTM pageview, in the same order. That means **every** array isfiltered by the same predicate — the timestamp being non-zero, i.e. the row qualified — and- never by whether its own value happens to be set. `utm_campaign` and `utm_source` are the- touchpoint qualifier, but the other seven tracked fields are routinely empty on a qualifying- pageview, and dropping those positions used to shift every later element: touchpoint i's- timestamp paired with touchpoint j's value.+ never by whether its own value happens to be set. `utm_source` or an ad click id is the+ touchpoint qualifier; every other tracked field, `utm_campaign` included, is routinely empty+ on a qualifying pageview, and dropping those positions used to shift every later element:+ touchpoint i's timestamp paired with touchpoint j's value."""pageview_with_utm = ast.And(exprs=[@@ -1358,8 +1369,7 @@ class ConversionGoalProcessor:op=ast.CompareOperationOp.Eq,right=ast.Constant(value="$pageview"),),- self._build_utm_not_empty_condition(utm_campaign_field),- self._build_utm_not_empty_condition(utm_source_field),+ build_pageview_touchpoint_condition(utm_source_field),])timestamp_expr = ast.Call(name="toUnixTimestamp", args=[ast.Field(chain=["events", "timestamp"])])@@ -1921,9 +1931,11 @@ class ConversionGoalProcessor:field_exprs: dict[str, ast.Expr] = {}for field in TRACKED_FIELDS:default = organic_overrides.get(field.name, field.default_value)- field_expr: ast.Expr = self._build_organic_default_expr(field.attributed_name, default)+ field_expr: ast.Exprif field.name == "source":- field_expr = self._normalize_source_field(field_expr)+ field_expr = self._normalize_source_field(self._build_source_expr(field, default))+ else:+ field_expr = self._build_organic_default_expr(field.attributed_name, default)field_exprs[field.name] = field_exprcampaign_expr = field_exprs["campaign"]@@ -2019,6 +2031,30 @@ class ConversionGoalProcessor:],)+ def _build_source_expr(self, source: TrackedField, default_value: str) -> ast.Expr:+ """Attributed source, naming the ad network when only a click id identifies it.++ A pageview qualifies as a touchpoint on a click id alone, and channel_type reads those+ same click ids to classify the row as paid. Falling straight through to the organic+ default would put an organic source next to a paid channel on one row, and would leave+ the conversion in the organic bucket on the campaign and source levels.+ """+ source_field = ast.Field(chain=[source.attributed_name])+ fallback: ast.Expr = ast.Constant(value=default_value)+ for field in reversed(CLICK_ID_FIELDS):+ fallback = ast.Call(+ name="if",+ args=[+ ast.Call(name="notEmpty", args=[ast.Field(chain=[field.attributed_name])]),+ ast.Constant(value=field.click_id_source),+ fallback,+ ],+ )+ return ast.Call(+ name="if",+ args=[ast.Call(name="notEmpty", args=[source_field]), source_field, fallback],+ )+def _apply_organic_default(self, expr: ast.Expr, default_value: str) -> ast.Call:"""Fall back to the organic default when the value is NULL or empty, matching theevents attribution path so all goal kinds classify unattributed conversions alike."""diff --git a/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py b/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.pyindex 9292c2437f2a..c949b8a9ba5b 100644--- a/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py+++ b/products/marketing_analytics/backend/hogql_queries/test_conversion_goal_processor.py@@ -3558,8 +3558,10 @@ class TestConversionGoalProcessor(ClickhouseTestMixin, BaseTest):- May 01: Ad with missing campaign but valid source- Jun 01: Purchase- Expected: Should handle gracefully with appropriate fallbacks- Tests data quality handling for incomplete UTM parameters+ Expected: utm_source alone marks a paid touchpoint (campaign optional). The May 01+ source-only pageview is the last touch before the purchase, so the conversion is+ credited to paid (facebook → meta). The Apr 01 pageview has a campaign but no source+ and no click id, so it is not a touchpoint."""with freeze_time("2023-03-01"):_create_person(distinct_ids=["malformed_utm_user"], team=self.team)@@ -3622,10 +3624,110 @@ class TestConversionGoalProcessor(ClickhouseTestMixin, BaseTest):first_result = response.results[0]# Schema: [0]=match_key, [1]=campaign, [2]=id, [3]=source, [4]=conversioncampaign_name, source_name, conversion_count = first_result[1], first_result[3], first_result[4]- # Should handle gracefully - could attribute to last valid campaign or show Unknown- assert campaign_name is not None, "Should handle malformed UTM without crashing"assert conversion_count == 1, f"Expected 1 conversion, got {conversion_count}"- assert source_name == "organic", f"Expected organic source, got {source_name}"+ # Source-only touchpoint attributes to paid; the empty campaign falls back to organic.+ assert source_name == "meta", f"Expected meta source, got {source_name}"+ assert campaign_name == "organic", f"Expected organic campaign, got {campaign_name}"++ @parameterized.expand(+ [+ ("gclid", {"gclid": "abc123"}, "google", "Paid Search"),+ ("gad_source", {"gad_source": "1"}, "google", "Paid Search"),+ ]+ )+ def test_click_id_only_touchpoint_names_the_ad_network(+ self,+ _name: str,+ pageview_properties: dict[str, str],+ expected_source: str,+ expected_channel: str,+ ) -> None:+ self.config.drill_down_level = MarketingAnalyticsDrillDownLevel.CHANNEL_SOURCE+ with freeze_time("2023-05-01"):+ _create_person(distinct_ids=["click_id_user"], team=self.team)+ _create_event(+ distinct_id="click_id_user",+ event="$pageview",+ team=self.team,+ properties=pageview_properties,+ )+ flush_persons_and_events_in_batches()++ with freeze_time("2023-06-01"):+ _create_event(distinct_id="click_id_user", event="purchase", team=self.team, properties={"revenue": 100})+ flush_persons_and_events_in_batches()++ goal = ConversionGoalFilter1(+ kind="EventsNode",+ event="purchase",+ conversion_goal_id="click_id_only",+ conversion_goal_name="Click id only",+ math=BaseMathType.TOTAL,+ schema_map={"utm_campaign_name": "utm_campaign", "utm_source_name": "utm_source"},+ )+ processor = ConversionGoalProcessor(goal=goal, index=0, team=self.team, config=self.config)+ additional_conditions = [+ ast.CompareOperation(+ left=ast.Field(chain=["events", "timestamp"]),+ op=ast.CompareOperationOp.GtEq,+ right=ast.Call(name="toDate", args=[ast.Constant(value="2023-06-01")]),+ ),+ ]++ cte_query = processor.generate_cte_query(additional_conditions)+ response = execute_hogql_query(query=cte_query, team=self.team)+ assert len(response.results) == 1, f"Expected 1 result, got {len(response.results)}"++ # Schema: [0]=match_key, [1]=campaign (channel_type at this level), [2]=id, [3]=source+ channel_type, source_name = response.results[0][1], response.results[0][3]+ assert source_name == expected_source, f"Expected {expected_source} source, got {source_name}"+ assert channel_type == expected_channel, f"Expected {expected_channel} channel, got {channel_type}"++ def test_fbclid_alone_is_not_a_paid_touchpoint(self) -> None:+ """Facebook appends fbclid to every outbound link, organic posts included.++ `channel_type`'s paid branch excludes it for that reason, so admitting it here would+ attribute the conversion to a meta source and then have channel_type call the same row+ Organic Social — a paid source inside an organic channel.+ """+ self.config.drill_down_level = MarketingAnalyticsDrillDownLevel.CHANNEL_SOURCE+ with freeze_time("2023-05-01"):+ _create_person(distinct_ids=["fbclid_user"], team=self.team)+ _create_event(+ distinct_id="fbclid_user",+ event="$pageview",+ team=self.team,+ properties={"fbclid": "xyz789"},+ )+ flush_persons_and_events_in_batches()++ with freeze_time("2023-06-01"):+ _create_event(distinct_id="fbclid_user", event="purchase", team=self.team, properties={"revenue": 100})+ flush_persons_and_events_in_batches()++ goal = ConversionGoalFilter1(+ kind="EventsNode",+ event="purchase",+ conversion_goal_id="fbclid_only",+ conversion_goal_name="fbclid only",+ math=BaseMathType.TOTAL,+ schema_map={"utm_campaign_name": "utm_campaign", "utm_source_name": "utm_source"},+ )+ processor = ConversionGoalProcessor(goal=goal, index=0, team=self.team, config=self.config)+ additional_conditions = [+ ast.CompareOperation(+ left=ast.Field(chain=["events", "timestamp"]),+ op=ast.CompareOperationOp.GtEq,+ right=ast.Call(name="toDate", args=[ast.Constant(value="2023-06-01")]),+ ),+ ]++ cte_query = processor.generate_cte_query(additional_conditions)+ response = execute_hogql_query(query=cte_query, team=self.team)++ assert len(response.results) == 1, f"Expected 1 result, got {len(response.results)}"+ source_name = response.results[0][3]+ assert source_name == "organic", f"Expected the conversion to stay organic, got {source_name}"def test_duplicate_events_same_timestamp_but_first_event_id_is_first(self):"""diff --git a/products/marketing_analytics/backend/hogql_queries/test_marketing_touchpoints_precompute.py b/products/marketing_analytics/backend/hogql_queries/test_marketing_touchpoints_precompute.pyindex 0f6ad0ed2b7c..9d84054dde4e 100644--- a/products/marketing_analytics/backend/hogql_queries/test_marketing_touchpoints_precompute.py+++ b/products/marketing_analytics/backend/hogql_queries/test_marketing_touchpoints_precompute.py@@ -106,3 +106,33 @@ class TestMarketingTouchpointsPrecompute(ClickhouseTestMixin, APIBaseTest):# Identical (config-agnostic) query hash → the second call reuses the same job(s), no re-materialize.assert set(first.job_ids) == set(second.job_ids)assert self._count_touchpoints() == 3++ def test_source_or_click_id_alone_is_a_touchpoint(self):+ _create_person(distinct_ids=["p1"], team=self.team)+ # utm_source with no utm_campaign — the paid touchpoint the old both-required filter dropped.+ _create_event(+ team=self.team,+ event="$pageview",+ distinct_id="p1",+ timestamp=datetime(2025, 1, 3, 10, tzinfo=UTC),+ properties={"utm_source": "google"},+ )+ # A click id with no UTMs at all — also paid evidence.+ _create_event(+ team=self.team,+ event="$pageview",+ distinct_id="p1",+ timestamp=datetime(2025, 1, 4, 10, tzinfo=UTC),+ properties={"gclid": "abc123"},+ )+ # No source and no click id — organic, still excluded.+ _create_event(+ team=self.team,+ event="$pageview",+ distinct_id="p1",+ timestamp=datetime(2025, 1, 5, 10, tzinfo=UTC),+ properties={"utm_campaign": "spring"},+ )+ flush_persons_and_events()+ assert self._ensure().ready+ assert self._count_touchpoints() == 2