: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
feat(marketing-analytics): integrate x ads (#111987)
Javier Bahamondesfe389729664b
diff --git a/docs/internal/marketing-source-suggestions.md b/docs/internal/marketing-source-suggestions.mdindex 8d750deda5b1..d60304db69c9 100644--- a/docs/internal/marketing-source-suggestions.md+++ b/docs/internal/marketing-source-suggestions.md@@ -10,3 +10,22 @@ For example, a source with 700 matching events, including 17 with paid signals,It ranks below a source with 25 paid events, regardless of that source's total traffic.These counts guide connection suggestions; they do not change report attribution or connected-source sync checks.++## X Ads++X Ads uses `twitter`, `x`, `twitter_ads`, and `x_ads` as its default source aliases.+The `marketing-analytics-twitter-ads` flag controls availability in Marketing analytics, independently of the warehouse connector's `dwh-twitter-ads` release flag.+When the Marketing analytics flag is off, X Ads is excluded from native reporting, connection menus, and health diagnostics, including attribution suggestions.+Report UTM normalization stays stable across flag changes, as it does for the other native integrations.+The connector retains its existing OAuth setup requirements.+The new-source announcement uses the shared dismissal key: adding X Ads does not show it again to users who already opened the announcement.++Import `campaigns` and `campaign_stats` for campaign reporting, and `line_items` and `line_item_stats` for ad group reporting.+All four tables are recommended and selected by default when setting up a new X Ads source.+Existing connections keep their selected tables until the user changes them.+Daily spend is converted from micros using each row's funding-instrument currency and report date.+Monetary tiles require the currency column; impressions remain available when only currency is missing.+Clicks include the engagement clicks reported by X, not only outbound link clicks.+The current import provides spend, clicks, and impressions; platform-reported conversions and revenue are not imported.+PostHog conversion goals still work through campaign attribution.+Ad-level reporting is unavailable because the connector does not import promoted-post statistics.diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 721f957807b1..7767c7103d18 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -5821,13 +5821,13 @@ snapshots:marketing-analytics-add-source--new-sources--light:hash: v1.k794b7964.5fa1307763c5b2c1d15d9da94126801e790cdb76e0d0de4e7afcd9cd27bc4c50.vlfBEVR6C5WxdqBMZe2QoAmr_I-A-oivfeAPBPrwLzcmarketing-analytics-add-source--open-menu--dark:- hash: v1.k794b7964.72c67ad4702a042b6eb027ad30e6cafca8c414be1b22cdb28b7a62ae16a0d684.NS37A7XjVATW1ezz9bQ0Jra_r4iL_F3eYCgggWr0FYU+ hash: v1.k794b7964.c80e329b11c730701325e1a0c13e1f7c8ce85d379876d50555cc41b14918042e.S-CnWDuB2kd13u1hlddPnY-AYtxtGmuqP3uTt8zxDHAmarketing-analytics-add-source--open-menu--light:- hash: v1.k794b7964.a0f071a6ec0fd5fe906994d405ec2dbb9338f52e8a09cbe1e574b6a2301150b6.65yXO6LAE3bw8Rqg_BLEQoZZxPW_yEyWh4ipVUFvxV0+ hash: v1.k794b7964.75907cb59b9de8006b1b146dc7007d464d76a88850f8adccf78bebed591d654f.MZPeX3U9rUsg81U5tOBFu7-0Mu23XPoWzNO1xM9pChwmarketing-analytics-add-source--sources-disabled--dark:- hash: v1.k794b7964.6ab679994aa458fc15fd650db178bf805d878d726265ad51e3502d9029e63903.z12MB5eLM0VM1Bs8-v2_5d5HH5VaDT25r8GuqvBC4ds+ hash: v1.k794b7964.9bee1e501763e66a28f7ea68a9418ed1df0840df387aa0e00fd4d86488060640.GHV-4l1LqVtt2HjkCblPtfr549EdYvLoVnox07jQALomarketing-analytics-add-source--sources-disabled--light:- hash: v1.k794b7964.a40f8610ed453a1401dbbc1fb3bb921eeb3f55656138dc3e26b4751f6e38b7e8.0Ura8ZyXPrrQdqAbS1DDqkmoEZMPWEe4Y5EcDqQ39Xk+ hash: v1.k794b7964.ba3d73935d7d3587fd88c6e93573b55d3d6ed1a39c2f39720d0bb3c82ab29784.yC2cotyG1XNhqpPSc4SZG1XnGudulQOoJuSZ8MPcKwMmarketing-analytics-conversion-recordings--empty--dark:hash: v1.k794b7964.8982a2852c9527ff952b660792885e04c2fd81a3302a2c5c820c30e040182a06.h2Rie6hdM7FmCIHijYzFOkelhYaqzQboMKzRrwcxu8wmarketing-analytics-conversion-recordings--empty--light:diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex b55d732ed551..fb0b174d89e0 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -417,6 +417,7 @@ export const FEATURE_FLAGS = {MARKETING_ANALYTICS_RETURN_METRICS: 'marketing-analytics-return-metrics', // owner: @jabahamondes #team-web-analytics — gates the ROAS columnMARKETING_ANALYTICS_ROKT_ADS: 'marketing-analytics-rokt-ads', // owner: @jabahamondes #team-web-analyticsMARKETING_ANALYTICS_SETUP: 'marketing-analytics-setup', // owner: @jabahamondes #team-web-analytics — gates the Setup tab and its setup_plan / apply_setup_ops endpoints+ MARKETING_ANALYTICS_TWITTER_ADS: 'marketing-analytics-twitter-ads', // owner: @jabahamondes #team-web-analyticsMARKETING_ANALYTICS_UTM_AUDIT: 'marketing-analytics-utm-audit', // owner: @jabahamondes #team-web-analyticsMAX_AI_INSIGHT_SEARCH: 'max-ai-insight-search', // owner: #team-posthog-aiMAX_BILLING_CONTEXT: 'max-billing-context', // owner: @pawel-cebula #team-billingdiff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 7fc69a2cc44c..734f06ad70bd 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -37409,6 +37409,78 @@"primarySource"],"type": "object"+ },+ {+ "additionalProperties": false,+ "properties": {+ "adsetStatsTableName": {+ "const": "line_item_stats",+ "type": "string"+ },+ "adsetTableName": {+ "const": "line_items",+ "type": "string"+ },+ "campaignTableName": {+ "const": "campaigns",+ "type": "string"+ },+ "defaultSources": {+ "items": [+ {+ "const": "twitter",+ "type": "string"+ },+ {+ "const": "x",+ "type": "string"+ },+ {+ "const": "twitter_ads",+ "type": "string"+ },+ {+ "const": "x_ads",+ "type": "string"+ }+ ],+ "maxItems": 4,+ "minItems": 4,+ "type": "array"+ },+ "idField": {+ "const": "id",+ "type": "string"+ },+ "nameField": {+ "const": "name",+ "type": "string"+ },+ "primarySource": {+ "const": "twitter",+ "type": "string"+ },+ "sourceType": {+ "const": "TwitterAds",+ "type": "string"+ },+ "statsTableName": {+ "const": "campaign_stats",+ "type": "string"+ }+ },+ "required": [+ "sourceType",+ "nameField",+ "idField",+ "campaignTableName",+ "statsTableName",+ "defaultSources",+ "primarySource",+ "adsetTableName",+ "adsetStatsTableName"+ ],+ "type": "object"}]},@@ -39328,7 +39400,8 @@"AppleSearchAds","OpenAIAds","AmazonAds",- "RoktAds"+ "RoktAds",+ "TwitterAds"],"type": "string"},@@ -56335,6 +56408,10 @@"required": ["kind"],"type": "object"},+ "TwitterAdsDefaultSources": {+ "enum": ["twitter", "x", "twitter_ads", "x_ads"],+ "type": "string"+ },"UIVisibilityConfig": {"additionalProperties": false,"description": "Visibility of a single customizable UI element. An absent config or an absent `visible` means the element is shown.",diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex 97a560fd2972..e785f6623881 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -8565,6 +8565,7 @@ export const VALID_NATIVE_MARKETING_SOURCES = ['OpenAIAds','AmazonAds','RoktAds',+ 'TwitterAds',] as constexport type NativeMarketingSource = (typeof VALID_NATIVE_MARKETING_SOURCES)[number]@@ -8764,6 +8765,17 @@ export const MARKETING_INTEGRATION_CONFIGS = {defaultSources: ['amazon', 'amazon_ads'] as const,primarySource: 'amazon',},+ TwitterAds: {+ sourceType: 'TwitterAds' as const,+ nameField: 'name',+ idField: 'id',+ campaignTableName: 'campaigns',+ statsTableName: 'campaign_stats',+ defaultSources: ['twitter', 'x', 'twitter_ads', 'x_ads'] as const,+ primarySource: 'twitter',+ adsetTableName: 'line_items' as const,+ adsetStatsTableName: 'line_item_stats' as const,+ },RoktAds: {sourceType: 'RoktAds' as const,nameField: 'campaign_name',@@ -8778,6 +8790,7 @@ export const MARKETING_INTEGRATION_CONFIGS = {export type MarketingIntegrationConfig = (typeof MARKETING_INTEGRATION_CONFIGS)[NativeMarketingSource]export type AmazonAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['AmazonAds']['defaultSources'][number]+export type TwitterAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['TwitterAds']['defaultSources'][number]export type RoktAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['RoktAds']['defaultSources'][number]export type AppleSearchAdsDefaultSources =(typeof MARKETING_INTEGRATION_CONFIGS)['AppleSearchAds']['defaultSources'][number]diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/CampaignMappingCellActions.stories.tsx b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/CampaignMappingCellActions.stories.tsxindex 4e2d041e2aef..6cd231d2e3bc 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/CampaignMappingCellActions.stories.tsx+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/components/CampaignMapping/CampaignMappingCellActions.stories.tsx@@ -31,6 +31,7 @@ const MARKETING_SOURCE_ICONS: Record<caption: 'Apple Ads',},OpenAIAds: { name: 'OpenAIAds', iconPath: '/static/services/openai_ads.svg', fields: [], caption: 'OpenAI Ads' },+ TwitterAds: { name: 'TwitterAds', iconPath: '/static/services/twitter_ads.png', fields: [], caption: 'X Ads' },RoktAds: { name: 'RoktAds', iconPath: '/static/services/rokt_ads.png', fields: [], caption: 'Rokt Ads' },GoogleAds: {name: 'GoogleAds',diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/__snapshots__/utils.test.ts.snap b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/__snapshots__/utils.test.ts.snapindex 32e4da8ed87a..77efbba8418b 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/__snapshots__/utils.test.ts.snap+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/__snapshots__/utils.test.ts.snap@@ -1619,3 +1619,138 @@ exports[`marketing analytics utils createMarketingTile snapshots TikTokAds - roa"timestamp_field": "stat_time_day",}`;++exports[`marketing analytics utils createMarketingTile snapshots TwitterAds - clicks 1`] = `+{+ "custom_name": "prefix.campaign_stats clicks",+ "distinct_id_field": "entity_id",+ "id": "TwitterAds-stats-table-id",+ "id_field": "entity_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "SUM(ifNull(toFloat(clicks), 0))",+ "name": "twitter",+ "table_name": "prefix.campaign_stats",+ "timestamp_field": "date",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots TwitterAds - cost 1`] = `+{+ "custom_name": "prefix.campaign_stats cost",+ "distinct_id_field": "entity_id",+ "id": "TwitterAds-stats-table-id",+ "id_field": "entity_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "(SUM(toFloat(convertCurrency(coalesce(currency, 'USD'), 'USD', toFloat(billed_charge_local_micro / 1000000), coalesce(toDate(date), today())))) + throwIf(countIf(empty(coalesce(currency, ''))) > 0, 'X Ads currency is missing. Fully resync campaign_stats, then try again.'))",+ "name": "twitter",+ "table_name": "prefix.campaign_stats",+ "timestamp_field": "date",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots TwitterAds - impressions 1`] = `+{+ "custom_name": "prefix.campaign_stats impressions",+ "distinct_id_field": "entity_id",+ "id": "TwitterAds-stats-table-id",+ "id_field": "entity_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "SUM(ifNull(toFloat(impressions), 0))",+ "name": "twitter",+ "table_name": "prefix.campaign_stats",+ "timestamp_field": "date",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots TwitterAds - reported_conversion (missing conversion fields) 1`] = `+{+ "custom_name": "prefix.campaign_stats reported_conversion",+ "distinct_id_field": "entity_id",+ "id": "TwitterAds-stats-table-id",+ "id_field": "entity_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "twitter",+ "table_name": "prefix.campaign_stats",+ "timestamp_field": "date",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots TwitterAds - reported_conversion 1`] = `+{+ "custom_name": "prefix.campaign_stats reported_conversion",+ "distinct_id_field": "entity_id",+ "id": "TwitterAds-stats-table-id",+ "id_field": "entity_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "twitter",+ "table_name": "prefix.campaign_stats",+ "timestamp_field": "date",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots TwitterAds - reported_conversion_value (missing conversion fields) 1`] = `+{+ "custom_name": "prefix.campaign_stats reported_conversion_value",+ "distinct_id_field": "entity_id",+ "id": "TwitterAds-stats-table-id",+ "id_field": "entity_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "twitter",+ "table_name": "prefix.campaign_stats",+ "timestamp_field": "date",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots TwitterAds - reported_conversion_value 1`] = `+{+ "custom_name": "prefix.campaign_stats reported_conversion_value",+ "distinct_id_field": "entity_id",+ "id": "TwitterAds-stats-table-id",+ "id_field": "entity_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "twitter",+ "table_name": "prefix.campaign_stats",+ "timestamp_field": "date",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots TwitterAds - roas (missing conversion fields) 1`] = `+{+ "custom_name": "prefix.campaign_stats roas",+ "distinct_id_field": "entity_id",+ "id": "TwitterAds-stats-table-id",+ "id_field": "entity_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "twitter",+ "table_name": "prefix.campaign_stats",+ "timestamp_field": "date",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots TwitterAds - roas 1`] = `+{+ "custom_name": "prefix.campaign_stats roas",+ "distinct_id_field": "entity_id",+ "id": "TwitterAds-stats-table-id",+ "id_field": "entity_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "twitter",+ "table_name": "prefix.campaign_stats",+ "timestamp_field": "date",+}+`;diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.tsindex 77b552b1dc36..097d3c6976eb 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.ts+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsSettingsLogic.ts@@ -158,6 +158,7 @@ export interface marketingAnalyticsSettingsLogicActions {| 'RoktAds'| 'SnapchatAds'| 'TikTokAds'+ | 'TwitterAds'}removeConversionGoal: (goalId: string) => {goalId: stringdiff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.test.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.test.tsindex cf2e8b178f55..fdfdc22b7685 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.test.ts+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.test.ts@@ -32,6 +32,7 @@ describe('marketing analytics utils', () => {['OpenAIAds', FEATURE_FLAGS.MARKETING_ANALYTICS_OPENAI_ADS],['AmazonAds', FEATURE_FLAGS.MARKETING_ANALYTICS_AMAZON_ADS],['RoktAds', FEATURE_FLAGS.MARKETING_ANALYTICS_ROKT_ADS],+ ['TwitterAds', FEATURE_FLAGS.MARKETING_ANALYTICS_TWITTER_ADS],] as const)('getEnabledNativeMarketingSources: %s', (sourceType, flag) => {it.each([undefined, false, true, 'test'])('gates the source when its flag is %s', (enabled) => {const flags: Record<string, boolean | string> = {@@ -39,6 +40,7 @@ describe('marketing analytics utils', () => {[FEATURE_FLAGS.MARKETING_ANALYTICS_OPENAI_ADS]: true,[FEATURE_FLAGS.MARKETING_ANALYTICS_AMAZON_ADS]: true,[FEATURE_FLAGS.MARKETING_ANALYTICS_ROKT_ADS]: true,+ [FEATURE_FLAGS.MARKETING_ANALYTICS_TWITTER_ADS]: true,}if (enabled === undefined) {delete flags[flag]@@ -312,6 +314,7 @@ describe('marketing analytics utils', () => {],AppleSearchAds: ['local_spend', 'impressions', 'taps', 'total_installs'],OpenAIAds: ['campaign_id', 'start_time', 'spend', 'impressions', 'clicks', 'currency_code'],+ TwitterAds: ['entity_id', 'date', 'billed_charge_local_micro', 'impressions', 'clicks', 'currency'],GoogleAds: ['metrics_cost_micros','metrics_impressions',@@ -367,6 +370,7 @@ describe('marketing analytics utils', () => {RoktAds: ['campaign_id', 'datetime', 'currency_code', 'gross_cost', 'impressions', 'referrals'],AppleSearchAds: ['local_spend', 'impressions', 'taps'],OpenAIAds: ['campaign_id', 'start_time', 'spend', 'impressions', 'clicks', 'currency_code'],+ TwitterAds: ['entity_id', 'date', 'billed_charge_local_micro', 'impressions', 'clicks', 'currency'],GoogleAds: ['metrics_cost_micros', 'metrics_impressions', 'metrics_clicks', 'customer_currency_code'],RedditAds: ['spend', 'impressions', 'clicks', 'currency'],LinkedinAds: ['cost_in_usd', 'impressions', 'clicks'],@@ -490,28 +494,35 @@ describe('marketing analytics utils', () => {expect(result?.table_name).toBe(source.tables[0].name)})- it.each(['campaign_budget_currency_code', 'date', 'campaign_id', 'cost', 'impressions', 'clicks'])(- 'omits Amazon monetary tiles missing %s',- (field) => {- const source = makeMockSource(- 'AmazonAds',- sourceFields.AmazonAds.filter((name) => name !== field)- )- for (const column of [- MarketingAnalyticsColumnsSchemaNames.Cost,- MarketingAnalyticsColumnsSchemaNames.ReportedConversionValue,- 'roas',- 'cost_per_reported_conversion',- ] as const) {- expect(createMarketingTile(source, column, 'EUR')).toBeNull()- }+ it.each(+ (['AmazonAds', 'TwitterAds'] as const).flatMap((sourceType) =>+ (sourceType === 'AmazonAds'+ ? ['campaign_budget_currency_code', 'date', 'campaign_id', 'cost', 'impressions', 'clicks']+ : ['currency', 'date', 'entity_id', 'billed_charge_local_micro', 'impressions', 'clicks']+ ).map((field) => [sourceType, field] as const)+ )+ )('omits %s monetary tiles missing %s', (sourceType, field) => {+ const source = makeMockSource(+ sourceType,+ sourceFields[sourceType].filter((name) => name !== field)+ )+ for (const column of [+ MarketingAnalyticsColumnsSchemaNames.Cost,+ MarketingAnalyticsColumnsSchemaNames.ReportedConversionValue,+ 'roas',+ 'cost_per_reported_conversion',+ ] as const) {+ expect(createMarketingTile(source, column, 'EUR')).toBeNull()}- )+ })- it('keeps Amazon impressions available without currency', () => {+ it.each([+ ['AmazonAds', 'campaign_budget_currency_code'],+ ['TwitterAds', 'currency'],+ ] as const)('keeps %s impressions available without currency', (sourceType, currencyColumn) => {const source = makeMockSource(- 'AmazonAds',- sourceFields.AmazonAds.filter((name) => name !== 'campaign_budget_currency_code')+ sourceType,+ sourceFields[sourceType].filter((name) => name !== currencyColumn))expect(createMarketingTile(source, MarketingAnalyticsColumnsSchemaNames.Impressions, 'EUR')).not.toBeNull()})diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.tsindex 86368b532540..9e7333a3d5c9 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.ts+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/utils.ts@@ -33,6 +33,7 @@ export const VALID_SELF_MANAGED_MARKETING_SOURCES: ManualLinkSourceType[] = [export const NATIVE_SOURCE_FEATURE_FLAGS: Partial<Record<NativeMarketingSource, FeatureFlagKey>> = {AmazonAds: FEATURE_FLAGS.MARKETING_ANALYTICS_AMAZON_ADS,RoktAds: FEATURE_FLAGS.MARKETING_ANALYTICS_ROKT_ADS,+ TwitterAds: FEATURE_FLAGS.MARKETING_ANALYTICS_TWITTER_ADS,AppleSearchAds: FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS,OpenAIAds: FEATURE_FLAGS.MARKETING_ANALYTICS_OPENAI_ADS,}@@ -75,6 +76,7 @@ const NATIVE_SOURCE_DISPLAY_LABELS: Record<NativeMarketingSource, string> = {PinterestAds: 'Pinterest Ads',AmazonAds: 'Amazon Ads',RoktAds: 'Rokt Ads',+ TwitterAds: 'X Ads',AppleSearchAds: 'Apple Ads',OpenAIAds: 'OpenAI Ads',}@@ -390,6 +392,30 @@ const sourceTileConfigs: Record<NativeMarketingSource, SourceTileConfig> = {return null},},+ TwitterAds: {+ idField: 'entity_id',+ timestampField: 'date',+ columnMappings: {+ cost: 'billed_charge_local_micro',+ costNeedsDivision: true,+ impressions: 'impressions',+ clicks: 'clicks',+ reportedConversion: '0',+ reportedConversionValue: '0',+ currencyColumn: 'currency',+ currencyTimestampColumn: 'date',+ missingCurrencyMessage: 'X Ads currency is missing. Fully resync campaign_stats, then try again.',+ },+ specialConversionLogic: (_table, column) => {+ if (+ column === MarketingAnalyticsColumnsSchemaNames.ReportedConversion ||+ column === MarketingAnalyticsColumnsSchemaNames.ReportedConversionValue+ ) {+ return { math: HogQLMathType.HogQL, math_hogql: '0' }+ }+ return null+ },+ },RoktAds: {idField: 'campaign_id',timestampField: 'datetime',@@ -838,8 +864,12 @@ export function createMarketingTile(}}- if (sourceType === 'AmazonAds') {- if (!['campaign_id', 'date', 'cost', 'impressions', 'clicks'].every((field) => field in table.fields)) {+ if (sourceType === 'AmazonAds' || sourceType === 'TwitterAds') {+ const requiredFields =+ sourceType === 'AmazonAds'+ ? ['campaign_id', 'date', 'cost', 'impressions', 'clicks']+ : ['entity_id', 'date', 'billed_charge_local_micro', 'impressions', 'clicks']+ if (!requiredFields.every((field) => field in table.fields)) {return null}const monetaryColumn =@@ -847,7 +877,8 @@ export function createMarketingTile(tileColumnSelection === MarketingAnalyticsColumnsSchemaNames.ReportedConversionValue ||tileColumnSelection === 'roas' ||tileColumnSelection === 'cost_per_reported_conversion'- if (monetaryColumn && !('campaign_budget_currency_code' in table.fields)) {+ const currencyColumn = sourceType === 'AmazonAds' ? 'campaign_budget_currency_code' : 'currency'+ if (monetaryColumn && !(currencyColumn in table.fields)) {return null}}diff --git a/posthog/schema.py b/posthog/schema.pyindex fdd075cc290d..bbc2021c98ce 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -299,6 +299,7 @@ from posthog.schema_enums import (TraceOrderColumn as TraceOrderColumn,TraceSpanBreakdownOrderBy as TraceSpanBreakdownOrderBy,TraceSpanBreakdownType as TraceSpanBreakdownType,+ TwitterAdsDefaultSources as TwitterAdsDefaultSources,UrlMatching as UrlMatching,UsageMetricDisplay as UsageMetricDisplay,UsageMetricFormat as UsageMetricFormat,@@ -2244,6 +2245,21 @@ class MarketingIntegrationConfig12(BaseModel):statsTableName: Literal["CampaignPerformance"] = "CampaignPerformance"+class MarketingIntegrationConfig13(BaseModel):+ model_config = ConfigDict(+ extra="forbid",+ )+ adsetStatsTableName: Literal["line_item_stats"] = "line_item_stats"+ adsetTableName: Literal["line_items"] = "line_items"+ campaignTableName: Literal["campaigns"] = "campaigns"+ defaultSources: list[str] = Field(..., max_length=4, min_length=4)+ idField: Literal["id"] = "id"+ nameField: Literal["name"] = "name"+ primarySource: Literal["twitter"] = "twitter"+ sourceType: Literal["TwitterAds"] = "TwitterAds"+ statsTableName: Literal["campaign_stats"] = "campaign_stats"++class MarketingIntegrationConfig(RootModel[MarketingIntegrationConfig1@@ -2258,6 +2274,7 @@ class MarketingIntegrationConfig(| MarketingIntegrationConfig10| MarketingIntegrationConfig11| MarketingIntegrationConfig12+ | MarketingIntegrationConfig13]):root: (@@ -2273,6 +2290,7 @@ class MarketingIntegrationConfig(| MarketingIntegrationConfig10| MarketingIntegrationConfig11| MarketingIntegrationConfig12+ | MarketingIntegrationConfig13)diff --git a/posthog/schema_enums.py b/posthog/schema_enums.pyindex 40f3890194d5..d1ace81f43b2 100644--- a/posthog/schema_enums.py+++ b/posthog/schema_enums.py@@ -2141,6 +2141,7 @@ class NativeMarketingSource(StrEnum):OPEN_AI_ADS = "OpenAIAds"AMAZON_ADS = "AmazonAds"ROKT_ADS = "RoktAds"+ TWITTER_ADS = "TwitterAds"class NodeKind(StrEnum):@@ -3018,6 +3019,13 @@ class DetailedResultsAggregationType(StrEnum):MEDIAN = "median"+class TwitterAdsDefaultSources(StrEnum):+ TWITTER = "twitter"+ X = "x"+ TWITTER_ADS = "twitter_ads"+ X_ADS = "x_ads"++class UsageMetricDisplay(StrEnum):NUMBER = "number"SPARKLINE = "sparkline"diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_paths_query_runner.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_paths_query_runner.ambrindex 6f77f24c2f31..6b4e9698de7f 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_paths_query_runner.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_paths_query_runner.ambr@@ -45,7 +45,7 @@# name: TestMarketingAnalyticsAttributionPathsQueryRunner.test_attribution_paths_sql_1_source'''WITH person_arrays AS (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, arraySlice(arraySort(groupArrayIf(tuple(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_19)s)), coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_20)s), ''), 'null'), '^"|"$', ''), %(hogql_val_21)s), 0.0)), and(equals(events.event, %(hogql_val_22)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_23)s), toDateTime(%(hogql_val_24)s, %(hogql_val_25)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_26)s), toDateTime64(%(hogql_val_27)s, 6, %(hogql_val_28)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_29)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_30)s), toDateTime(%(hogql_val_31)s, %(hogql_val_32)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_33)s), toDateTime64(%(hogql_val_34)s, 6, %(hogql_val_35)s)))) AS conversion_count, arraySlice(arraySort(groupUniqArrayIf(tuple(toUnixTimestamp(events__session.`$start_timestamp`), if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_36)s)), events__session.`$entry_utm_source`, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s]), %(hogql_val_41)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_42)s)), events__session.`$entry_utm_source`, %(hogql_val_43)s)), [%(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s]), %(hogql_val_52)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_53)s)), events__session.`$entry_utm_source`, %(hogql_val_54)s)), [%(hogql_val_55)s]), %(hogql_val_56)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_57)s)), events__session.`$entry_utm_source`, %(hogql_val_58)s)), [%(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s]), %(hogql_val_68)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_69)s)), events__session.`$entry_utm_source`, %(hogql_val_70)s)), [%(hogql_val_71)s]), %(hogql_val_72)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_73)s)), events__session.`$entry_utm_source`, %(hogql_val_74)s)), [%(hogql_val_75)s, %(hogql_val_76)s]), %(hogql_val_77)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_78)s)), events__session.`$entry_utm_source`, %(hogql_val_79)s)), [%(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s]), %(hogql_val_83)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_84)s)), events__session.`$entry_utm_source`, %(hogql_val_85)s)), [%(hogql_val_86)s]), %(hogql_val_87)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_88)s)), events__session.`$entry_utm_source`, %(hogql_val_89)s)))))))))), and(and(equals(events.event, %(hogql_val_90)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), minus(conv_bounds.first_conversion, 345600)), lessOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), conv_bounds.last_conversion)))), -500) AS touchpoints+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, arraySlice(arraySort(groupArrayIf(tuple(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_19)s)), coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_20)s), ''), 'null'), '^"|"$', ''), %(hogql_val_21)s), 0.0)), and(equals(events.event, %(hogql_val_22)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_23)s), toDateTime(%(hogql_val_24)s, %(hogql_val_25)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_26)s), toDateTime64(%(hogql_val_27)s, 6, %(hogql_val_28)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_29)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_30)s), toDateTime(%(hogql_val_31)s, %(hogql_val_32)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_33)s), toDateTime64(%(hogql_val_34)s, 6, %(hogql_val_35)s)))) AS conversion_count, arraySlice(arraySort(groupUniqArrayIf(tuple(toUnixTimestamp(events__session.`$start_timestamp`), if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_36)s)), events__session.`$entry_utm_source`, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s]), %(hogql_val_41)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_42)s)), events__session.`$entry_utm_source`, %(hogql_val_43)s)), [%(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s]), %(hogql_val_52)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_53)s)), events__session.`$entry_utm_source`, %(hogql_val_54)s)), [%(hogql_val_55)s]), %(hogql_val_56)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_57)s)), events__session.`$entry_utm_source`, %(hogql_val_58)s)), [%(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s]), %(hogql_val_68)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_69)s)), events__session.`$entry_utm_source`, %(hogql_val_70)s)), [%(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s]), %(hogql_val_74)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_75)s)), events__session.`$entry_utm_source`, %(hogql_val_76)s)), [%(hogql_val_77)s]), %(hogql_val_78)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_79)s)), events__session.`$entry_utm_source`, %(hogql_val_80)s)), [%(hogql_val_81)s, %(hogql_val_82)s]), %(hogql_val_83)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_84)s)), events__session.`$entry_utm_source`, %(hogql_val_85)s)), [%(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s]), %(hogql_val_89)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_90)s)), events__session.`$entry_utm_source`, %(hogql_val_91)s)), [%(hogql_val_92)s]), %(hogql_val_93)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_94)s)), events__session.`$entry_utm_source`, %(hogql_val_95)s))))))))))), and(and(equals(events.event, %(hogql_val_96)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), minus(conv_bounds.first_conversion, 345600)), lessOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), conv_bounds.last_conversion)))), -500) AS touchpointsFROM events LEFT JOIN (SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_0)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_1)s), %(hogql_val_2)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions@@ -67,7 +67,7 @@SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_14)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_15)s, %(hogql_val_16)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_17)s, 6, %(hogql_val_18)s)))GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS conv_bounds ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), conv_bounds.person_id)- WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_91)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_92)s, %(hogql_val_93)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_94)s, 6, %(hogql_val_95)s))), and(equals(events.event, %(hogql_val_96)s), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_97)s, %(hogql_val_98)s), toIntervalSecond(345600)), 6, %(hogql_val_99)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_100)s, 6, %(hogql_val_101)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_102)s)), minus(conv_bounds.first_conversion, 345600)))))+ WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_97)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_98)s, %(hogql_val_99)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_100)s, 6, %(hogql_val_101)s))), and(equals(events.event, %(hogql_val_102)s), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_103)s, %(hogql_val_104)s), toIntervalSecond(345600)), 6, %(hogql_val_105)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_106)s, 6, %(hogql_val_107)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_108)s)), minus(conv_bounds.first_conversion, 345600)))))GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)HAVING greater(length(conversions), 0)), per_conversion_path AS MATERIALIZED (SELECT i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).2 AS conv_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, (person_arrays.conversions[i]).1), 0), ifNull(greaterOrEquals(t.1, minus((person_arrays.conversions[i]).1, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.2, tps) AS path_full, length(path_full) AS orig_len, arraySlice(path_full, -10) AS path, ifNull(greater(orig_len, 10), 0) AS truncated@@ -243,11 +243,11 @@FROM cached_session_conversions) AS c LEFT JOIN (SELECT d.person_id AS person_id, arraySlice(arraySort(groupUniqArray(tuple(d.session_ts, d.session_dim))), -500) AS touchpointsFROM (- SELECT conv.conv_person_id AS person_id, toUnixTimestamp(cached_sessions.start_timestamp) AS session_ts, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_32)s)), cached_sessions.utm_source, %(hogql_val_33)s)), [%(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s]), %(hogql_val_37)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_38)s)), cached_sessions.utm_source, %(hogql_val_39)s)), [%(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s]), %(hogql_val_48)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_49)s)), cached_sessions.utm_source, %(hogql_val_50)s)), [%(hogql_val_51)s]), %(hogql_val_52)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_53)s)), cached_sessions.utm_source, %(hogql_val_54)s)), [%(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s]), %(hogql_val_64)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_65)s)), cached_sessions.utm_source, %(hogql_val_66)s)), [%(hogql_val_67)s]), %(hogql_val_68)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_69)s)), cached_sessions.utm_source, %(hogql_val_70)s)), [%(hogql_val_71)s, %(hogql_val_72)s]), %(hogql_val_73)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_74)s)), cached_sessions.utm_source, %(hogql_val_75)s)), [%(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s]), %(hogql_val_79)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_80)s)), cached_sessions.utm_source, %(hogql_val_81)s)), [%(hogql_val_82)s]), %(hogql_val_83)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_84)s)), cached_sessions.utm_source, %(hogql_val_85)s))))))))) AS session_dim, conv.first_conversion AS first_conversion, conv.last_conversion AS upper_bound+ SELECT conv.conv_person_id AS person_id, toUnixTimestamp(cached_sessions.start_timestamp) AS session_ts, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_32)s)), cached_sessions.utm_source, %(hogql_val_33)s)), [%(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s]), %(hogql_val_37)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_38)s)), cached_sessions.utm_source, %(hogql_val_39)s)), [%(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s]), %(hogql_val_48)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_49)s)), cached_sessions.utm_source, %(hogql_val_50)s)), [%(hogql_val_51)s]), %(hogql_val_52)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_53)s)), cached_sessions.utm_source, %(hogql_val_54)s)), [%(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s]), %(hogql_val_64)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_65)s)), cached_sessions.utm_source, %(hogql_val_66)s)), [%(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s]), %(hogql_val_70)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_71)s)), cached_sessions.utm_source, %(hogql_val_72)s)), [%(hogql_val_73)s]), %(hogql_val_74)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_75)s)), cached_sessions.utm_source, %(hogql_val_76)s)), [%(hogql_val_77)s, %(hogql_val_78)s]), %(hogql_val_79)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_80)s)), cached_sessions.utm_source, %(hogql_val_81)s)), [%(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s]), %(hogql_val_85)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_86)s)), cached_sessions.utm_source, %(hogql_val_87)s)), [%(hogql_val_88)s]), %(hogql_val_89)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_90)s)), cached_sessions.utm_source, %(hogql_val_91)s)))))))))) AS session_dim, conv.first_conversion AS first_conversion, conv.last_conversion AS upper_boundFROM resolved_cached_sessions AS cached_sessions INNER JOIN (SELECT cached_session_conversions.conv_person_id AS conv_person_id, cached_session_conversions.first_conversion AS first_conversion, cached_session_conversions.last_conversion AS last_conversionFROM cached_session_conversions) AS conv ON equals(cached_sessions.person_id, conv.conv_person_id)- WHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')), greaterOrEquals(toUnixTimestamp(toTimeZone(cached_sessions.max_event_timestamp, %(hogql_val_86)s)), minus(conv.first_conversion, 345600)))) AS d+ WHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')), greaterOrEquals(toUnixTimestamp(toTimeZone(cached_sessions.max_event_timestamp, %(hogql_val_92)s)), minus(conv.first_conversion, 345600)))) AS dWHERE and(ifNull(greaterOrEquals(d.session_ts, minus(d.first_conversion, 345600)), 0), ifNull(lessOrEquals(d.session_ts, d.upper_bound), 0))GROUP BY d.person_id) AS t ON equals(c.conv_person_id, t.person_id)WHERE ifNull(greater(length(c.conversions), 0), 0)), per_conversion_path AS MATERIALIZED (diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_paths_query_runner.new_events_schema.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_paths_query_runner.new_events_schema.ambrindex 156c59a9a61e..f1ff12fe52af 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_paths_query_runner.new_events_schema.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_paths_query_runner.new_events_schema.ambr@@ -45,7 +45,7 @@# name: TestMarketingAnalyticsAttributionPathsQueryRunner.test_attribution_paths_sql_1_source[new_events_schema]'''WITH person_arrays AS (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, arraySlice(arraySort(groupArrayIf(tuple(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_19)s)), coalesce(accurateCastOrNull(events.properties.revenue, 'Float64'), 0.0)), and(equals(events.event, %(hogql_val_20)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_21)s), toDateTime(%(hogql_val_22)s, %(hogql_val_23)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_24)s), toDateTime64(%(hogql_val_25)s, 6, %(hogql_val_26)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_27)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_28)s), toDateTime(%(hogql_val_29)s, %(hogql_val_30)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_31)s), toDateTime64(%(hogql_val_32)s, 6, %(hogql_val_33)s)))) AS conversion_count, arraySlice(arraySort(groupUniqArrayIf(tuple(toUnixTimestamp(events__session.`$start_timestamp`), if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_34)s)), events__session.`$entry_utm_source`, %(hogql_val_35)s)), [%(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s]), %(hogql_val_39)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_40)s)), events__session.`$entry_utm_source`, %(hogql_val_41)s)), [%(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s]), %(hogql_val_54)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_55)s)), events__session.`$entry_utm_source`, %(hogql_val_56)s)), [%(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s]), %(hogql_val_66)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_67)s)), events__session.`$entry_utm_source`, %(hogql_val_68)s)), [%(hogql_val_69)s]), %(hogql_val_70)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_71)s)), events__session.`$entry_utm_source`, %(hogql_val_72)s)), [%(hogql_val_73)s, %(hogql_val_74)s]), %(hogql_val_75)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_76)s)), events__session.`$entry_utm_source`, %(hogql_val_77)s)), [%(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s]), %(hogql_val_81)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_82)s)), events__session.`$entry_utm_source`, %(hogql_val_83)s)), [%(hogql_val_84)s]), %(hogql_val_85)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_86)s)), events__session.`$entry_utm_source`, %(hogql_val_87)s)))))))))), and(and(equals(events.event, %(hogql_val_88)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), minus(conv_bounds.first_conversion, 345600)), lessOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), conv_bounds.last_conversion)))), -500) AS touchpoints+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, arraySlice(arraySort(groupArrayIf(tuple(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_19)s)), coalesce(accurateCastOrNull(events.properties.revenue, 'Float64'), 0.0)), and(equals(events.event, %(hogql_val_20)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_21)s), toDateTime(%(hogql_val_22)s, %(hogql_val_23)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_24)s), toDateTime64(%(hogql_val_25)s, 6, %(hogql_val_26)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_27)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_28)s), toDateTime(%(hogql_val_29)s, %(hogql_val_30)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_31)s), toDateTime64(%(hogql_val_32)s, 6, %(hogql_val_33)s)))) AS conversion_count, arraySlice(arraySort(groupUniqArrayIf(tuple(toUnixTimestamp(events__session.`$start_timestamp`), if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_34)s)), events__session.`$entry_utm_source`, %(hogql_val_35)s)), [%(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s]), %(hogql_val_39)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_40)s)), events__session.`$entry_utm_source`, %(hogql_val_41)s)), [%(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s]), %(hogql_val_54)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_55)s)), events__session.`$entry_utm_source`, %(hogql_val_56)s)), [%(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s]), %(hogql_val_66)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_67)s)), events__session.`$entry_utm_source`, %(hogql_val_68)s)), [%(hogql_val_69)s, %(hogql_val_70)s, %(hogql_val_71)s]), %(hogql_val_72)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_73)s)), events__session.`$entry_utm_source`, %(hogql_val_74)s)), [%(hogql_val_75)s]), %(hogql_val_76)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_77)s)), events__session.`$entry_utm_source`, %(hogql_val_78)s)), [%(hogql_val_79)s, %(hogql_val_80)s]), %(hogql_val_81)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_82)s)), events__session.`$entry_utm_source`, %(hogql_val_83)s)), [%(hogql_val_84)s, %(hogql_val_85)s, %(hogql_val_86)s]), %(hogql_val_87)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_88)s)), events__session.`$entry_utm_source`, %(hogql_val_89)s)), [%(hogql_val_90)s]), %(hogql_val_91)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_92)s)), events__session.`$entry_utm_source`, %(hogql_val_93)s))))))))))), and(and(equals(events.event, %(hogql_val_94)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), minus(conv_bounds.first_conversion, 345600)), lessOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), conv_bounds.last_conversion)))), -500) AS touchpointsFROM events_json AS events LEFT JOIN (SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_0)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_1)s), %(hogql_val_2)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions@@ -67,7 +67,7 @@SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_14)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_15)s, %(hogql_val_16)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_17)s, 6, %(hogql_val_18)s)))GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS conv_bounds ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), conv_bounds.person_id)- WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_89)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_90)s, %(hogql_val_91)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_92)s, 6, %(hogql_val_93)s))), and(equals(events.event, %(hogql_val_94)s), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_95)s, %(hogql_val_96)s), toIntervalSecond(345600)), 6, %(hogql_val_97)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_98)s, 6, %(hogql_val_99)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_100)s)), minus(conv_bounds.first_conversion, 345600)))))+ WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_95)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_96)s, %(hogql_val_97)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_98)s, 6, %(hogql_val_99)s))), and(equals(events.event, %(hogql_val_100)s), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_101)s, %(hogql_val_102)s), toIntervalSecond(345600)), 6, %(hogql_val_103)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_104)s, 6, %(hogql_val_105)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_106)s)), minus(conv_bounds.first_conversion, 345600)))))GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)HAVING greater(length(conversions), 0)), per_conversion_path AS MATERIALIZED (SELECT i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).2 AS conv_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, (person_arrays.conversions[i]).1), 0), ifNull(greaterOrEquals(t.1, minus((person_arrays.conversions[i]).1, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.2, tps) AS path_full, length(path_full) AS orig_len, arraySlice(path_full, -10) AS path, ifNull(greater(orig_len, 10), 0) AS truncated@@ -243,11 +243,11 @@FROM cached_session_conversions) AS c LEFT JOIN (SELECT d.person_id AS person_id, arraySlice(arraySort(groupUniqArray(tuple(d.session_ts, d.session_dim))), -500) AS touchpointsFROM (- SELECT conv.conv_person_id AS person_id, toUnixTimestamp(cached_sessions.start_timestamp) AS session_ts, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_30)s)), cached_sessions.utm_source, %(hogql_val_31)s)), [%(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s]), %(hogql_val_35)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_36)s)), cached_sessions.utm_source, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_47)s)), cached_sessions.utm_source, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_51)s)), cached_sessions.utm_source, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s]), %(hogql_val_62)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_63)s)), cached_sessions.utm_source, %(hogql_val_64)s)), [%(hogql_val_65)s]), %(hogql_val_66)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_67)s)), cached_sessions.utm_source, %(hogql_val_68)s)), [%(hogql_val_69)s, %(hogql_val_70)s]), %(hogql_val_71)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_72)s)), cached_sessions.utm_source, %(hogql_val_73)s)), [%(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s]), %(hogql_val_77)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_78)s)), cached_sessions.utm_source, %(hogql_val_79)s)), [%(hogql_val_80)s]), %(hogql_val_81)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_82)s)), cached_sessions.utm_source, %(hogql_val_83)s))))))))) AS session_dim, conv.first_conversion AS first_conversion, conv.last_conversion AS upper_bound+ SELECT conv.conv_person_id AS person_id, toUnixTimestamp(cached_sessions.start_timestamp) AS session_ts, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_30)s)), cached_sessions.utm_source, %(hogql_val_31)s)), [%(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s]), %(hogql_val_35)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_36)s)), cached_sessions.utm_source, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_47)s)), cached_sessions.utm_source, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_51)s)), cached_sessions.utm_source, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s]), %(hogql_val_62)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_63)s)), cached_sessions.utm_source, %(hogql_val_64)s)), [%(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s]), %(hogql_val_68)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_69)s)), cached_sessions.utm_source, %(hogql_val_70)s)), [%(hogql_val_71)s]), %(hogql_val_72)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_73)s)), cached_sessions.utm_source, %(hogql_val_74)s)), [%(hogql_val_75)s, %(hogql_val_76)s]), %(hogql_val_77)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_78)s)), cached_sessions.utm_source, %(hogql_val_79)s)), [%(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s]), %(hogql_val_83)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_84)s)), cached_sessions.utm_source, %(hogql_val_85)s)), [%(hogql_val_86)s]), %(hogql_val_87)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_88)s)), cached_sessions.utm_source, %(hogql_val_89)s)))))))))) AS session_dim, conv.first_conversion AS first_conversion, conv.last_conversion AS upper_boundFROM resolved_cached_sessions AS cached_sessions INNER JOIN (SELECT cached_session_conversions.conv_person_id AS conv_person_id, cached_session_conversions.first_conversion AS first_conversion, cached_session_conversions.last_conversion AS last_conversionFROM cached_session_conversions) AS conv ON equals(cached_sessions.person_id, conv.conv_person_id)- WHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')), greaterOrEquals(toUnixTimestamp(toTimeZone(cached_sessions.max_event_timestamp, %(hogql_val_84)s)), minus(conv.first_conversion, 345600)))) AS d+ WHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')), greaterOrEquals(toUnixTimestamp(toTimeZone(cached_sessions.max_event_timestamp, %(hogql_val_90)s)), minus(conv.first_conversion, 345600)))) AS dWHERE and(ifNull(greaterOrEquals(d.session_ts, minus(d.first_conversion, 345600)), 0), ifNull(lessOrEquals(d.session_ts, d.upper_bound), 0))GROUP BY d.person_id) AS t ON equals(c.conv_person_id, t.person_id)WHERE ifNull(greater(length(c.conversions), 0), 0)), per_conversion_path AS MATERIALIZED (diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_table_query_runner.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_table_query_runner.ambrindex d209e3b1abbe..f907551378d0 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_table_query_runner.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_table_query_runner.ambr@@ -65,7 +65,7 @@# name: TestMarketingAnalyticsAttributionQueryRunner.test_attribution_table_sql_1_source'''WITH influenced_reach AS (- SELECT if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_45)s)), events__session.`$entry_utm_source`, %(hogql_val_46)s)), [%(hogql_val_47)s, %(hogql_val_48)s]), %(hogql_val_49)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_50)s)), events__session.`$entry_utm_source`, %(hogql_val_51)s)), [%(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_60)s)), events__session.`$entry_utm_source`, %(hogql_val_61)s))))))))) AS breakdown_value, uniq(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS visitors+ SELECT if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_62)s)), events__session.`$entry_utm_source`, %(hogql_val_63)s)), [%(hogql_val_64)s]), %(hogql_val_65)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_66)s)), events__session.`$entry_utm_source`, %(hogql_val_67)s)))))))))) AS breakdown_value, uniq(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS visitorsFROM events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overrides@@ -77,21 +77,21 @@FROM raw_sessionsWHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_3)s, %(hogql_val_4)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_5)s, 6, %(hogql_val_6)s), toIntervalDay(3))))GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_7)s)), events__session.session_id_v7)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_62)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_63)s, %(hogql_val_64)s), toIntervalSecond(345600)), 6, %(hogql_val_65)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_66)s, 6, %(hogql_val_67)s)))+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_68)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_69)s, %(hogql_val_70)s), toIntervalSecond(345600)), 6, %(hogql_val_71)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_72)s, 6, %(hogql_val_73)s)))GROUP BY breakdown_value), person_arrays AS (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, arraySlice(arraySort(groupArrayIf(tuple(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_87)s)), coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_88)s), ''), 'null'), '^"|"$', ''), %(hogql_val_89)s), 0.0)), and(equals(events.event, %(hogql_val_90)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_91)s), toDateTime(%(hogql_val_92)s, %(hogql_val_93)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_94)s), toDateTime64(%(hogql_val_95)s, 6, %(hogql_val_96)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_97)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_98)s), toDateTime(%(hogql_val_99)s, %(hogql_val_100)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_101)s), toDateTime64(%(hogql_val_102)s, 6, %(hogql_val_103)s)))) AS conversion_count, arraySlice(arraySort(groupUniqArrayIf(tuple(toUnixTimestamp(events__session.`$start_timestamp`), if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_104)s)), events__session.`$entry_utm_source`, %(hogql_val_105)s)), [%(hogql_val_106)s, %(hogql_val_107)s, %(hogql_val_108)s]), %(hogql_val_109)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_110)s)), events__session.`$entry_utm_source`, %(hogql_val_111)s)), [%(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s]), %(hogql_val_120)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_121)s)), events__session.`$entry_utm_source`, %(hogql_val_122)s)), [%(hogql_val_123)s]), %(hogql_val_124)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_125)s)), events__session.`$entry_utm_source`, %(hogql_val_126)s)), [%(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s]), %(hogql_val_136)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_137)s)), events__session.`$entry_utm_source`, %(hogql_val_138)s)), [%(hogql_val_139)s]), %(hogql_val_140)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_141)s)), events__session.`$entry_utm_source`, %(hogql_val_142)s)), [%(hogql_val_143)s, %(hogql_val_144)s]), %(hogql_val_145)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_146)s)), events__session.`$entry_utm_source`, %(hogql_val_147)s)), [%(hogql_val_148)s, %(hogql_val_149)s, %(hogql_val_150)s]), %(hogql_val_151)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_152)s)), events__session.`$entry_utm_source`, %(hogql_val_153)s)), [%(hogql_val_154)s]), %(hogql_val_155)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_156)s)), events__session.`$entry_utm_source`, %(hogql_val_157)s)))))))))), and(and(equals(events.event, %(hogql_val_158)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), minus(conv_bounds.first_conversion, 345600)), lessOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), conv_bounds.last_conversion)))), -500) AS touchpoints+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, arraySlice(arraySort(groupArrayIf(tuple(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_93)s)), coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_94)s), ''), 'null'), '^"|"$', ''), %(hogql_val_95)s), 0.0)), and(equals(events.event, %(hogql_val_96)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_97)s), toDateTime(%(hogql_val_98)s, %(hogql_val_99)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_100)s), toDateTime64(%(hogql_val_101)s, 6, %(hogql_val_102)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_103)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_104)s), toDateTime(%(hogql_val_105)s, %(hogql_val_106)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_107)s), toDateTime64(%(hogql_val_108)s, 6, %(hogql_val_109)s)))) AS conversion_count, arraySlice(arraySort(groupUniqArrayIf(tuple(toUnixTimestamp(events__session.`$start_timestamp`), if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_110)s)), events__session.`$entry_utm_source`, %(hogql_val_111)s)), [%(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s]), %(hogql_val_115)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_116)s)), events__session.`$entry_utm_source`, %(hogql_val_117)s)), [%(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s]), %(hogql_val_126)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_127)s)), events__session.`$entry_utm_source`, %(hogql_val_128)s)), [%(hogql_val_129)s]), %(hogql_val_130)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_131)s)), events__session.`$entry_utm_source`, %(hogql_val_132)s)), [%(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s]), %(hogql_val_142)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_143)s)), events__session.`$entry_utm_source`, %(hogql_val_144)s)), [%(hogql_val_145)s, %(hogql_val_146)s, %(hogql_val_147)s]), %(hogql_val_148)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_149)s)), events__session.`$entry_utm_source`, %(hogql_val_150)s)), [%(hogql_val_151)s]), %(hogql_val_152)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_153)s)), events__session.`$entry_utm_source`, %(hogql_val_154)s)), [%(hogql_val_155)s, %(hogql_val_156)s]), %(hogql_val_157)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_158)s)), events__session.`$entry_utm_source`, %(hogql_val_159)s)), [%(hogql_val_160)s, %(hogql_val_161)s, %(hogql_val_162)s]), %(hogql_val_163)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_164)s)), events__session.`$entry_utm_source`, %(hogql_val_165)s)), [%(hogql_val_166)s]), %(hogql_val_167)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_168)s)), events__session.`$entry_utm_source`, %(hogql_val_169)s))))))))))), and(and(equals(events.event, %(hogql_val_170)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), minus(conv_bounds.first_conversion, 345600)), lessOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), conv_bounds.last_conversion)))), -500) AS touchpointsFROM events LEFT JOIN (- SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_68)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_69)s), %(hogql_val_70)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_74)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_75)s), %(hogql_val_76)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_71)s, %(hogql_val_72)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_73)s, 6, %(hogql_val_74)s), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_75)s, %(hogql_val_76)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_77)s, 6, %(hogql_val_78)s), toIntervalDay(3))))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_79)s)), events__session.session_id_v7) LEFT OUTER JOIN (+ WHERE and(equals(raw_sessions.team_id, 420), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_77)s, %(hogql_val_78)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_79)s, 6, %(hogql_val_80)s), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_81)s, %(hogql_val_82)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_83)s, 6, %(hogql_val_84)s), toIntervalDay(3))))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_85)s)), events__session.session_id_v7) LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overridesWHERE equals(person_distinct_id_overrides.team_id, 420)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) INNER JOIN (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, min(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_80)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_81)s))) AS last_conversion+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, min(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_86)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_87)s))) AS last_conversionFROM events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overrides@@ -99,12 +99,12 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_82)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_83)s, %(hogql_val_84)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_85)s, 6, %(hogql_val_86)s)))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_88)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_89)s, %(hogql_val_90)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_91)s, 6, %(hogql_val_92)s)))GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS conv_bounds ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), conv_bounds.person_id)- WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_159)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_160)s, %(hogql_val_161)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_162)s, 6, %(hogql_val_163)s))), and(equals(events.event, %(hogql_val_164)s), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_165)s, %(hogql_val_166)s), toIntervalSecond(345600)), 6, %(hogql_val_167)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_168)s, 6, %(hogql_val_169)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_170)s)), minus(conv_bounds.first_conversion, 345600)))))+ WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_171)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_172)s, %(hogql_val_173)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_174)s, 6, %(hogql_val_175)s))), and(equals(events.event, %(hogql_val_176)s), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_177)s, %(hogql_val_178)s), toIntervalSecond(345600)), 6, %(hogql_val_179)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_180)s, 6, %(hogql_val_181)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_182)s)), minus(conv_bounds.first_conversion, 345600)))))GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)HAVING greater(length(conversions), 0)), per_conversion AS MATERIALIZED (- SELECT person_arrays.person_id AS person_id, i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).1 AS conversion_time, (person_arrays.conversions[i]).2 AS conversion_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, conversion_time), 0), ifNull(greaterOrEquals(t.1, minus(conversion_time, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.1, tps) AS touch_ts, arrayMap(t -> t.2, tps) AS dims, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMin(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMin(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_first, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMax(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMax(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_last, arrayMap(_x -> divide(1.0, greatest(accurateCastOrNull(length(touch_ts), %(hogql_val_171)s), 1.0)), touch_ts) AS w_linear, arrayMap(w -> divide(w, greatest(arraySum(arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)), 1e-06)), arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)) AS w_decay, if(ifNull(equals(length(touch_ts), 0), 0), [], if(ifNull(equals(length(touch_ts), 1), 0), [1.0], if(ifNull(equals(length(touch_ts), 2), 0), [0.5, 0.5], arrayMap(w -> divide(w, greatest(arraySum(arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_172)s), 2.0), 1.0)))), touch_ts))), 1e-06)), arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_173)s), 2.0), 1.0)))), touch_ts)))))) AS w_position+ SELECT person_arrays.person_id AS person_id, i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).1 AS conversion_time, (person_arrays.conversions[i]).2 AS conversion_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, conversion_time), 0), ifNull(greaterOrEquals(t.1, minus(conversion_time, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.1, tps) AS touch_ts, arrayMap(t -> t.2, tps) AS dims, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMin(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMin(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_first, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMax(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMax(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_last, arrayMap(_x -> divide(1.0, greatest(accurateCastOrNull(length(touch_ts), %(hogql_val_183)s), 1.0)), touch_ts) AS w_linear, arrayMap(w -> divide(w, greatest(arraySum(arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)), 1e-06)), arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)) AS w_decay, if(ifNull(equals(length(touch_ts), 0), 0), [], if(ifNull(equals(length(touch_ts), 1), 0), [1.0], if(ifNull(equals(length(touch_ts), 2), 0), [0.5, 0.5], arrayMap(w -> divide(w, greatest(arraySum(arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_184)s), 2.0), 1.0)))), touch_ts))), 1e-06)), arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_185)s), 2.0), 1.0)))), touch_ts)))))) AS w_positionFROM person_arrays ARRAY JOIN arrayEnumerate(person_arrays.conversions) AS i), per_touchpoint AS (SELECT per_conversion.person_id AS person_id, per_conversion.i AS i, per_conversion.conversion_value AS conversion_value, per_conversion.dims[k] AS breakdown_value, per_conversion.w_first[k] AS w_first, per_conversion.w_last[k] AS w_last, per_conversion.w_linear[k] AS w_linear, per_conversion.w_decay[k] AS w_decay, per_conversion.w_position[k] AS w_positionFROM per_conversion ARRAY JOIN arrayEnumerate(per_conversion.touch_ts) AS k), per_conversion_dim AS (@@ -114,7 +114,7 @@SELECT per_conversion_dim.breakdown_value AS breakdown_value, count() AS influenced_conversions, sum(per_conversion_dim.conv_value) AS influenced_value, sum(per_conversion_dim.w_first) AS w_first_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_first)) AS w_first_value, sum(per_conversion_dim.w_last) AS w_last_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_last)) AS w_last_value, sum(per_conversion_dim.w_linear) AS w_linear_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_linear)) AS w_linear_value, sum(per_conversion_dim.w_decay) AS w_decay_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_decay)) AS w_decay_value, sum(per_conversion_dim.w_position) AS w_position_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_position)) AS w_position_valueFROM per_conversion_dimGROUP BY per_conversion_dim.breakdown_value), attribution_rows AS (- SELECT coalesce(nullIf(attribution_totals.breakdown_value, %(hogql_val_174)s), influenced_reach.breakdown_value) AS breakdown_value, ifNull(influenced_reach.visitors, 0) AS visitors, ifNull(attribution_totals.influenced_conversions, 0) AS influenced_conversions, ifNull(attribution_totals.influenced_value, 0.0) AS influenced_value, ifNull(attribution_totals.w_first_conversions, 0.0) AS w_first_conversions, ifNull(attribution_totals.w_first_value, 0.0) AS w_first_value, ifNull(attribution_totals.w_last_conversions, 0.0) AS w_last_conversions, ifNull(attribution_totals.w_last_value, 0.0) AS w_last_value, ifNull(attribution_totals.w_linear_conversions, 0.0) AS w_linear_conversions, ifNull(attribution_totals.w_linear_value, 0.0) AS w_linear_value, ifNull(attribution_totals.w_decay_conversions, 0.0) AS w_decay_conversions, ifNull(attribution_totals.w_decay_value, 0.0) AS w_decay_value, ifNull(attribution_totals.w_position_conversions, 0.0) AS w_position_conversions, ifNull(attribution_totals.w_position_value, 0.0) AS w_position_value, 1 AS footer_key+ SELECT coalesce(nullIf(attribution_totals.breakdown_value, %(hogql_val_186)s), influenced_reach.breakdown_value) AS breakdown_value, ifNull(influenced_reach.visitors, 0) AS visitors, ifNull(attribution_totals.influenced_conversions, 0) AS influenced_conversions, ifNull(attribution_totals.influenced_value, 0.0) AS influenced_value, ifNull(attribution_totals.w_first_conversions, 0.0) AS w_first_conversions, ifNull(attribution_totals.w_first_value, 0.0) AS w_first_value, ifNull(attribution_totals.w_last_conversions, 0.0) AS w_last_conversions, ifNull(attribution_totals.w_last_value, 0.0) AS w_last_value, ifNull(attribution_totals.w_linear_conversions, 0.0) AS w_linear_conversions, ifNull(attribution_totals.w_linear_value, 0.0) AS w_linear_value, ifNull(attribution_totals.w_decay_conversions, 0.0) AS w_decay_conversions, ifNull(attribution_totals.w_decay_value, 0.0) AS w_decay_value, ifNull(attribution_totals.w_position_conversions, 0.0) AS w_position_conversions, ifNull(attribution_totals.w_position_value, 0.0) AS w_position_value, 1 AS footer_keyFROM attribution_totals FULL OUTER JOIN influenced_reach ON equals(attribution_totals.breakdown_value, influenced_reach.breakdown_value)), attribution_footer AS (SELECT sumIf(per_conversion.conversion_count, ifNull(equals(per_conversion.i, 1), 0)) AS total_conversions, countIf(ifNull(greater(length(per_conversion.tps), 0), 0)) AS attributed_conversions, 1 AS footer_keyFROM per_conversion)@@ -311,7 +311,7 @@GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)), influenced_reach AS (SELECT s.breakdown_value AS breakdown_value, uniq(s.person_id) AS visitorsFROM (- SELECT cached_sessions.person_id AS person_id, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_32)s)), cached_sessions.utm_source, %(hogql_val_33)s)), [%(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s]), %(hogql_val_37)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_38)s)), cached_sessions.utm_source, %(hogql_val_39)s)), [%(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s]), %(hogql_val_48)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_49)s)), cached_sessions.utm_source, %(hogql_val_50)s)), [%(hogql_val_51)s]), %(hogql_val_52)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_53)s)), cached_sessions.utm_source, %(hogql_val_54)s)), [%(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s]), %(hogql_val_64)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_65)s)), cached_sessions.utm_source, %(hogql_val_66)s)), [%(hogql_val_67)s]), %(hogql_val_68)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_69)s)), cached_sessions.utm_source, %(hogql_val_70)s)), [%(hogql_val_71)s, %(hogql_val_72)s]), %(hogql_val_73)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_74)s)), cached_sessions.utm_source, %(hogql_val_75)s)), [%(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s]), %(hogql_val_79)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_80)s)), cached_sessions.utm_source, %(hogql_val_81)s)), [%(hogql_val_82)s]), %(hogql_val_83)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_84)s)), cached_sessions.utm_source, %(hogql_val_85)s))))))))) AS breakdown_value+ SELECT cached_sessions.person_id AS person_id, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_32)s)), cached_sessions.utm_source, %(hogql_val_33)s)), [%(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s]), %(hogql_val_37)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_38)s)), cached_sessions.utm_source, %(hogql_val_39)s)), [%(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s]), %(hogql_val_48)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_49)s)), cached_sessions.utm_source, %(hogql_val_50)s)), [%(hogql_val_51)s]), %(hogql_val_52)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_53)s)), cached_sessions.utm_source, %(hogql_val_54)s)), [%(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s]), %(hogql_val_64)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_65)s)), cached_sessions.utm_source, %(hogql_val_66)s)), [%(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s]), %(hogql_val_70)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_71)s)), cached_sessions.utm_source, %(hogql_val_72)s)), [%(hogql_val_73)s]), %(hogql_val_74)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_75)s)), cached_sessions.utm_source, %(hogql_val_76)s)), [%(hogql_val_77)s, %(hogql_val_78)s]), %(hogql_val_79)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_80)s)), cached_sessions.utm_source, %(hogql_val_81)s)), [%(hogql_val_82)s, %(hogql_val_83)s, %(hogql_val_84)s]), %(hogql_val_85)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_86)s)), cached_sessions.utm_source, %(hogql_val_87)s)), [%(hogql_val_88)s]), %(hogql_val_89)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_90)s)), cached_sessions.utm_source, %(hogql_val_91)s)))))))))) AS breakdown_valueFROM resolved_cached_sessions AS cached_sessionsWHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')))) AS sGROUP BY s.breakdown_value), person_arrays AS (@@ -321,15 +321,15 @@FROM cached_session_conversions) AS c LEFT JOIN (SELECT d.person_id AS person_id, arraySlice(arraySort(groupUniqArray(tuple(d.session_ts, d.session_dim))), -500) AS touchpointsFROM (- SELECT conv.conv_person_id AS person_id, toUnixTimestamp(cached_sessions.start_timestamp) AS session_ts, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_86)s)), cached_sessions.utm_source, %(hogql_val_87)s)), [%(hogql_val_88)s, %(hogql_val_89)s, %(hogql_val_90)s]), %(hogql_val_91)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_92)s)), cached_sessions.utm_source, %(hogql_val_93)s)), [%(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s]), %(hogql_val_102)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_103)s)), cached_sessions.utm_source, %(hogql_val_104)s)), [%(hogql_val_105)s]), %(hogql_val_106)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_107)s)), cached_sessions.utm_source, %(hogql_val_108)s)), [%(hogql_val_109)s, %(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s]), %(hogql_val_118)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_119)s)), cached_sessions.utm_source, %(hogql_val_120)s)), [%(hogql_val_121)s]), %(hogql_val_122)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_123)s)), cached_sessions.utm_source, %(hogql_val_124)s)), [%(hogql_val_125)s, %(hogql_val_126)s]), %(hogql_val_127)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_128)s)), cached_sessions.utm_source, %(hogql_val_129)s)), [%(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s]), %(hogql_val_133)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_134)s)), cached_sessions.utm_source, %(hogql_val_135)s)), [%(hogql_val_136)s]), %(hogql_val_137)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_138)s)), cached_sessions.utm_source, %(hogql_val_139)s))))))))) AS session_dim, conv.first_conversion AS first_conversion, conv.last_conversion AS upper_bound+ SELECT conv.conv_person_id AS person_id, toUnixTimestamp(cached_sessions.start_timestamp) AS session_ts, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_92)s)), cached_sessions.utm_source, %(hogql_val_93)s)), [%(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s]), %(hogql_val_97)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_98)s)), cached_sessions.utm_source, %(hogql_val_99)s)), [%(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s]), %(hogql_val_108)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_109)s)), cached_sessions.utm_source, %(hogql_val_110)s)), [%(hogql_val_111)s]), %(hogql_val_112)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_113)s)), cached_sessions.utm_source, %(hogql_val_114)s)), [%(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s]), %(hogql_val_124)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_125)s)), cached_sessions.utm_source, %(hogql_val_126)s)), [%(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s]), %(hogql_val_130)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_131)s)), cached_sessions.utm_source, %(hogql_val_132)s)), [%(hogql_val_133)s]), %(hogql_val_134)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_135)s)), cached_sessions.utm_source, %(hogql_val_136)s)), [%(hogql_val_137)s, %(hogql_val_138)s]), %(hogql_val_139)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_140)s)), cached_sessions.utm_source, %(hogql_val_141)s)), [%(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s]), %(hogql_val_145)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_146)s)), cached_sessions.utm_source, %(hogql_val_147)s)), [%(hogql_val_148)s]), %(hogql_val_149)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_150)s)), cached_sessions.utm_source, %(hogql_val_151)s)))))))))) AS session_dim, conv.first_conversion AS first_conversion, conv.last_conversion AS upper_boundFROM resolved_cached_sessions AS cached_sessions INNER JOIN (SELECT cached_session_conversions.conv_person_id AS conv_person_id, cached_session_conversions.first_conversion AS first_conversion, cached_session_conversions.last_conversion AS last_conversionFROM cached_session_conversions) AS conv ON equals(cached_sessions.person_id, conv.conv_person_id)- WHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')), greaterOrEquals(toUnixTimestamp(toTimeZone(cached_sessions.max_event_timestamp, %(hogql_val_140)s)), minus(conv.first_conversion, 345600)))) AS d+ WHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')), greaterOrEquals(toUnixTimestamp(toTimeZone(cached_sessions.max_event_timestamp, %(hogql_val_152)s)), minus(conv.first_conversion, 345600)))) AS dWHERE and(ifNull(greaterOrEquals(d.session_ts, minus(d.first_conversion, 345600)), 0), ifNull(lessOrEquals(d.session_ts, d.upper_bound), 0))GROUP BY d.person_id) AS t ON equals(c.conv_person_id, t.person_id)WHERE ifNull(greater(length(c.conversions), 0), 0)), per_conversion AS MATERIALIZED (- SELECT person_arrays.person_id AS person_id, i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).1 AS conversion_time, (person_arrays.conversions[i]).2 AS conversion_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, conversion_time), 0), ifNull(greaterOrEquals(t.1, minus(conversion_time, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.1, tps) AS touch_ts, arrayMap(t -> t.2, tps) AS dims, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMin(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMin(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_first, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMax(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMax(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_last, arrayMap(_x -> divide(1.0, greatest(accurateCastOrNull(length(touch_ts), %(hogql_val_141)s), 1.0)), touch_ts) AS w_linear, arrayMap(w -> divide(w, greatest(arraySum(arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)), 1e-06)), arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)) AS w_decay, if(ifNull(equals(length(touch_ts), 0), 0), [], if(ifNull(equals(length(touch_ts), 1), 0), [1.0], if(ifNull(equals(length(touch_ts), 2), 0), [0.5, 0.5], arrayMap(w -> divide(w, greatest(arraySum(arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_142)s), 2.0), 1.0)))), touch_ts))), 1e-06)), arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_143)s), 2.0), 1.0)))), touch_ts)))))) AS w_position+ SELECT person_arrays.person_id AS person_id, i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).1 AS conversion_time, (person_arrays.conversions[i]).2 AS conversion_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, conversion_time), 0), ifNull(greaterOrEquals(t.1, minus(conversion_time, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.1, tps) AS touch_ts, arrayMap(t -> t.2, tps) AS dims, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMin(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMin(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_first, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMax(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMax(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_last, arrayMap(_x -> divide(1.0, greatest(accurateCastOrNull(length(touch_ts), %(hogql_val_153)s), 1.0)), touch_ts) AS w_linear, arrayMap(w -> divide(w, greatest(arraySum(arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)), 1e-06)), arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)) AS w_decay, if(ifNull(equals(length(touch_ts), 0), 0), [], if(ifNull(equals(length(touch_ts), 1), 0), [1.0], if(ifNull(equals(length(touch_ts), 2), 0), [0.5, 0.5], arrayMap(w -> divide(w, greatest(arraySum(arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_154)s), 2.0), 1.0)))), touch_ts))), 1e-06)), arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_155)s), 2.0), 1.0)))), touch_ts)))))) AS w_positionFROM person_arrays ARRAY JOIN arrayEnumerate(person_arrays.conversions) AS i), per_touchpoint AS (SELECT per_conversion.person_id AS person_id, per_conversion.i AS i, per_conversion.conversion_value AS conversion_value, per_conversion.dims[k] AS breakdown_value, per_conversion.w_first[k] AS w_first, per_conversion.w_last[k] AS w_last, per_conversion.w_linear[k] AS w_linear, per_conversion.w_decay[k] AS w_decay, per_conversion.w_position[k] AS w_positionFROM per_conversion ARRAY JOIN arrayEnumerate(per_conversion.touch_ts) AS k), per_conversion_dim AS (@@ -339,7 +339,7 @@SELECT per_conversion_dim.breakdown_value AS breakdown_value, count() AS influenced_conversions, sum(per_conversion_dim.conv_value) AS influenced_value, sum(per_conversion_dim.w_first) AS w_first_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_first)) AS w_first_value, sum(per_conversion_dim.w_last) AS w_last_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_last)) AS w_last_value, sum(per_conversion_dim.w_linear) AS w_linear_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_linear)) AS w_linear_value, sum(per_conversion_dim.w_decay) AS w_decay_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_decay)) AS w_decay_value, sum(per_conversion_dim.w_position) AS w_position_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_position)) AS w_position_valueFROM per_conversion_dimGROUP BY per_conversion_dim.breakdown_value), attribution_rows AS (- SELECT coalesce(nullIf(attribution_totals.breakdown_value, %(hogql_val_144)s), influenced_reach.breakdown_value) AS breakdown_value, ifNull(influenced_reach.visitors, 0) AS visitors, ifNull(attribution_totals.influenced_conversions, 0) AS influenced_conversions, ifNull(attribution_totals.influenced_value, 0.0) AS influenced_value, ifNull(attribution_totals.w_first_conversions, 0.0) AS w_first_conversions, ifNull(attribution_totals.w_first_value, 0.0) AS w_first_value, ifNull(attribution_totals.w_last_conversions, 0.0) AS w_last_conversions, ifNull(attribution_totals.w_last_value, 0.0) AS w_last_value, ifNull(attribution_totals.w_linear_conversions, 0.0) AS w_linear_conversions, ifNull(attribution_totals.w_linear_value, 0.0) AS w_linear_value, ifNull(attribution_totals.w_decay_conversions, 0.0) AS w_decay_conversions, ifNull(attribution_totals.w_decay_value, 0.0) AS w_decay_value, ifNull(attribution_totals.w_position_conversions, 0.0) AS w_position_conversions, ifNull(attribution_totals.w_position_value, 0.0) AS w_position_value, 1 AS footer_key+ SELECT coalesce(nullIf(attribution_totals.breakdown_value, %(hogql_val_156)s), influenced_reach.breakdown_value) AS breakdown_value, ifNull(influenced_reach.visitors, 0) AS visitors, ifNull(attribution_totals.influenced_conversions, 0) AS influenced_conversions, ifNull(attribution_totals.influenced_value, 0.0) AS influenced_value, ifNull(attribution_totals.w_first_conversions, 0.0) AS w_first_conversions, ifNull(attribution_totals.w_first_value, 0.0) AS w_first_value, ifNull(attribution_totals.w_last_conversions, 0.0) AS w_last_conversions, ifNull(attribution_totals.w_last_value, 0.0) AS w_last_value, ifNull(attribution_totals.w_linear_conversions, 0.0) AS w_linear_conversions, ifNull(attribution_totals.w_linear_value, 0.0) AS w_linear_value, ifNull(attribution_totals.w_decay_conversions, 0.0) AS w_decay_conversions, ifNull(attribution_totals.w_decay_value, 0.0) AS w_decay_value, ifNull(attribution_totals.w_position_conversions, 0.0) AS w_position_conversions, ifNull(attribution_totals.w_position_value, 0.0) AS w_position_value, 1 AS footer_keyFROM attribution_totals FULL OUTER JOIN influenced_reach ON equals(attribution_totals.breakdown_value, influenced_reach.breakdown_value)), attribution_footer AS (SELECT sumIf(per_conversion.conversion_count, ifNull(equals(per_conversion.i, 1), 0)) AS total_conversions, countIf(ifNull(greater(length(per_conversion.tps), 0), 0)) AS attributed_conversions, 1 AS footer_keyFROM per_conversion)diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_table_query_runner.new_events_schema.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_table_query_runner.new_events_schema.ambrindex 824ed31ddb51..17ab77d24967 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_table_query_runner.new_events_schema.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_attribution_table_query_runner.new_events_schema.ambr@@ -65,7 +65,7 @@# name: TestMarketingAnalyticsAttributionQueryRunner.test_attribution_table_sql_1_source[new_events_schema]'''WITH influenced_reach AS (- SELECT if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_45)s)), events__session.`$entry_utm_source`, %(hogql_val_46)s)), [%(hogql_val_47)s, %(hogql_val_48)s]), %(hogql_val_49)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_50)s)), events__session.`$entry_utm_source`, %(hogql_val_51)s)), [%(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_60)s)), events__session.`$entry_utm_source`, %(hogql_val_61)s))))))))) AS breakdown_value, uniq(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS visitors+ SELECT if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_62)s)), events__session.`$entry_utm_source`, %(hogql_val_63)s)), [%(hogql_val_64)s]), %(hogql_val_65)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_66)s)), events__session.`$entry_utm_source`, %(hogql_val_67)s)))))))))) AS breakdown_value, uniq(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS visitorsFROM events_json AS events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overrides@@ -77,21 +77,21 @@FROM raw_sessionsWHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_3)s, %(hogql_val_4)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_5)s, 6, %(hogql_val_6)s), toIntervalDay(3))))GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_7)s)), events__session.session_id_v7)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_62)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_63)s, %(hogql_val_64)s), toIntervalSecond(345600)), 6, %(hogql_val_65)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_66)s, 6, %(hogql_val_67)s)))+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_68)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_69)s, %(hogql_val_70)s), toIntervalSecond(345600)), 6, %(hogql_val_71)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_72)s, 6, %(hogql_val_73)s)))GROUP BY breakdown_value), person_arrays AS (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, arraySlice(arraySort(groupArrayIf(tuple(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_87)s)), coalesce(accurateCastOrNull(events.properties.revenue, 'Float64'), 0.0)), and(equals(events.event, %(hogql_val_88)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_89)s), toDateTime(%(hogql_val_90)s, %(hogql_val_91)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_92)s), toDateTime64(%(hogql_val_93)s, 6, %(hogql_val_94)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_95)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_96)s), toDateTime(%(hogql_val_97)s, %(hogql_val_98)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_99)s), toDateTime64(%(hogql_val_100)s, 6, %(hogql_val_101)s)))) AS conversion_count, arraySlice(arraySort(groupUniqArrayIf(tuple(toUnixTimestamp(events__session.`$start_timestamp`), if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_102)s)), events__session.`$entry_utm_source`, %(hogql_val_103)s)), [%(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s]), %(hogql_val_107)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_108)s)), events__session.`$entry_utm_source`, %(hogql_val_109)s)), [%(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s]), %(hogql_val_118)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_119)s)), events__session.`$entry_utm_source`, %(hogql_val_120)s)), [%(hogql_val_121)s]), %(hogql_val_122)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_123)s)), events__session.`$entry_utm_source`, %(hogql_val_124)s)), [%(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s, %(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s]), %(hogql_val_134)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_135)s)), events__session.`$entry_utm_source`, %(hogql_val_136)s)), [%(hogql_val_137)s]), %(hogql_val_138)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_139)s)), events__session.`$entry_utm_source`, %(hogql_val_140)s)), [%(hogql_val_141)s, %(hogql_val_142)s]), %(hogql_val_143)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_144)s)), events__session.`$entry_utm_source`, %(hogql_val_145)s)), [%(hogql_val_146)s, %(hogql_val_147)s, %(hogql_val_148)s]), %(hogql_val_149)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_150)s)), events__session.`$entry_utm_source`, %(hogql_val_151)s)), [%(hogql_val_152)s]), %(hogql_val_153)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_154)s)), events__session.`$entry_utm_source`, %(hogql_val_155)s)))))))))), and(and(equals(events.event, %(hogql_val_156)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), minus(conv_bounds.first_conversion, 345600)), lessOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), conv_bounds.last_conversion)))), -500) AS touchpoints+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, arraySlice(arraySort(groupArrayIf(tuple(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_93)s)), coalesce(accurateCastOrNull(events.properties.revenue, 'Float64'), 0.0)), and(equals(events.event, %(hogql_val_94)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_95)s), toDateTime(%(hogql_val_96)s, %(hogql_val_97)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_98)s), toDateTime64(%(hogql_val_99)s, 6, %(hogql_val_100)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_101)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_102)s), toDateTime(%(hogql_val_103)s, %(hogql_val_104)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_105)s), toDateTime64(%(hogql_val_106)s, 6, %(hogql_val_107)s)))) AS conversion_count, arraySlice(arraySort(groupUniqArrayIf(tuple(toUnixTimestamp(events__session.`$start_timestamp`), if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_108)s)), events__session.`$entry_utm_source`, %(hogql_val_109)s)), [%(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s]), %(hogql_val_113)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_114)s)), events__session.`$entry_utm_source`, %(hogql_val_115)s)), [%(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s]), %(hogql_val_124)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_125)s)), events__session.`$entry_utm_source`, %(hogql_val_126)s)), [%(hogql_val_127)s]), %(hogql_val_128)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_129)s)), events__session.`$entry_utm_source`, %(hogql_val_130)s)), [%(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s]), %(hogql_val_140)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_141)s)), events__session.`$entry_utm_source`, %(hogql_val_142)s)), [%(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s]), %(hogql_val_146)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_147)s)), events__session.`$entry_utm_source`, %(hogql_val_148)s)), [%(hogql_val_149)s]), %(hogql_val_150)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_151)s)), events__session.`$entry_utm_source`, %(hogql_val_152)s)), [%(hogql_val_153)s, %(hogql_val_154)s]), %(hogql_val_155)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_156)s)), events__session.`$entry_utm_source`, %(hogql_val_157)s)), [%(hogql_val_158)s, %(hogql_val_159)s, %(hogql_val_160)s]), %(hogql_val_161)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_162)s)), events__session.`$entry_utm_source`, %(hogql_val_163)s)), [%(hogql_val_164)s]), %(hogql_val_165)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_166)s)), events__session.`$entry_utm_source`, %(hogql_val_167)s))))))))))), and(and(equals(events.event, %(hogql_val_168)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), minus(conv_bounds.first_conversion, 345600)), lessOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), conv_bounds.last_conversion)))), -500) AS touchpointsFROM events_json AS events LEFT JOIN (- SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_68)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_69)s), %(hogql_val_70)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_74)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_75)s), %(hogql_val_76)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_71)s, %(hogql_val_72)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_73)s, 6, %(hogql_val_74)s), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_75)s, %(hogql_val_76)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_77)s, 6, %(hogql_val_78)s), toIntervalDay(3))))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_79)s)), events__session.session_id_v7) LEFT OUTER JOIN (+ WHERE and(equals(raw_sessions.team_id, 420), or(and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_77)s, %(hogql_val_78)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_79)s, 6, %(hogql_val_80)s), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_81)s, %(hogql_val_82)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_83)s, 6, %(hogql_val_84)s), toIntervalDay(3))))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_85)s)), events__session.session_id_v7) LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overridesWHERE equals(person_distinct_id_overrides.team_id, 420)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) INNER JOIN (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, min(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_80)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_81)s))) AS last_conversion+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, min(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_86)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_87)s))) AS last_conversionFROM events_json AS events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overrides@@ -99,12 +99,12 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_82)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_83)s, %(hogql_val_84)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_85)s, 6, %(hogql_val_86)s)))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_88)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_89)s, %(hogql_val_90)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_91)s, 6, %(hogql_val_92)s)))GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS conv_bounds ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), conv_bounds.person_id)- WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_157)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_158)s, %(hogql_val_159)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_160)s, 6, %(hogql_val_161)s))), and(equals(events.event, %(hogql_val_162)s), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_163)s, %(hogql_val_164)s), toIntervalSecond(345600)), 6, %(hogql_val_165)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_166)s, 6, %(hogql_val_167)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_168)s)), minus(conv_bounds.first_conversion, 345600)))))+ WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_169)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_170)s, %(hogql_val_171)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_172)s, 6, %(hogql_val_173)s))), and(equals(events.event, %(hogql_val_174)s), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_175)s, %(hogql_val_176)s), toIntervalSecond(345600)), 6, %(hogql_val_177)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_178)s, 6, %(hogql_val_179)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_180)s)), minus(conv_bounds.first_conversion, 345600)))))GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)HAVING greater(length(conversions), 0)), per_conversion AS MATERIALIZED (- SELECT person_arrays.person_id AS person_id, i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).1 AS conversion_time, (person_arrays.conversions[i]).2 AS conversion_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, conversion_time), 0), ifNull(greaterOrEquals(t.1, minus(conversion_time, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.1, tps) AS touch_ts, arrayMap(t -> t.2, tps) AS dims, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMin(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMin(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_first, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMax(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMax(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_last, arrayMap(_x -> divide(1.0, greatest(accurateCastOrNull(length(touch_ts), %(hogql_val_169)s), 1.0)), touch_ts) AS w_linear, arrayMap(w -> divide(w, greatest(arraySum(arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)), 1e-06)), arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)) AS w_decay, if(ifNull(equals(length(touch_ts), 0), 0), [], if(ifNull(equals(length(touch_ts), 1), 0), [1.0], if(ifNull(equals(length(touch_ts), 2), 0), [0.5, 0.5], arrayMap(w -> divide(w, greatest(arraySum(arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_170)s), 2.0), 1.0)))), touch_ts))), 1e-06)), arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_171)s), 2.0), 1.0)))), touch_ts)))))) AS w_position+ SELECT person_arrays.person_id AS person_id, i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).1 AS conversion_time, (person_arrays.conversions[i]).2 AS conversion_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, conversion_time), 0), ifNull(greaterOrEquals(t.1, minus(conversion_time, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.1, tps) AS touch_ts, arrayMap(t -> t.2, tps) AS dims, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMin(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMin(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_first, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMax(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMax(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_last, arrayMap(_x -> divide(1.0, greatest(accurateCastOrNull(length(touch_ts), %(hogql_val_181)s), 1.0)), touch_ts) AS w_linear, arrayMap(w -> divide(w, greatest(arraySum(arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)), 1e-06)), arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)) AS w_decay, if(ifNull(equals(length(touch_ts), 0), 0), [], if(ifNull(equals(length(touch_ts), 1), 0), [1.0], if(ifNull(equals(length(touch_ts), 2), 0), [0.5, 0.5], arrayMap(w -> divide(w, greatest(arraySum(arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_182)s), 2.0), 1.0)))), touch_ts))), 1e-06)), arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_183)s), 2.0), 1.0)))), touch_ts)))))) AS w_positionFROM person_arrays ARRAY JOIN arrayEnumerate(person_arrays.conversions) AS i), per_touchpoint AS (SELECT per_conversion.person_id AS person_id, per_conversion.i AS i, per_conversion.conversion_value AS conversion_value, per_conversion.dims[k] AS breakdown_value, per_conversion.w_first[k] AS w_first, per_conversion.w_last[k] AS w_last, per_conversion.w_linear[k] AS w_linear, per_conversion.w_decay[k] AS w_decay, per_conversion.w_position[k] AS w_positionFROM per_conversion ARRAY JOIN arrayEnumerate(per_conversion.touch_ts) AS k), per_conversion_dim AS (@@ -114,7 +114,7 @@SELECT per_conversion_dim.breakdown_value AS breakdown_value, count() AS influenced_conversions, sum(per_conversion_dim.conv_value) AS influenced_value, sum(per_conversion_dim.w_first) AS w_first_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_first)) AS w_first_value, sum(per_conversion_dim.w_last) AS w_last_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_last)) AS w_last_value, sum(per_conversion_dim.w_linear) AS w_linear_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_linear)) AS w_linear_value, sum(per_conversion_dim.w_decay) AS w_decay_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_decay)) AS w_decay_value, sum(per_conversion_dim.w_position) AS w_position_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_position)) AS w_position_valueFROM per_conversion_dimGROUP BY per_conversion_dim.breakdown_value), attribution_rows AS (- SELECT coalesce(nullIf(attribution_totals.breakdown_value, %(hogql_val_172)s), influenced_reach.breakdown_value) AS breakdown_value, ifNull(influenced_reach.visitors, 0) AS visitors, ifNull(attribution_totals.influenced_conversions, 0) AS influenced_conversions, ifNull(attribution_totals.influenced_value, 0.0) AS influenced_value, ifNull(attribution_totals.w_first_conversions, 0.0) AS w_first_conversions, ifNull(attribution_totals.w_first_value, 0.0) AS w_first_value, ifNull(attribution_totals.w_last_conversions, 0.0) AS w_last_conversions, ifNull(attribution_totals.w_last_value, 0.0) AS w_last_value, ifNull(attribution_totals.w_linear_conversions, 0.0) AS w_linear_conversions, ifNull(attribution_totals.w_linear_value, 0.0) AS w_linear_value, ifNull(attribution_totals.w_decay_conversions, 0.0) AS w_decay_conversions, ifNull(attribution_totals.w_decay_value, 0.0) AS w_decay_value, ifNull(attribution_totals.w_position_conversions, 0.0) AS w_position_conversions, ifNull(attribution_totals.w_position_value, 0.0) AS w_position_value, 1 AS footer_key+ SELECT coalesce(nullIf(attribution_totals.breakdown_value, %(hogql_val_184)s), influenced_reach.breakdown_value) AS breakdown_value, ifNull(influenced_reach.visitors, 0) AS visitors, ifNull(attribution_totals.influenced_conversions, 0) AS influenced_conversions, ifNull(attribution_totals.influenced_value, 0.0) AS influenced_value, ifNull(attribution_totals.w_first_conversions, 0.0) AS w_first_conversions, ifNull(attribution_totals.w_first_value, 0.0) AS w_first_value, ifNull(attribution_totals.w_last_conversions, 0.0) AS w_last_conversions, ifNull(attribution_totals.w_last_value, 0.0) AS w_last_value, ifNull(attribution_totals.w_linear_conversions, 0.0) AS w_linear_conversions, ifNull(attribution_totals.w_linear_value, 0.0) AS w_linear_value, ifNull(attribution_totals.w_decay_conversions, 0.0) AS w_decay_conversions, ifNull(attribution_totals.w_decay_value, 0.0) AS w_decay_value, ifNull(attribution_totals.w_position_conversions, 0.0) AS w_position_conversions, ifNull(attribution_totals.w_position_value, 0.0) AS w_position_value, 1 AS footer_keyFROM attribution_totals FULL OUTER JOIN influenced_reach ON equals(attribution_totals.breakdown_value, influenced_reach.breakdown_value)), attribution_footer AS (SELECT sumIf(per_conversion.conversion_count, ifNull(equals(per_conversion.i, 1), 0)) AS total_conversions, countIf(ifNull(greater(length(per_conversion.tps), 0), 0)) AS attributed_conversions, 1 AS footer_keyFROM per_conversion)@@ -311,7 +311,7 @@GROUP BY if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)), influenced_reach AS (SELECT s.breakdown_value AS breakdown_value, uniq(s.person_id) AS visitorsFROM (- SELECT cached_sessions.person_id AS person_id, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_30)s)), cached_sessions.utm_source, %(hogql_val_31)s)), [%(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s]), %(hogql_val_35)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_36)s)), cached_sessions.utm_source, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_47)s)), cached_sessions.utm_source, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_51)s)), cached_sessions.utm_source, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s]), %(hogql_val_62)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_63)s)), cached_sessions.utm_source, %(hogql_val_64)s)), [%(hogql_val_65)s]), %(hogql_val_66)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_67)s)), cached_sessions.utm_source, %(hogql_val_68)s)), [%(hogql_val_69)s, %(hogql_val_70)s]), %(hogql_val_71)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_72)s)), cached_sessions.utm_source, %(hogql_val_73)s)), [%(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s]), %(hogql_val_77)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_78)s)), cached_sessions.utm_source, %(hogql_val_79)s)), [%(hogql_val_80)s]), %(hogql_val_81)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_82)s)), cached_sessions.utm_source, %(hogql_val_83)s))))))))) AS breakdown_value+ SELECT cached_sessions.person_id AS person_id, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_30)s)), cached_sessions.utm_source, %(hogql_val_31)s)), [%(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s]), %(hogql_val_35)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_36)s)), cached_sessions.utm_source, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_47)s)), cached_sessions.utm_source, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_51)s)), cached_sessions.utm_source, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s]), %(hogql_val_62)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_63)s)), cached_sessions.utm_source, %(hogql_val_64)s)), [%(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s]), %(hogql_val_68)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_69)s)), cached_sessions.utm_source, %(hogql_val_70)s)), [%(hogql_val_71)s]), %(hogql_val_72)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_73)s)), cached_sessions.utm_source, %(hogql_val_74)s)), [%(hogql_val_75)s, %(hogql_val_76)s]), %(hogql_val_77)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_78)s)), cached_sessions.utm_source, %(hogql_val_79)s)), [%(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s]), %(hogql_val_83)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_84)s)), cached_sessions.utm_source, %(hogql_val_85)s)), [%(hogql_val_86)s]), %(hogql_val_87)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_88)s)), cached_sessions.utm_source, %(hogql_val_89)s)))))))))) AS breakdown_valueFROM resolved_cached_sessions AS cached_sessionsWHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')))) AS sGROUP BY s.breakdown_value), person_arrays AS (@@ -321,15 +321,15 @@FROM cached_session_conversions) AS c LEFT JOIN (SELECT d.person_id AS person_id, arraySlice(arraySort(groupUniqArray(tuple(d.session_ts, d.session_dim))), -500) AS touchpointsFROM (- SELECT conv.conv_person_id AS person_id, toUnixTimestamp(cached_sessions.start_timestamp) AS session_ts, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_84)s)), cached_sessions.utm_source, %(hogql_val_85)s)), [%(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s]), %(hogql_val_89)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_90)s)), cached_sessions.utm_source, %(hogql_val_91)s)), [%(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s]), %(hogql_val_100)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_101)s)), cached_sessions.utm_source, %(hogql_val_102)s)), [%(hogql_val_103)s]), %(hogql_val_104)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_105)s)), cached_sessions.utm_source, %(hogql_val_106)s)), [%(hogql_val_107)s, %(hogql_val_108)s, %(hogql_val_109)s, %(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s, %(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s]), %(hogql_val_116)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_117)s)), cached_sessions.utm_source, %(hogql_val_118)s)), [%(hogql_val_119)s]), %(hogql_val_120)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_121)s)), cached_sessions.utm_source, %(hogql_val_122)s)), [%(hogql_val_123)s, %(hogql_val_124)s]), %(hogql_val_125)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_126)s)), cached_sessions.utm_source, %(hogql_val_127)s)), [%(hogql_val_128)s, %(hogql_val_129)s, %(hogql_val_130)s]), %(hogql_val_131)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_132)s)), cached_sessions.utm_source, %(hogql_val_133)s)), [%(hogql_val_134)s]), %(hogql_val_135)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_136)s)), cached_sessions.utm_source, %(hogql_val_137)s))))))))) AS session_dim, conv.first_conversion AS first_conversion, conv.last_conversion AS upper_bound+ SELECT conv.conv_person_id AS person_id, toUnixTimestamp(cached_sessions.start_timestamp) AS session_ts, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_90)s)), cached_sessions.utm_source, %(hogql_val_91)s)), [%(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s]), %(hogql_val_95)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_96)s)), cached_sessions.utm_source, %(hogql_val_97)s)), [%(hogql_val_98)s, %(hogql_val_99)s, %(hogql_val_100)s, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s]), %(hogql_val_106)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_107)s)), cached_sessions.utm_source, %(hogql_val_108)s)), [%(hogql_val_109)s]), %(hogql_val_110)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_111)s)), cached_sessions.utm_source, %(hogql_val_112)s)), [%(hogql_val_113)s, %(hogql_val_114)s, %(hogql_val_115)s, %(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s]), %(hogql_val_122)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_123)s)), cached_sessions.utm_source, %(hogql_val_124)s)), [%(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s]), %(hogql_val_128)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_129)s)), cached_sessions.utm_source, %(hogql_val_130)s)), [%(hogql_val_131)s]), %(hogql_val_132)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_133)s)), cached_sessions.utm_source, %(hogql_val_134)s)), [%(hogql_val_135)s, %(hogql_val_136)s]), %(hogql_val_137)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_138)s)), cached_sessions.utm_source, %(hogql_val_139)s)), [%(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s]), %(hogql_val_143)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_144)s)), cached_sessions.utm_source, %(hogql_val_145)s)), [%(hogql_val_146)s]), %(hogql_val_147)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_148)s)), cached_sessions.utm_source, %(hogql_val_149)s)))))))))) AS session_dim, conv.first_conversion AS first_conversion, conv.last_conversion AS upper_boundFROM resolved_cached_sessions AS cached_sessions INNER JOIN (SELECT cached_session_conversions.conv_person_id AS conv_person_id, cached_session_conversions.first_conversion AS first_conversion, cached_session_conversions.last_conversion AS last_conversionFROM cached_session_conversions) AS conv ON equals(cached_sessions.person_id, conv.conv_person_id)- WHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')), greaterOrEquals(toUnixTimestamp(toTimeZone(cached_sessions.max_event_timestamp, %(hogql_val_138)s)), minus(conv.first_conversion, 345600)))) AS d+ WHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')), greaterOrEquals(toUnixTimestamp(toTimeZone(cached_sessions.max_event_timestamp, %(hogql_val_150)s)), minus(conv.first_conversion, 345600)))) AS dWHERE and(ifNull(greaterOrEquals(d.session_ts, minus(d.first_conversion, 345600)), 0), ifNull(lessOrEquals(d.session_ts, d.upper_bound), 0))GROUP BY d.person_id) AS t ON equals(c.conv_person_id, t.person_id)WHERE ifNull(greater(length(c.conversions), 0), 0)), per_conversion AS MATERIALIZED (- SELECT person_arrays.person_id AS person_id, i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).1 AS conversion_time, (person_arrays.conversions[i]).2 AS conversion_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, conversion_time), 0), ifNull(greaterOrEquals(t.1, minus(conversion_time, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.1, tps) AS touch_ts, arrayMap(t -> t.2, tps) AS dims, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMin(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMin(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_first, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMax(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMax(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_last, arrayMap(_x -> divide(1.0, greatest(accurateCastOrNull(length(touch_ts), %(hogql_val_139)s), 1.0)), touch_ts) AS w_linear, arrayMap(w -> divide(w, greatest(arraySum(arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)), 1e-06)), arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)) AS w_decay, if(ifNull(equals(length(touch_ts), 0), 0), [], if(ifNull(equals(length(touch_ts), 1), 0), [1.0], if(ifNull(equals(length(touch_ts), 2), 0), [0.5, 0.5], arrayMap(w -> divide(w, greatest(arraySum(arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_140)s), 2.0), 1.0)))), touch_ts))), 1e-06)), arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_141)s), 2.0), 1.0)))), touch_ts)))))) AS w_position+ SELECT person_arrays.person_id AS person_id, i, person_arrays.conversion_count AS conversion_count, (person_arrays.conversions[i]).1 AS conversion_time, (person_arrays.conversions[i]).2 AS conversion_value, arrayFilter(t -> and(ifNull(lessOrEquals(t.1, conversion_time), 0), ifNull(greaterOrEquals(t.1, minus(conversion_time, 345600)), 0)), person_arrays.touchpoints) AS tps, arrayMap(t -> t.1, tps) AS touch_ts, arrayMap(t -> t.2, tps) AS dims, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMin(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMin(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_first, arrayMap(_j -> if(ifNull(equals(_j, indexOf(touch_ts, arrayMax(touch_ts))), isNull(_j) and isNull(indexOf(touch_ts, arrayMax(touch_ts)))), 1.0, 0.0), arrayEnumerate(touch_ts)) AS w_last, arrayMap(_x -> divide(1.0, greatest(accurateCastOrNull(length(touch_ts), %(hogql_val_151)s), 1.0)), touch_ts) AS w_linear, arrayMap(w -> divide(w, greatest(arraySum(arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)), 1e-06)), arrayMap(ts -> exp(multiply(-0.6931471805599453, divide(minus(conversion_time, ts), 86400))), touch_ts)) AS w_decay, if(ifNull(equals(length(touch_ts), 0), 0), [], if(ifNull(equals(length(touch_ts), 1), 0), [1.0], if(ifNull(equals(length(touch_ts), 2), 0), [0.5, 0.5], arrayMap(w -> divide(w, greatest(arraySum(arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_152)s), 2.0), 1.0)))), touch_ts))), 1e-06)), arrayMap(_pw -> ifNull(_pw, 0.0), arrayMap(ts -> if(ifNull(equals(ts, arrayMin(touch_ts)), isNull(ts) and isNull(arrayMin(touch_ts))), 0.4, if(ifNull(equals(ts, arrayMax(touch_ts)), isNull(ts) and isNull(arrayMax(touch_ts))), 0.4, divide(0.2, greatest(minus(accurateCastOrNull(length(touch_ts), %(hogql_val_153)s), 2.0), 1.0)))), touch_ts)))))) AS w_positionFROM person_arrays ARRAY JOIN arrayEnumerate(person_arrays.conversions) AS i), per_touchpoint AS (SELECT per_conversion.person_id AS person_id, per_conversion.i AS i, per_conversion.conversion_value AS conversion_value, per_conversion.dims[k] AS breakdown_value, per_conversion.w_first[k] AS w_first, per_conversion.w_last[k] AS w_last, per_conversion.w_linear[k] AS w_linear, per_conversion.w_decay[k] AS w_decay, per_conversion.w_position[k] AS w_positionFROM per_conversion ARRAY JOIN arrayEnumerate(per_conversion.touch_ts) AS k), per_conversion_dim AS (@@ -339,7 +339,7 @@SELECT per_conversion_dim.breakdown_value AS breakdown_value, count() AS influenced_conversions, sum(per_conversion_dim.conv_value) AS influenced_value, sum(per_conversion_dim.w_first) AS w_first_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_first)) AS w_first_value, sum(per_conversion_dim.w_last) AS w_last_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_last)) AS w_last_value, sum(per_conversion_dim.w_linear) AS w_linear_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_linear)) AS w_linear_value, sum(per_conversion_dim.w_decay) AS w_decay_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_decay)) AS w_decay_value, sum(per_conversion_dim.w_position) AS w_position_conversions, sum(multiply(per_conversion_dim.conv_value, per_conversion_dim.w_position)) AS w_position_valueFROM per_conversion_dimGROUP BY per_conversion_dim.breakdown_value), attribution_rows AS (- SELECT coalesce(nullIf(attribution_totals.breakdown_value, %(hogql_val_142)s), influenced_reach.breakdown_value) AS breakdown_value, ifNull(influenced_reach.visitors, 0) AS visitors, ifNull(attribution_totals.influenced_conversions, 0) AS influenced_conversions, ifNull(attribution_totals.influenced_value, 0.0) AS influenced_value, ifNull(attribution_totals.w_first_conversions, 0.0) AS w_first_conversions, ifNull(attribution_totals.w_first_value, 0.0) AS w_first_value, ifNull(attribution_totals.w_last_conversions, 0.0) AS w_last_conversions, ifNull(attribution_totals.w_last_value, 0.0) AS w_last_value, ifNull(attribution_totals.w_linear_conversions, 0.0) AS w_linear_conversions, ifNull(attribution_totals.w_linear_value, 0.0) AS w_linear_value, ifNull(attribution_totals.w_decay_conversions, 0.0) AS w_decay_conversions, ifNull(attribution_totals.w_decay_value, 0.0) AS w_decay_value, ifNull(attribution_totals.w_position_conversions, 0.0) AS w_position_conversions, ifNull(attribution_totals.w_position_value, 0.0) AS w_position_value, 1 AS footer_key+ SELECT coalesce(nullIf(attribution_totals.breakdown_value, %(hogql_val_154)s), influenced_reach.breakdown_value) AS breakdown_value, ifNull(influenced_reach.visitors, 0) AS visitors, ifNull(attribution_totals.influenced_conversions, 0) AS influenced_conversions, ifNull(attribution_totals.influenced_value, 0.0) AS influenced_value, ifNull(attribution_totals.w_first_conversions, 0.0) AS w_first_conversions, ifNull(attribution_totals.w_first_value, 0.0) AS w_first_value, ifNull(attribution_totals.w_last_conversions, 0.0) AS w_last_conversions, ifNull(attribution_totals.w_last_value, 0.0) AS w_last_value, ifNull(attribution_totals.w_linear_conversions, 0.0) AS w_linear_conversions, ifNull(attribution_totals.w_linear_value, 0.0) AS w_linear_value, ifNull(attribution_totals.w_decay_conversions, 0.0) AS w_decay_conversions, ifNull(attribution_totals.w_decay_value, 0.0) AS w_decay_value, ifNull(attribution_totals.w_position_conversions, 0.0) AS w_position_conversions, ifNull(attribution_totals.w_position_value, 0.0) AS w_position_value, 1 AS footer_keyFROM attribution_totals FULL OUTER JOIN influenced_reach ON equals(attribution_totals.breakdown_value, influenced_reach.breakdown_value)), attribution_footer AS (SELECT sumIf(per_conversion.conversion_count, ifNull(equals(per_conversion.i, 1), 0)) AS total_conversions, countIf(ifNull(greater(length(per_conversion.tps), 0), 0)) AS attributed_conversions, 1 AS footer_keyFROM per_conversion)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 d2b33f91eac0..46eae25d73ed 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_1FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(diff --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 c769032cddc4..c2b045173527 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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_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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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 (@@ -22,7 +22,7 @@# 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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 (@@ -40,7 +40,7 @@# 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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 (diff --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 6288e4cfa3b0..e1a4e1de6905 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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 be94b0c5a853..d7c8f6879277 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,7 +8,7 @@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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', 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 (diff --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 afd6909f803f..ef88ba1fee75 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@@ -102,7 +102,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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(diff --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 5a9bb1481609..6e36454bf950 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@@ -137,7 +137,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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -301,7 +301,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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -498,7 +498,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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(@@ -662,7 +662,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, 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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', '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(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['amazon_ads']), 'amazon', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))))))))))) AS source,count() AS conversion_0FROM(diff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_retention_query_runner.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_retention_query_runner.ambrindex e3ed51a83f22..2a6b15f8aa26 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_retention_query_runner.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_retention_query_runner.ambr@@ -6,7 +6,7 @@SELECTevents.person_id AS actor_id,min(events.session.$start_timestamp) AS cohort_at,- argMin(if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['amazon_ads']), 'amazon', if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic'))))))))), events.session.$start_timestamp) AS breakdown_value+ argMin(if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['li']), 'linkedin', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['x', 'twitter_ads', 'x_ads']), 'twitter', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['rokt_ads']), 'rokt', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['chatgpt', 'openai_ads']), 'openai', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', if(in(lower(if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')), ['amazon_ads']), 'amazon', if(notEmpty(ifNull(events.session.$entry_utm_source, '')), events.session.$entry_utm_source, 'organic')))))))))), events.session.$start_timestamp) AS breakdown_valueFROMeventsWHERE@@ -196,7 +196,7 @@# name: TestMarketingAnalyticsRetentionQueryRunner.test_retention_sql_1_source'''WITH acquisition AS MATERIALIZED (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_45)s)), events__session.`$entry_utm_source`, %(hogql_val_46)s)), [%(hogql_val_47)s, %(hogql_val_48)s]), %(hogql_val_49)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_50)s)), events__session.`$entry_utm_source`, %(hogql_val_51)s)), [%(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_60)s)), events__session.`$entry_utm_source`, %(hogql_val_61)s))))))))), events__session.`$start_timestamp`) AS breakdown_value+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_62)s)), events__session.`$entry_utm_source`, %(hogql_val_63)s)), [%(hogql_val_64)s]), %(hogql_val_65)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_66)s)), events__session.`$entry_utm_source`, %(hogql_val_67)s)))))))))), events__session.`$start_timestamp`) AS breakdown_valueFROM events LEFT JOIN (SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_0)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_1)s), %(hogql_val_2)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions@@ -208,7 +208,7 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_62)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_63)s, %(hogql_val_64)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_65)s, %(hogql_val_66)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_67)s, %(hogql_val_68)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_68)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_71)s, %(hogql_val_72)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_73)s, %(hogql_val_74)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_75)s, %(hogql_val_76)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT DISTINCT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_idFROM events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -217,9 +217,9 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_71)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_72)s, %(hogql_val_73)s), toIntervalDay(90)), 6, %(hogql_val_74)s)), less(events.timestamp, toDateTime(%(hogql_val_75)s, %(hogql_val_76)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_77)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_78)s, %(hogql_val_79)s), toIntervalDay(90)), 6, %(hogql_val_80)s)), less(events.timestamp, toDateTime(%(hogql_val_81)s, %(hogql_val_82)s))))))GROUP BY actor_id), activity AS (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, dateDiff(%(hogql_val_77)s, toStartOfWeek(toDateTime(%(hogql_val_78)s, %(hogql_val_79)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_80)s), 0)) AS activity_index+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, dateDiff(%(hogql_val_83)s, toStartOfWeek(toDateTime(%(hogql_val_84)s, %(hogql_val_85)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_86)s), 0)) AS activity_indexFROM events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overrides@@ -227,14 +227,14 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_81)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_82)s, %(hogql_val_83)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_84)s, %(hogql_val_85)s)), globalIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_87)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_88)s, %(hogql_val_89)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_90)s, %(hogql_val_91)s)), globalIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT acquisition.actor_id AS actor_idFROM acquisition)))GROUP BY actor_id, activity_index), cohort_sizes AS MATERIALIZED (- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_86)s, toStartOfWeek(toDateTime(%(hogql_val_87)s, %(hogql_val_88)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_89)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_size+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_92)s, toStartOfWeek(toDateTime(%(hogql_val_93)s, %(hogql_val_94)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_95)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_sizeFROM acquisitionGROUP BY acquisition.breakdown_value, cohort_index), matrix AS (- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_90)s, toStartOfWeek(toDateTime(%(hogql_val_91)s, %(hogql_val_92)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_93)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_94)s, toStartOfWeek(toDateTime(%(hogql_val_95)s, %(hogql_val_96)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_97)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS count+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_96)s, toStartOfWeek(toDateTime(%(hogql_val_97)s, %(hogql_val_98)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_99)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_100)s, toStartOfWeek(toDateTime(%(hogql_val_101)s, %(hogql_val_102)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_103)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS countFROM acquisition INNER JOIN activity ON equals(activity.actor_id, acquisition.actor_id)GROUP BY acquisition.breakdown_value, cohort_index, intervals_from_baseHAVING and(ifNull(greaterOrEquals(intervals_from_base, 0), 0), ifNull(less(intervals_from_base, 4), 0))), folded_sizes AS (@@ -243,7 +243,7 @@FROM cohort_sizesGROUP BY cohort_sizes.breakdown_valueORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC- LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_98)s) AS breakdown_value, cohort_sizes.cohort_index AS cohort_index, sum(cohort_sizes.cohort_size) AS cohort_size+ LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_104)s) AS breakdown_value, cohort_sizes.cohort_index AS cohort_index, sum(cohort_sizes.cohort_size) AS cohort_sizeFROM cohort_sizesGROUP BY breakdown_value, cohort_sizes.cohort_index), folded_matrix AS (SELECT if(globalIn(matrix.breakdown_value, (@@ -251,7 +251,7 @@FROM cohort_sizesGROUP BY cohort_sizes.breakdown_valueORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC- LIMIT 20)), matrix.breakdown_value, %(hogql_val_99)s) AS breakdown_value, matrix.cohort_index AS cohort_index, matrix.intervals_from_base AS intervals_from_base, sum(matrix.count) AS count+ LIMIT 20)), matrix.breakdown_value, %(hogql_val_105)s) AS breakdown_value, matrix.cohort_index AS cohort_index, matrix.intervals_from_base AS intervals_from_base, sum(matrix.count) AS countFROM matrixGROUP BY breakdown_value, matrix.cohort_index, matrix.intervals_from_base), summary AS (SELECT uniqExact(cohort_sizes.breakdown_value) AS distinct_breakdowns@@ -334,7 +334,7 @@# name: TestMarketingAnalyticsRetentionQueryRunner.test_retention_sql_3_all_users'''WITH acquisition AS MATERIALIZED (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_45)s)), events__session.`$entry_utm_source`, %(hogql_val_46)s)), [%(hogql_val_47)s, %(hogql_val_48)s]), %(hogql_val_49)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_50)s)), events__session.`$entry_utm_source`, %(hogql_val_51)s)), [%(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_60)s)), events__session.`$entry_utm_source`, %(hogql_val_61)s))))))))), events__session.`$start_timestamp`) AS breakdown_value+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_62)s)), events__session.`$entry_utm_source`, %(hogql_val_63)s)), [%(hogql_val_64)s]), %(hogql_val_65)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_66)s)), events__session.`$entry_utm_source`, %(hogql_val_67)s)))))))))), events__session.`$start_timestamp`) AS breakdown_valueFROM events LEFT JOIN (SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_0)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_1)s), %(hogql_val_2)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions@@ -346,9 +346,9 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_62)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_63)s, %(hogql_val_64)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_65)s, %(hogql_val_66)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_67)s, %(hogql_val_68)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), 0))+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_68)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_71)s, %(hogql_val_72)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_73)s, %(hogql_val_74)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_75)s, %(hogql_val_76)s)), 0))GROUP BY actor_id), activity AS (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, dateDiff(%(hogql_val_71)s, toStartOfWeek(toDateTime(%(hogql_val_72)s, %(hogql_val_73)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_74)s), 0)) AS activity_index+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, dateDiff(%(hogql_val_77)s, toStartOfWeek(toDateTime(%(hogql_val_78)s, %(hogql_val_79)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_80)s), 0)) AS activity_indexFROM events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overrides@@ -356,14 +356,14 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_75)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_76)s, %(hogql_val_77)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_78)s, %(hogql_val_79)s)), globalIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_81)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_82)s, %(hogql_val_83)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_84)s, %(hogql_val_85)s)), globalIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT acquisition.actor_id AS actor_idFROM acquisition)))GROUP BY actor_id, activity_index), cohort_sizes AS MATERIALIZED (- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_80)s, toStartOfWeek(toDateTime(%(hogql_val_81)s, %(hogql_val_82)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_83)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_size+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_86)s, toStartOfWeek(toDateTime(%(hogql_val_87)s, %(hogql_val_88)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_89)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_sizeFROM acquisitionGROUP BY acquisition.breakdown_value, cohort_index), matrix AS (- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_84)s, toStartOfWeek(toDateTime(%(hogql_val_85)s, %(hogql_val_86)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_87)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_88)s, toStartOfWeek(toDateTime(%(hogql_val_89)s, %(hogql_val_90)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_91)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS count+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_90)s, toStartOfWeek(toDateTime(%(hogql_val_91)s, %(hogql_val_92)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_93)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_94)s, toStartOfWeek(toDateTime(%(hogql_val_95)s, %(hogql_val_96)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_97)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS countFROM acquisition INNER JOIN activity ON equals(activity.actor_id, acquisition.actor_id)GROUP BY acquisition.breakdown_value, cohort_index, intervals_from_baseHAVING and(ifNull(greaterOrEquals(intervals_from_base, 0), 0), ifNull(less(intervals_from_base, 4), 0))), folded_sizes AS (@@ -372,7 +372,7 @@FROM cohort_sizesGROUP BY cohort_sizes.breakdown_valueORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC- LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_92)s) AS breakdown_value, cohort_sizes.cohort_index AS cohort_index, sum(cohort_sizes.cohort_size) AS cohort_size+ LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_98)s) AS breakdown_value, cohort_sizes.cohort_index AS cohort_index, sum(cohort_sizes.cohort_size) AS cohort_sizeFROM cohort_sizesGROUP BY breakdown_value, cohort_sizes.cohort_index), folded_matrix AS (SELECT if(globalIn(matrix.breakdown_value, (@@ -380,7 +380,7 @@FROM cohort_sizesGROUP BY cohort_sizes.breakdown_valueORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC- LIMIT 20)), matrix.breakdown_value, %(hogql_val_93)s) AS breakdown_value, matrix.cohort_index AS cohort_index, matrix.intervals_from_base AS intervals_from_base, sum(matrix.count) AS count+ LIMIT 20)), matrix.breakdown_value, %(hogql_val_99)s) AS breakdown_value, matrix.cohort_index AS cohort_index, matrix.intervals_from_base AS intervals_from_base, sum(matrix.count) AS countFROM matrixGROUP BY breakdown_value, matrix.cohort_index, matrix.intervals_from_base), summary AS (SELECT uniqExact(cohort_sizes.breakdown_value) AS distinct_breakdowns@@ -394,7 +394,7 @@# name: TestMarketingAnalyticsRetentionQueryRunner.test_retention_sql_4_summary'''WITH acquisition AS MATERIALIZED (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS first_session_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_30)s)), events__session.`$entry_utm_source`, %(hogql_val_31)s)), [%(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s]), %(hogql_val_35)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_36)s)), events__session.`$entry_utm_source`, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s]), %(hogql_val_62)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_63)s)), events__session.`$entry_utm_source`, %(hogql_val_64)s)), [%(hogql_val_65)s]), %(hogql_val_66)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_67)s)), events__session.`$entry_utm_source`, %(hogql_val_68)s)), [%(hogql_val_69)s, %(hogql_val_70)s]), %(hogql_val_71)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_72)s)), events__session.`$entry_utm_source`, %(hogql_val_73)s)), [%(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s]), %(hogql_val_77)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_78)s)), events__session.`$entry_utm_source`, %(hogql_val_79)s)), [%(hogql_val_80)s]), %(hogql_val_81)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_82)s)), events__session.`$entry_utm_source`, %(hogql_val_83)s))))))))), events__session.`$start_timestamp`) AS breakdown_value, 0 AS previous, %(hogql_val_84)s AS observation_end, argMin(events.`$session_id`, events__session.`$start_timestamp`) AS first_session_id+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS first_session_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_30)s)), events__session.`$entry_utm_source`, %(hogql_val_31)s)), [%(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s]), %(hogql_val_35)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_36)s)), events__session.`$entry_utm_source`, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s]), %(hogql_val_62)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_63)s)), events__session.`$entry_utm_source`, %(hogql_val_64)s)), [%(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s]), %(hogql_val_68)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_69)s)), events__session.`$entry_utm_source`, %(hogql_val_70)s)), [%(hogql_val_71)s]), %(hogql_val_72)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_73)s)), events__session.`$entry_utm_source`, %(hogql_val_74)s)), [%(hogql_val_75)s, %(hogql_val_76)s]), %(hogql_val_77)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_78)s)), events__session.`$entry_utm_source`, %(hogql_val_79)s)), [%(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s]), %(hogql_val_83)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_84)s)), events__session.`$entry_utm_source`, %(hogql_val_85)s)), [%(hogql_val_86)s]), %(hogql_val_87)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_88)s)), events__session.`$entry_utm_source`, %(hogql_val_89)s)))))))))), events__session.`$start_timestamp`) AS breakdown_value, 0 AS previous, %(hogql_val_90)s AS observation_end, argMin(events.`$session_id`, events__session.`$start_timestamp`) AS first_session_idFROM events LEFT JOIN (SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_22)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_23)s), %(hogql_val_24)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions@@ -406,7 +406,7 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_85)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_86)s, %(hogql_val_87)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_88)s, %(hogql_val_89)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_90)s, %(hogql_val_91)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_92)s, %(hogql_val_93)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_91)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_92)s, %(hogql_val_93)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_94)s, %(hogql_val_95)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_96)s, %(hogql_val_97)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_98)s, %(hogql_val_99)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT DISTINCT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_idFROM events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -415,21 +415,21 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_94)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_95)s, %(hogql_val_96)s), toIntervalDay(90)), 6, %(hogql_val_97)s)), less(events.timestamp, toDateTime(%(hogql_val_98)s, %(hogql_val_99)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_100)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_101)s, %(hogql_val_102)s), toIntervalDay(90)), 6, %(hogql_val_103)s)), less(events.timestamp, toDateTime(%(hogql_val_104)s, %(hogql_val_105)s))))))GROUP BY actor_id UNION ALL- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS first_session_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_108)s)), events__session.`$entry_utm_source`, %(hogql_val_109)s)), [%(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s]), %(hogql_val_113)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_114)s)), events__session.`$entry_utm_source`, %(hogql_val_115)s)), [%(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s]), %(hogql_val_124)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_125)s)), events__session.`$entry_utm_source`, %(hogql_val_126)s)), [%(hogql_val_127)s]), %(hogql_val_128)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_129)s)), events__session.`$entry_utm_source`, %(hogql_val_130)s)), [%(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s]), %(hogql_val_140)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_141)s)), events__session.`$entry_utm_source`, %(hogql_val_142)s)), [%(hogql_val_143)s]), %(hogql_val_144)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_145)s)), events__session.`$entry_utm_source`, %(hogql_val_146)s)), [%(hogql_val_147)s, %(hogql_val_148)s]), %(hogql_val_149)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_150)s)), events__session.`$entry_utm_source`, %(hogql_val_151)s)), [%(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s]), %(hogql_val_155)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_156)s)), events__session.`$entry_utm_source`, %(hogql_val_157)s)), [%(hogql_val_158)s]), %(hogql_val_159)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_160)s)), events__session.`$entry_utm_source`, %(hogql_val_161)s))))))))), events__session.`$start_timestamp`) AS breakdown_value, 1 AS previous, %(hogql_val_162)s AS observation_end, argMin(events.`$session_id`, events__session.`$start_timestamp`) AS first_session_id+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS first_session_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_114)s)), events__session.`$entry_utm_source`, %(hogql_val_115)s)), [%(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s]), %(hogql_val_119)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_120)s)), events__session.`$entry_utm_source`, %(hogql_val_121)s)), [%(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s]), %(hogql_val_130)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_131)s)), events__session.`$entry_utm_source`, %(hogql_val_132)s)), [%(hogql_val_133)s]), %(hogql_val_134)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_135)s)), events__session.`$entry_utm_source`, %(hogql_val_136)s)), [%(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s]), %(hogql_val_146)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_147)s)), events__session.`$entry_utm_source`, %(hogql_val_148)s)), [%(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s]), %(hogql_val_152)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_153)s)), events__session.`$entry_utm_source`, %(hogql_val_154)s)), [%(hogql_val_155)s]), %(hogql_val_156)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_157)s)), events__session.`$entry_utm_source`, %(hogql_val_158)s)), [%(hogql_val_159)s, %(hogql_val_160)s]), %(hogql_val_161)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_162)s)), events__session.`$entry_utm_source`, %(hogql_val_163)s)), [%(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s]), %(hogql_val_167)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_168)s)), events__session.`$entry_utm_source`, %(hogql_val_169)s)), [%(hogql_val_170)s]), %(hogql_val_171)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_172)s)), events__session.`$entry_utm_source`, %(hogql_val_173)s)))))))))), events__session.`$start_timestamp`) AS breakdown_value, 1 AS previous, %(hogql_val_174)s AS observation_end, argMin(events.`$session_id`, events__session.`$start_timestamp`) AS first_session_idFROM events LEFT JOIN (- SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_100)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_101)s), %(hogql_val_102)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_106)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_107)s), %(hogql_val_108)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_103)s, %(hogql_val_104)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_105)s, %(hogql_val_106)s), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_107)s)), events__session.session_id_v7) LEFT OUTER JOIN (+ WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_109)s, %(hogql_val_110)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_111)s, %(hogql_val_112)s), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_113)s)), events__session.session_id_v7) LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overridesWHERE equals(person_distinct_id_overrides.team_id, 420)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_163)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_164)s, %(hogql_val_165)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_166)s, %(hogql_val_167)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_168)s, %(hogql_val_169)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_170)s, %(hogql_val_171)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_175)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_176)s, %(hogql_val_177)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_178)s, %(hogql_val_179)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_180)s, %(hogql_val_181)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_182)s, %(hogql_val_183)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT DISTINCT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_idFROM events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -438,23 +438,23 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_172)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_173)s, %(hogql_val_174)s), toIntervalDay(90)), 6, %(hogql_val_175)s)), less(events.timestamp, toDateTime(%(hogql_val_176)s, %(hogql_val_177)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_184)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_185)s, %(hogql_val_186)s), toIntervalDay(90)), 6, %(hogql_val_187)s)), less(events.timestamp, toDateTime(%(hogql_val_188)s, %(hogql_val_189)s))))))GROUP BY actor_id), activity AS (SELECT acquisition.actor_id AS actor_id, acquisition.previous AS previous, min(events__session.`$start_timestamp`) AS returned_atFROM events LEFT JOIN (- SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_178)s)) AS `$start_timestamp`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_190)s)) AS `$start_timestamp`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_179)s, %(hogql_val_180)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_181)s, %(hogql_val_182)s), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_183)s)), events__session.session_id_v7) LEFT OUTER JOIN (+ WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_191)s, %(hogql_val_192)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_193)s, %(hogql_val_194)s), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_195)s)), events__session.session_id_v7) LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overridesWHERE equals(person_distinct_id_overrides.team_id, 420)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) GLOBAL INNER JOIN acquisition ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), acquisition.actor_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_184)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_185)s, %(hogql_val_186)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_187)s, %(hogql_val_188)s)), notEquals(events.`$session_id`, acquisition.first_session_id), greater(toDate(events__session.`$start_timestamp`), toDate(toTimeZone(acquisition.first_session_at, %(hogql_val_189)s))), lessOrEquals(events__session.`$start_timestamp`, plus(toTimeZone(acquisition.first_session_at, %(hogql_val_190)s), toIntervalDay(30))), ifNull(lessOrEquals(events__session.`$start_timestamp`, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_191)s)), 0))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_196)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_197)s, %(hogql_val_198)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_199)s, %(hogql_val_200)s)), notEquals(events.`$session_id`, acquisition.first_session_id), greater(toDate(events__session.`$start_timestamp`), toDate(toTimeZone(acquisition.first_session_at, %(hogql_val_201)s))), lessOrEquals(events__session.`$start_timestamp`, plus(toTimeZone(acquisition.first_session_at, %(hogql_val_202)s), toIntervalDay(30))), ifNull(lessOrEquals(events__session.`$start_timestamp`, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_203)s)), 0))GROUP BY actor_id, previous), people AS MATERIALIZED (- SELECT acquisition.actor_id AS actor_id, acquisition.breakdown_value AS breakdown_value, acquisition.previous AS previous, toTimeZone(acquisition.first_session_at, %(hogql_val_192)s) AS first_session_at, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_193)s) AS observation_end, toTimeZone(activity.returned_at, %(hogql_val_194)s) AS returned_at+ SELECT acquisition.actor_id AS actor_id, acquisition.breakdown_value AS breakdown_value, acquisition.previous AS previous, toTimeZone(acquisition.first_session_at, %(hogql_val_204)s) AS first_session_at, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_205)s) AS observation_end, toTimeZone(activity.returned_at, %(hogql_val_206)s) AS returned_atFROM acquisition LEFT JOIN activity ON and(equals(acquisition.actor_id, activity.actor_id), equals(acquisition.previous, activity.previous)))SELECT if(globalIn(people.breakdown_value, (SELECT people.breakdown_value AS breakdown_valuediff --git a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_retention_query_runner.new_events_schema.ambr b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_retention_query_runner.new_events_schema.ambrindex 0e28bd78d717..5af8f0afae57 100644--- a/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_retention_query_runner.new_events_schema.ambr+++ b/products/marketing_analytics/backend/hogql_queries/__snapshots__/test_marketing_retention_query_runner.new_events_schema.ambr@@ -71,7 +71,7 @@# name: TestMarketingAnalyticsRetentionQueryRunner.test_retention_sql_1_source[new_events_schema]'''WITH acquisition AS MATERIALIZED (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_45)s)), events__session.`$entry_utm_source`, %(hogql_val_46)s)), [%(hogql_val_47)s, %(hogql_val_48)s]), %(hogql_val_49)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_50)s)), events__session.`$entry_utm_source`, %(hogql_val_51)s)), [%(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_60)s)), events__session.`$entry_utm_source`, %(hogql_val_61)s))))))))), events__session.`$start_timestamp`) AS breakdown_value+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_62)s)), events__session.`$entry_utm_source`, %(hogql_val_63)s)), [%(hogql_val_64)s]), %(hogql_val_65)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_66)s)), events__session.`$entry_utm_source`, %(hogql_val_67)s)))))))))), events__session.`$start_timestamp`) AS breakdown_valueFROM events_json AS events LEFT JOIN (SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_0)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_1)s), %(hogql_val_2)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions@@ -83,7 +83,7 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_62)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_63)s, %(hogql_val_64)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_65)s, %(hogql_val_66)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_67)s, %(hogql_val_68)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_68)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_71)s, %(hogql_val_72)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_73)s, %(hogql_val_74)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_75)s, %(hogql_val_76)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT DISTINCT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_idFROM events_json AS events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -92,9 +92,9 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_71)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_72)s, %(hogql_val_73)s), toIntervalDay(90)), 6, %(hogql_val_74)s)), less(events.timestamp, toDateTime(%(hogql_val_75)s, %(hogql_val_76)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_77)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_78)s, %(hogql_val_79)s), toIntervalDay(90)), 6, %(hogql_val_80)s)), less(events.timestamp, toDateTime(%(hogql_val_81)s, %(hogql_val_82)s))))))GROUP BY actor_id), activity AS (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, dateDiff(%(hogql_val_77)s, toStartOfWeek(toDateTime(%(hogql_val_78)s, %(hogql_val_79)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_80)s), 0)) AS activity_index+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, dateDiff(%(hogql_val_83)s, toStartOfWeek(toDateTime(%(hogql_val_84)s, %(hogql_val_85)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_86)s), 0)) AS activity_indexFROM events_json AS events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overrides@@ -102,14 +102,14 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_81)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_82)s, %(hogql_val_83)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_84)s, %(hogql_val_85)s)), globalIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_87)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_88)s, %(hogql_val_89)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_90)s, %(hogql_val_91)s)), globalIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT acquisition.actor_id AS actor_idFROM acquisition)))GROUP BY actor_id, activity_index), cohort_sizes AS MATERIALIZED (- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_86)s, toStartOfWeek(toDateTime(%(hogql_val_87)s, %(hogql_val_88)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_89)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_size+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_92)s, toStartOfWeek(toDateTime(%(hogql_val_93)s, %(hogql_val_94)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_95)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_sizeFROM acquisitionGROUP BY acquisition.breakdown_value, cohort_index), matrix AS (- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_90)s, toStartOfWeek(toDateTime(%(hogql_val_91)s, %(hogql_val_92)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_93)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_94)s, toStartOfWeek(toDateTime(%(hogql_val_95)s, %(hogql_val_96)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_97)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS count+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_96)s, toStartOfWeek(toDateTime(%(hogql_val_97)s, %(hogql_val_98)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_99)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_100)s, toStartOfWeek(toDateTime(%(hogql_val_101)s, %(hogql_val_102)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_103)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS countFROM acquisition INNER JOIN activity ON equals(activity.actor_id, acquisition.actor_id)GROUP BY acquisition.breakdown_value, cohort_index, intervals_from_baseHAVING and(ifNull(greaterOrEquals(intervals_from_base, 0), 0), ifNull(less(intervals_from_base, 4), 0))), folded_sizes AS (@@ -118,7 +118,7 @@FROM cohort_sizesGROUP BY cohort_sizes.breakdown_valueORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC- LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_98)s) AS breakdown_value, cohort_sizes.cohort_index AS cohort_index, sum(cohort_sizes.cohort_size) AS cohort_size+ LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_104)s) AS breakdown_value, cohort_sizes.cohort_index AS cohort_index, sum(cohort_sizes.cohort_size) AS cohort_sizeFROM cohort_sizesGROUP BY breakdown_value, cohort_sizes.cohort_index), folded_matrix AS (SELECT if(globalIn(matrix.breakdown_value, (@@ -126,7 +126,7 @@FROM cohort_sizesGROUP BY cohort_sizes.breakdown_valueORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC- LIMIT 20)), matrix.breakdown_value, %(hogql_val_99)s) AS breakdown_value, matrix.cohort_index AS cohort_index, matrix.intervals_from_base AS intervals_from_base, sum(matrix.count) AS count+ LIMIT 20)), matrix.breakdown_value, %(hogql_val_105)s) AS breakdown_value, matrix.cohort_index AS cohort_index, matrix.intervals_from_base AS intervals_from_base, sum(matrix.count) AS countFROM matrixGROUP BY breakdown_value, matrix.cohort_index, matrix.intervals_from_base), summary AS (SELECT uniqExact(cohort_sizes.breakdown_value) AS distinct_breakdowns@@ -209,7 +209,7 @@# name: TestMarketingAnalyticsRetentionQueryRunner.test_retention_sql_3_all_users[new_events_schema]'''WITH acquisition AS MATERIALIZED (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_45)s)), events__session.`$entry_utm_source`, %(hogql_val_46)s)), [%(hogql_val_47)s, %(hogql_val_48)s]), %(hogql_val_49)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_50)s)), events__session.`$entry_utm_source`, %(hogql_val_51)s)), [%(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_60)s)), events__session.`$entry_utm_source`, %(hogql_val_61)s))))))))), events__session.`$start_timestamp`) AS breakdown_value+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_56)s)), events__session.`$entry_utm_source`, %(hogql_val_57)s)), [%(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_62)s)), events__session.`$entry_utm_source`, %(hogql_val_63)s)), [%(hogql_val_64)s]), %(hogql_val_65)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_66)s)), events__session.`$entry_utm_source`, %(hogql_val_67)s)))))))))), events__session.`$start_timestamp`) AS breakdown_valueFROM events_json AS events LEFT JOIN (SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_0)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_1)s), %(hogql_val_2)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions@@ -221,9 +221,9 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_62)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_63)s, %(hogql_val_64)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_65)s, %(hogql_val_66)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_67)s, %(hogql_val_68)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), 0))+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_68)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_71)s, %(hogql_val_72)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_73)s, %(hogql_val_74)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_75)s, %(hogql_val_76)s)), 0))GROUP BY actor_id), activity AS (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, dateDiff(%(hogql_val_71)s, toStartOfWeek(toDateTime(%(hogql_val_72)s, %(hogql_val_73)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_74)s), 0)) AS activity_index+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, dateDiff(%(hogql_val_77)s, toStartOfWeek(toDateTime(%(hogql_val_78)s, %(hogql_val_79)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_80)s), 0)) AS activity_indexFROM events_json AS events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overrides@@ -231,14 +231,14 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_75)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_76)s, %(hogql_val_77)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_78)s, %(hogql_val_79)s)), globalIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_81)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_82)s, %(hogql_val_83)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_84)s, %(hogql_val_85)s)), globalIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT acquisition.actor_id AS actor_idFROM acquisition)))GROUP BY actor_id, activity_index), cohort_sizes AS MATERIALIZED (- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_80)s, toStartOfWeek(toDateTime(%(hogql_val_81)s, %(hogql_val_82)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_83)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_size+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_86)s, toStartOfWeek(toDateTime(%(hogql_val_87)s, %(hogql_val_88)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_89)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_sizeFROM acquisitionGROUP BY acquisition.breakdown_value, cohort_index), matrix AS (- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_84)s, toStartOfWeek(toDateTime(%(hogql_val_85)s, %(hogql_val_86)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_87)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_88)s, toStartOfWeek(toDateTime(%(hogql_val_89)s, %(hogql_val_90)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_91)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS count+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_90)s, toStartOfWeek(toDateTime(%(hogql_val_91)s, %(hogql_val_92)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_93)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_94)s, toStartOfWeek(toDateTime(%(hogql_val_95)s, %(hogql_val_96)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_97)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS countFROM acquisition INNER JOIN activity ON equals(activity.actor_id, acquisition.actor_id)GROUP BY acquisition.breakdown_value, cohort_index, intervals_from_baseHAVING and(ifNull(greaterOrEquals(intervals_from_base, 0), 0), ifNull(less(intervals_from_base, 4), 0))), folded_sizes AS (@@ -247,7 +247,7 @@FROM cohort_sizesGROUP BY cohort_sizes.breakdown_valueORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC- LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_92)s) AS breakdown_value, cohort_sizes.cohort_index AS cohort_index, sum(cohort_sizes.cohort_size) AS cohort_size+ LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_98)s) AS breakdown_value, cohort_sizes.cohort_index AS cohort_index, sum(cohort_sizes.cohort_size) AS cohort_sizeFROM cohort_sizesGROUP BY breakdown_value, cohort_sizes.cohort_index), folded_matrix AS (SELECT if(globalIn(matrix.breakdown_value, (@@ -255,7 +255,7 @@FROM cohort_sizesGROUP BY cohort_sizes.breakdown_valueORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC- LIMIT 20)), matrix.breakdown_value, %(hogql_val_93)s) AS breakdown_value, matrix.cohort_index AS cohort_index, matrix.intervals_from_base AS intervals_from_base, sum(matrix.count) AS count+ LIMIT 20)), matrix.breakdown_value, %(hogql_val_99)s) AS breakdown_value, matrix.cohort_index AS cohort_index, matrix.intervals_from_base AS intervals_from_base, sum(matrix.count) AS countFROM matrixGROUP BY breakdown_value, matrix.cohort_index, matrix.intervals_from_base), summary AS (SELECT uniqExact(cohort_sizes.breakdown_value) AS distinct_breakdowns@@ -269,7 +269,7 @@# name: TestMarketingAnalyticsRetentionQueryRunner.test_retention_sql_4_summary[new_events_schema]'''WITH acquisition AS MATERIALIZED (- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS first_session_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_30)s)), events__session.`$entry_utm_source`, %(hogql_val_31)s)), [%(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s]), %(hogql_val_35)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_36)s)), events__session.`$entry_utm_source`, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s]), %(hogql_val_62)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_63)s)), events__session.`$entry_utm_source`, %(hogql_val_64)s)), [%(hogql_val_65)s]), %(hogql_val_66)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_67)s)), events__session.`$entry_utm_source`, %(hogql_val_68)s)), [%(hogql_val_69)s, %(hogql_val_70)s]), %(hogql_val_71)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_72)s)), events__session.`$entry_utm_source`, %(hogql_val_73)s)), [%(hogql_val_74)s, %(hogql_val_75)s, %(hogql_val_76)s]), %(hogql_val_77)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_78)s)), events__session.`$entry_utm_source`, %(hogql_val_79)s)), [%(hogql_val_80)s]), %(hogql_val_81)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_82)s)), events__session.`$entry_utm_source`, %(hogql_val_83)s))))))))), events__session.`$start_timestamp`) AS breakdown_value, 0 AS previous, %(hogql_val_84)s AS observation_end, argMin(events.properties.`$session_id`, events__session.`$start_timestamp`) AS first_session_id+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS first_session_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_30)s)), events__session.`$entry_utm_source`, %(hogql_val_31)s)), [%(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s]), %(hogql_val_35)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_36)s)), events__session.`$entry_utm_source`, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s]), %(hogql_val_62)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_63)s)), events__session.`$entry_utm_source`, %(hogql_val_64)s)), [%(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s]), %(hogql_val_68)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_69)s)), events__session.`$entry_utm_source`, %(hogql_val_70)s)), [%(hogql_val_71)s]), %(hogql_val_72)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_73)s)), events__session.`$entry_utm_source`, %(hogql_val_74)s)), [%(hogql_val_75)s, %(hogql_val_76)s]), %(hogql_val_77)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_78)s)), events__session.`$entry_utm_source`, %(hogql_val_79)s)), [%(hogql_val_80)s, %(hogql_val_81)s, %(hogql_val_82)s]), %(hogql_val_83)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_84)s)), events__session.`$entry_utm_source`, %(hogql_val_85)s)), [%(hogql_val_86)s]), %(hogql_val_87)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_88)s)), events__session.`$entry_utm_source`, %(hogql_val_89)s)))))))))), events__session.`$start_timestamp`) AS breakdown_value, 0 AS previous, %(hogql_val_90)s AS observation_end, argMin(events.properties.`$session_id`, events__session.`$start_timestamp`) AS first_session_idFROM events_json AS events LEFT JOIN (SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_22)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_23)s), %(hogql_val_24)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions@@ -281,7 +281,7 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_85)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_86)s, %(hogql_val_87)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_88)s, %(hogql_val_89)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_90)s, %(hogql_val_91)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_92)s, %(hogql_val_93)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_91)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_92)s, %(hogql_val_93)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_94)s, %(hogql_val_95)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_96)s, %(hogql_val_97)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_98)s, %(hogql_val_99)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT DISTINCT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_idFROM events_json AS events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -290,21 +290,21 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_94)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_95)s, %(hogql_val_96)s), toIntervalDay(90)), 6, %(hogql_val_97)s)), less(events.timestamp, toDateTime(%(hogql_val_98)s, %(hogql_val_99)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_100)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_101)s, %(hogql_val_102)s), toIntervalDay(90)), 6, %(hogql_val_103)s)), less(events.timestamp, toDateTime(%(hogql_val_104)s, %(hogql_val_105)s))))))GROUP BY actor_id UNION ALL- SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS first_session_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_108)s)), events__session.`$entry_utm_source`, %(hogql_val_109)s)), [%(hogql_val_110)s, %(hogql_val_111)s, %(hogql_val_112)s]), %(hogql_val_113)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_114)s)), events__session.`$entry_utm_source`, %(hogql_val_115)s)), [%(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s, %(hogql_val_120)s, %(hogql_val_121)s, %(hogql_val_122)s, %(hogql_val_123)s]), %(hogql_val_124)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_125)s)), events__session.`$entry_utm_source`, %(hogql_val_126)s)), [%(hogql_val_127)s]), %(hogql_val_128)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_129)s)), events__session.`$entry_utm_source`, %(hogql_val_130)s)), [%(hogql_val_131)s, %(hogql_val_132)s, %(hogql_val_133)s, %(hogql_val_134)s, %(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s]), %(hogql_val_140)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_141)s)), events__session.`$entry_utm_source`, %(hogql_val_142)s)), [%(hogql_val_143)s]), %(hogql_val_144)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_145)s)), events__session.`$entry_utm_source`, %(hogql_val_146)s)), [%(hogql_val_147)s, %(hogql_val_148)s]), %(hogql_val_149)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_150)s)), events__session.`$entry_utm_source`, %(hogql_val_151)s)), [%(hogql_val_152)s, %(hogql_val_153)s, %(hogql_val_154)s]), %(hogql_val_155)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_156)s)), events__session.`$entry_utm_source`, %(hogql_val_157)s)), [%(hogql_val_158)s]), %(hogql_val_159)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_160)s)), events__session.`$entry_utm_source`, %(hogql_val_161)s))))))))), events__session.`$start_timestamp`) AS breakdown_value, 1 AS previous, %(hogql_val_162)s AS observation_end, argMin(events.properties.`$session_id`, events__session.`$start_timestamp`) AS first_session_id+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS first_session_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_114)s)), events__session.`$entry_utm_source`, %(hogql_val_115)s)), [%(hogql_val_116)s, %(hogql_val_117)s, %(hogql_val_118)s]), %(hogql_val_119)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_120)s)), events__session.`$entry_utm_source`, %(hogql_val_121)s)), [%(hogql_val_122)s, %(hogql_val_123)s, %(hogql_val_124)s, %(hogql_val_125)s, %(hogql_val_126)s, %(hogql_val_127)s, %(hogql_val_128)s, %(hogql_val_129)s]), %(hogql_val_130)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_131)s)), events__session.`$entry_utm_source`, %(hogql_val_132)s)), [%(hogql_val_133)s]), %(hogql_val_134)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_135)s)), events__session.`$entry_utm_source`, %(hogql_val_136)s)), [%(hogql_val_137)s, %(hogql_val_138)s, %(hogql_val_139)s, %(hogql_val_140)s, %(hogql_val_141)s, %(hogql_val_142)s, %(hogql_val_143)s, %(hogql_val_144)s, %(hogql_val_145)s]), %(hogql_val_146)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_147)s)), events__session.`$entry_utm_source`, %(hogql_val_148)s)), [%(hogql_val_149)s, %(hogql_val_150)s, %(hogql_val_151)s]), %(hogql_val_152)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_153)s)), events__session.`$entry_utm_source`, %(hogql_val_154)s)), [%(hogql_val_155)s]), %(hogql_val_156)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_157)s)), events__session.`$entry_utm_source`, %(hogql_val_158)s)), [%(hogql_val_159)s, %(hogql_val_160)s]), %(hogql_val_161)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_162)s)), events__session.`$entry_utm_source`, %(hogql_val_163)s)), [%(hogql_val_164)s, %(hogql_val_165)s, %(hogql_val_166)s]), %(hogql_val_167)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_168)s)), events__session.`$entry_utm_source`, %(hogql_val_169)s)), [%(hogql_val_170)s]), %(hogql_val_171)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_172)s)), events__session.`$entry_utm_source`, %(hogql_val_173)s)))))))))), events__session.`$start_timestamp`) AS breakdown_value, 1 AS previous, %(hogql_val_174)s AS observation_end, argMin(events.properties.`$session_id`, events__session.`$start_timestamp`) AS first_session_idFROM events_json AS events LEFT JOIN (- SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_100)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_101)s), %(hogql_val_102)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_106)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_107)s), %(hogql_val_108)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_103)s, %(hogql_val_104)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_105)s, %(hogql_val_106)s), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_107)s)), events__session.session_id_v7) LEFT OUTER JOIN (+ WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_109)s, %(hogql_val_110)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_111)s, %(hogql_val_112)s), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_113)s)), events__session.session_id_v7) LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overridesWHERE equals(person_distinct_id_overrides.team_id, 420)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_163)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_164)s, %(hogql_val_165)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_166)s, %(hogql_val_167)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_168)s, %(hogql_val_169)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_170)s, %(hogql_val_171)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_175)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_176)s, %(hogql_val_177)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_178)s, %(hogql_val_179)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_180)s, %(hogql_val_181)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_182)s, %(hogql_val_183)s)), 0), globalNotIn(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), (SELECT DISTINCT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_idFROM events_json AS events LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_id@@ -313,23 +313,23 @@GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_172)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_173)s, %(hogql_val_174)s), toIntervalDay(90)), 6, %(hogql_val_175)s)), less(events.timestamp, toDateTime(%(hogql_val_176)s, %(hogql_val_177)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_184)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime64(minus(toDateTime(%(hogql_val_185)s, %(hogql_val_186)s), toIntervalDay(90)), 6, %(hogql_val_187)s)), less(events.timestamp, toDateTime(%(hogql_val_188)s, %(hogql_val_189)s))))))GROUP BY actor_id), activity AS (SELECT acquisition.actor_id AS actor_id, acquisition.previous AS previous, min(events__session.`$start_timestamp`) AS returned_atFROM events_json AS events LEFT JOIN (- SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_178)s)) AS `$start_timestamp`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_190)s)) AS `$start_timestamp`, raw_sessions.session_id_v7 AS session_id_v7FROM raw_sessions- WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_179)s, %(hogql_val_180)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_181)s, %(hogql_val_182)s), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_183)s)), events__session.session_id_v7) LEFT OUTER JOIN (+ WHERE and(equals(raw_sessions.team_id, 420), greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(toDateTime(%(hogql_val_191)s, %(hogql_val_192)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_193)s, %(hogql_val_194)s), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_195)s)), events__session.session_id_v7) LEFT OUTER JOIN (SELECT argMax(person_distinct_id_overrides.person_id, person_distinct_id_overrides.version) AS person_id, person_distinct_id_overrides.distinct_id AS distinct_idFROM person_distinct_id_overridesWHERE equals(person_distinct_id_overrides.team_id, 420)GROUP BY person_distinct_id_overrides.distinct_idHAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id) GLOBAL INNER JOIN acquisition ON equals(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id), acquisition.actor_id)- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_184)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_185)s, %(hogql_val_186)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_187)s, %(hogql_val_188)s)), notEquals(events.properties.`$session_id`, acquisition.first_session_id), greater(toDate(events__session.`$start_timestamp`), toDate(toTimeZone(acquisition.first_session_at, %(hogql_val_189)s))), lessOrEquals(events__session.`$start_timestamp`, plus(toTimeZone(acquisition.first_session_at, %(hogql_val_190)s), toIntervalDay(30))), ifNull(lessOrEquals(events__session.`$start_timestamp`, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_191)s)), 0))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_196)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_197)s, %(hogql_val_198)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_199)s, %(hogql_val_200)s)), notEquals(events.properties.`$session_id`, acquisition.first_session_id), greater(toDate(events__session.`$start_timestamp`), toDate(toTimeZone(acquisition.first_session_at, %(hogql_val_201)s))), lessOrEquals(events__session.`$start_timestamp`, plus(toTimeZone(acquisition.first_session_at, %(hogql_val_202)s), toIntervalDay(30))), ifNull(lessOrEquals(events__session.`$start_timestamp`, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_203)s)), 0))GROUP BY actor_id, previous), people AS MATERIALIZED (- SELECT acquisition.actor_id AS actor_id, acquisition.breakdown_value AS breakdown_value, acquisition.previous AS previous, toTimeZone(acquisition.first_session_at, %(hogql_val_192)s) AS first_session_at, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_193)s) AS observation_end, toTimeZone(activity.returned_at, %(hogql_val_194)s) AS returned_at+ SELECT acquisition.actor_id AS actor_id, acquisition.breakdown_value AS breakdown_value, acquisition.previous AS previous, toTimeZone(acquisition.first_session_at, %(hogql_val_204)s) AS first_session_at, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_205)s) AS observation_end, toTimeZone(activity.returned_at, %(hogql_val_206)s) AS returned_atFROM acquisition LEFT JOIN activity ON and(equals(acquisition.actor_id, activity.actor_id), equals(acquisition.previous, activity.previous)))SELECT if(globalIn(people.breakdown_value, (SELECT people.breakdown_value AS breakdown_valuediff --git a/products/marketing_analytics/backend/hogql_queries/adapters/factory.py b/products/marketing_analytics/backend/hogql_queries/adapters/factory.pyindex 9bd33298e2a8..3b5bb8ed8ee8 100644--- a/products/marketing_analytics/backend/hogql_queries/adapters/factory.py+++ b/products/marketing_analytics/backend/hogql_queries/adapters/factory.py@@ -52,6 +52,7 @@ from .google_ads import GoogleAdsAdapterfrom .openai_ads import OpenAIAdsAdapterfrom .rokt_ads import RoktAdsAdapterfrom .self_managed import AWSAdapter, AzureAdapter, CloudflareR2Adapter, GoogleCloudAdapter+from .twitter_ads import TwitterAdsAdapterlogger = structlog.get_logger(__name__)@@ -85,6 +86,7 @@ class MarketingSourceFactory:"AppleSearchAds": AppleSearchAdsAdapter,"OpenAIAds": OpenAIAdsAdapter,"RoktAds": RoktAdsAdapter,+ "TwitterAds": TwitterAdsAdapter,"GoogleAds": GoogleAdsAdapter,"LinkedinAds": LinkedinAdsAdapter,"RedditAds": RedditAdsAdapter,@@ -109,6 +111,7 @@ class MarketingSourceFactory:"AppleSearchAds": (NativeMarketingSource.APPLE_SEARCH_ADS, HierarchicalNativeAdsConfig),"OpenAIAds": (NativeMarketingSource.OPEN_AI_ADS, HierarchicalNativeAdsConfig),"RoktAds": (NativeMarketingSource.ROKT_ADS, HierarchicalNativeAdsConfig),+ "TwitterAds": (NativeMarketingSource.TWITTER_ADS, HierarchicalNativeAdsConfig),"GoogleAds": (NativeMarketingSource.GOOGLE_ADS, GoogleAdsConfig),"LinkedinAds": (NativeMarketingSource.LINKEDIN_ADS, LinkedinAdsConfig),"RedditAds": (NativeMarketingSource.REDDIT_ADS, RedditAdsConfig),diff --git a/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py b/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.pyindex c1dfcf5cbbf7..8c6067b788b9 100644--- a/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py+++ b/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py@@ -572,7 +572,7 @@ class TestNativeSourceKillSwitch(SimpleTestCase):factory._warehouse_tables = []factory._external_sources = []factory._tables_by_source_id = {}- for source_type in ("GoogleAds", "AppleSearchAds", "OpenAIAds", "AmazonAds", "RoktAds"):+ for source_type in ("GoogleAds", "AppleSearchAds", "OpenAIAds", "AmazonAds", "RoktAds", "TwitterAds"):source = ExternalDataSource(source_type=source_type)patterns = TABLE_PATTERNS[NativeMarketingSource(source_type)]tables = [@@ -590,7 +590,9 @@ class TestNativeSourceKillSwitch(SimpleTestCase):adapters = factory.create_adapters()assert [adapter.get_source_type() for adapter in adapters] == (- ["GoogleAds", "AppleSearchAds", "OpenAIAds", "AmazonAds", "RoktAds"] if enabled else ["GoogleAds"]+ ["GoogleAds", "AppleSearchAds", "OpenAIAds", "AmazonAds", "RoktAds", "TwitterAds"]+ if enabled+ else ["GoogleAds"])errors = factory.get_validation_errors(adapters)assert set(errors) == ({adapter.config.source_id for adapter in adapters[1:]} if enabled else set())diff --git a/products/marketing_analytics/backend/hogql_queries/adapters/test_twitter_ads.py b/products/marketing_analytics/backend/hogql_queries/adapters/test_twitter_ads.pynew file mode 100644index 000000000000..74329ede9448--- /dev/null+++ b/products/marketing_analytics/backend/hogql_queries/adapters/test_twitter_ads.py@@ -0,0 +1,134 @@+from datetime import UTC, datetime++from unittest.mock import PropertyMock, patch++from django.test import SimpleTestCase++from parameterized import parameterized++from posthog.schema import DateRange, MarketingAnalyticsDrillDownLevel++from posthog.hogql import ast+from posthog.hogql.placeholders import replace_placeholders++from posthog.hogql_queries.utils.query_date_range import QueryDateRange+from posthog.models import Team+from posthog.models.team.team_marketing_analytics_config import TeamMarketingAnalyticsConfig++from products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSource++from .base import HierarchicalNativeAdsConfig, QueryContext+from .twitter_ads import TwitterAdsAdapter++_CAMPAIGN_COLUMNS = ["id", "name", "funding_instrument_id", "deleted"]+_LINE_ITEM_COLUMNS = ["id", "name", "campaign_id", "objective"]+_STATS_COLUMNS = [+ "entity_id",+ "date",+ "placement",+ "currency",+ "impressions",+ "clicks",+ "billed_charge_local_micro",+ "account_id",+]+++class TestTwitterAdsAdapter(SimpleTestCase):+ def setUp(self) -> None:+ self.team = Team(id=1)+ self.enterContext(+ patch.object(+ Team,+ "marketing_analytics_config",+ new_callable=PropertyMock,+ return_value=TeamMarketingAnalyticsConfig(team=self.team),+ )+ )++ def _table(self, name: str, columns: list[str]) -> DataWarehouseTable:+ return DataWarehouseTable(+ name=name,+ external_data_source=ExternalDataSource(source_type="TwitterAds"),+ columns=dict.fromkeys(columns, "String"),+ )++ def _adapter(self, drill_down_level: MarketingAnalyticsDrillDownLevel) -> TwitterAdsAdapter:+ return TwitterAdsAdapter(+ HierarchicalNativeAdsConfig(+ source_type="TwitterAds",+ source_id="x-source",+ campaign_table=self._table("twitterads_campaigns", _CAMPAIGN_COLUMNS),+ stats_table=self._table("twitterads_campaign_stats", _STATS_COLUMNS),+ adset_table=self._table("twitterads_line_items", _LINE_ITEM_COLUMNS),+ adset_stats_table=self._table("twitterads_line_item_stats", _STATS_COLUMNS),+ ),+ QueryContext(+ team=self.team,+ date_range=QueryDateRange(+ date_range=DateRange(date_from="2026-09-01", date_to="2026-09-02"),+ team=self.team,+ interval=None,+ now=datetime(2026, 9, 3, tzinfo=UTC),+ ),+ base_currency="EUR",+ drill_down_level=drill_down_level,+ ),+ )++ def _sql(self, adapter: TwitterAdsAdapter) -> str:+ query = adapter.build_query()+ assert query is not None+ return replace_placeholders(+ query,+ {+ "time_window_min": ast.Constant(value="2026-09-01"),+ "time_window_max": ast.Constant(value="2026-09-03"),+ },+ ).to_hogql()++ def test_campaign_spend_is_converted_from_micros_at_the_row_currency(self) -> None:+ sql = self._sql(self._adapter(MarketingAnalyticsDrillDownLevel.CAMPAIGN))++ assert "divide(coalesce(toFloat(twitterads_campaign_stats.billed_charge_local_micro), 0), 1000000)" in sql+ assert "convertCurrency(coalesce(twitterads_campaign_stats.currency, 'EUR'), 'EUR'" in sql+ assert "toDate(twitterads_campaign_stats.date)" in sql+ assert "throwIf(greater(countIf(empty(coalesce(twitterads_campaign_stats.currency, ''))), 0)" in sql++ def test_campaign_level_joins_stats_on_entity_id(self) -> None:+ sql = self._sql(self._adapter(MarketingAnalyticsDrillDownLevel.CAMPAIGN))++ assert "twitterads_campaign_stats.entity_id" in sql+ assert "twitterads_campaigns.id" in sql+ assert "twitterads_campaigns.name" in sql++ def test_ad_group_level_reads_the_line_item_tables(self) -> None:+ sql = self._sql(self._adapter(MarketingAnalyticsDrillDownLevel.AD_GROUP))++ assert "twitterads_line_item_stats" in sql+ assert "twitterads_line_items" in sql+ assert "twitterads_line_item_stats.entity_id" in sql++ def test_metrics_aggregate_so_placements_add_up(self) -> None:+ sql = self._sql(self._adapter(MarketingAnalyticsDrillDownLevel.CAMPAIGN))++ assert "sum(coalesce(toFloat(twitterads_campaign_stats.impressions), 0))" in sql+ assert "sum(coalesce(toFloat(twitterads_campaign_stats.clicks), 0))" in sql++ def test_conversions_report_zero_until_the_source_requests_them(self) -> None:+ sql = self._sql(self._adapter(MarketingAnalyticsDrillDownLevel.CAMPAIGN))++ assert "0 AS reported_conversion" in sql++ def test_validation_passes_on_a_complete_schema(self) -> None:+ assert self._adapter(MarketingAnalyticsDrillDownLevel.CAMPAIGN).validate().is_valid++ @parameterized.expand([("currency",), ("billed_charge_local_micro",)])+ def test_stats_table_without_required_column_is_rejected(self, column: str) -> None:+ adapter = self._adapter(MarketingAnalyticsDrillDownLevel.CAMPAIGN)+ assert adapter.config.stats_table.columns is not None+ del adapter.config.stats_table.columns[column]++ result = adapter.validate()+ assert not result.is_valid+ assert any(column in error for error in result.errors)diff --git a/products/marketing_analytics/backend/hogql_queries/adapters/twitter_ads.py b/products/marketing_analytics/backend/hogql_queries/adapters/twitter_ads.pynew file mode 100644index 000000000000..dec983566414--- /dev/null+++ b/products/marketing_analytics/backend/hogql_queries/adapters/twitter_ads.py@@ -0,0 +1,90 @@+from posthog.schema import MarketingAnalyticsDrillDownLevel, NativeMarketingSource++from posthog.hogql import ast+from posthog.hogql.parser import parse_expr++from ..constants import INTEGRATION_DEFAULT_SOURCES, INTEGRATION_PRIMARY_SOURCE+from .base import HierarchicalNativeAdsConfig, MarketingSourceAdapter, ValidationResult+++class TwitterAdsAdapter(MarketingSourceAdapter[HierarchicalNativeAdsConfig]):+ _source_type = NativeMarketingSource.TWITTER_ADS+ _stats_date_column = "date"+ _campaign_stats_fk_column = "entity_id"+ _adset_campaign_fk_column = "campaign_id"+ _adset_stats_fk_column = "entity_id"++ @classmethod+ def get_source_identifier_mapping(cls) -> dict[str, list[str]]:+ return {INTEGRATION_PRIMARY_SOURCE[cls._source_type]: list(INTEGRATION_DEFAULT_SOURCES[cls._source_type])}++ def get_source_type(self) -> str:+ return self._source_type.value++ def validate(self) -> ValidationResult:+ tables = self._level_tables()+ required_columns = [+ (tables.entity_table, (tables.entity_id_column, tables.entity_name_column)),+ (+ tables.stats_table,+ (+ tables.stats_entity_id_column,+ "date",+ "impressions",+ "clicks",+ "billed_charge_local_micro",+ "currency",+ ),+ ),+ ]+ if self.context.drill_down_level == MarketingAnalyticsDrillDownLevel.AD_GROUP:+ required_columns.extend(+ [+ (tables.entity_table, (self._adset_campaign_fk_column,)),+ (self.config.campaign_table, (self._campaign_pk_column, self._campaign_name_column)),+ ]+ )+ errors = [+ f"X Ads is missing '{column}' in '{table.name}'. Sync this table again."+ for table, columns in required_columns+ for column in columns+ if not self._table_has_column(table, column)+ ]+ return ValidationResult(is_valid=not errors, errors=errors)++ def _sum_metric(self, column: str) -> ast.Expr:+ table = self._level_tables().stats_table+ return parse_expr(+ "sum(coalesce(toFloat({value}), 0))",+ placeholders={"value": ast.Field(chain=[table.name, column])},+ )++ def _get_impressions_field(self) -> ast.Expr:+ return self._sum_metric("impressions")++ def _get_clicks_field(self) -> ast.Expr:+ return self._sum_metric("clicks")++ def _get_cost_field(self) -> ast.Expr:+ table = self._level_tables().stats_table+ return parse_expr(+ "sum(toFloat(convertCurrency(coalesce({currency}, {target}), {target}, "+ "coalesce(toFloat({spend}), 0) / 1000000, coalesce(toDate({date}), today())))) "+ "+ throwIf(countIf(empty(coalesce({currency}, ''))) > 0, {message})",+ placeholders={+ "spend": ast.Field(chain=[table.name, "billed_charge_local_micro"]),+ "currency": ast.Field(chain=[table.name, "currency"]),+ "target": ast.Constant(value=self.context.base_currency),+ "date": ast.Field(chain=[table.name, "date"]),+ "message": ast.Constant(+ value="X Ads currency is missing. Fully resync the stats table, then try again."+ ),+ },+ )++ def _get_reported_conversion_field(self) -> ast.Expr:+ # The source imports ENGAGEMENT and BILLING metrics, not conversion reports.+ return ast.Constant(value=0)++ def _get_reported_conversion_value_field(self) -> ast.Expr:+ return ast.Constant(value=0)diff --git a/products/marketing_analytics/backend/hogql_queries/constants.py b/products/marketing_analytics/backend/hogql_queries/constants.pyindex dd5d3bf38d06..b6c0d95c81b5 100644--- a/products/marketing_analytics/backend/hogql_queries/constants.py+++ b/products/marketing_analytics/backend/hogql_queries/constants.py@@ -30,6 +30,7 @@ from posthog.schema import (MarketingIntegrationConfig10,MarketingIntegrationConfig11,MarketingIntegrationConfig12,+ MarketingIntegrationConfig13,MetaAdsConversionFallbackActionTypes,MetaAdsConversionOmniActionTypes,MetaAdsConversionSpecificActionTypes,@@ -44,6 +45,7 @@ from posthog.schema import (SnapchatAdsConversionValueFields,SnapchatAdsDefaultSources,TikTokAdsDefaultSources,+ TwitterAdsDefaultSources,WebAnalyticsItemKind,)@@ -512,6 +514,7 @@ _ALL_CONFIG_MODELS: list[type[BaseModel]] = [MarketingIntegrationConfig10,MarketingIntegrationConfig11,MarketingIntegrationConfig12,+ MarketingIntegrationConfig13,MarketingIntegrationConfig2,MarketingIntegrationConfig3,MarketingIntegrationConfig4,@@ -553,6 +556,7 @@ _DEFAULT_SOURCES_ENUMS = {NativeMarketingSource.APPLE_SEARCH_ADS: AppleSearchAdsDefaultSources,NativeMarketingSource.OPEN_AI_ADS: OpenAIAdsDefaultSources,NativeMarketingSource.ROKT_ADS: RoktAdsDefaultSources,+ NativeMarketingSource.TWITTER_ADS: TwitterAdsDefaultSources,NativeMarketingSource.GOOGLE_ADS: GoogleAdsDefaultSources,NativeMarketingSource.LINKEDIN_ADS: LinkedinAdsDefaultSources,NativeMarketingSource.META_ADS: MetaAdsDefaultSources,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 85ce0b74a0a2..f7cb565ed771 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@@ -5437,7 +5437,7 @@ class TestConversionGoalProcessor(ClickhouseTestMixin, BaseTest):# Both should attribute to same UTM sourceassert events_campaign == actions_campaign == "summer_launch"- assert events_source == actions_source == "twitter_ads"+ assert events_source == actions_source == "twitter"# ActionsNode should count both events, EventsNode only oneassert events_count == 1diff --git a/products/marketing_analytics/backend/services/attribution_health.py b/products/marketing_analytics/backend/services/attribution_health.pyindex 6e8058f21a34..42a008a14132 100644--- a/products/marketing_analytics/backend/services/attribution_health.py+++ b/products/marketing_analytics/backend/services/attribution_health.py@@ -13,6 +13,7 @@ from typing import Any, castfrom django.utils import timezoneimport structlog+from asgiref.sync import sync_to_asyncfrom posthog.hogql import astfrom posthog.hogql.parser import parse_expr, parse_select@@ -24,11 +25,11 @@ from posthog.models.team.team import Teamfrom posthog.sync import database_sync_to_asyncfrom products.marketing_analytics.backend.services.native_integrations import (- EXTERNAL_SOURCE_TYPE_TO_NATIVE,NATIVE_TO_KEY,NativeIntegration,build_combined_alias_map,display_name_for_key,+ get_enabled_native_integrations,lookup_in,normalize,)@@ -137,9 +138,12 @@ async def get_attribution_health(else:alias_map = build_combined_alias_map(custom_source_mappings)- targets = list(NATIVE_TO_KEY.values())+ enabled_integrations = await sync_to_async(get_enabled_native_integrations, thread_sensitive=False)(team)+ targets = [NATIVE_TO_KEY[native] for native in enabled_integrations.values()]+ enabled_keys = set(targets)+ alias_map = {alias: key for alias, key in alias_map.items() if key in enabled_keys}if source_type is not None:- native = EXTERNAL_SOURCE_TYPE_TO_NATIVE.get(source_type)+ native = enabled_integrations.get(source_type)targets = [NATIVE_TO_KEY[native]] if native else []allowed = set(targets)diff --git a/products/marketing_analytics/backend/services/data_source_health.py b/products/marketing_analytics/backend/services/data_source_health.pyindex fabf55976b45..c9dfb5c06298 100644--- a/products/marketing_analytics/backend/services/data_source_health.py+++ b/products/marketing_analytics/backend/services/data_source_health.py@@ -20,8 +20,7 @@ from products.marketing_analytics.backend.hogql_queries.constants import ()from products.marketing_analytics.backend.services.native_integrations import (DISPLAY_NAMES,- EXTERNAL_SOURCE_TYPE_TO_NATIVE,- is_native_source_enabled,+ get_enabled_native_integrations,)from products.warehouse_sources.backend.facade.models import ExternalDataJob, ExternalDataSchema, ExternalDataSourcefrom products.warehouse_sources.backend.facade.types import ExternalDataJobStatus@@ -126,11 +125,7 @@ async def get_data_source_health(`marketing_analytics_config.sources_map` instead of triggering anotherPostgres roundtrip. None → service loads it itself."""- targets = {- key: native- for key, native in EXTERNAL_SOURCE_TYPE_TO_NATIVE.items()- if await sync_to_async(is_native_source_enabled, thread_sensitive=False)(key, team)- }+ targets = await sync_to_async(get_enabled_native_integrations, thread_sensitive=False)(team)if source_type is not None:targets = {k: v for k, v in targets.items() if k == source_type}diff --git a/products/marketing_analytics/backend/services/marketing_diagnostic.py b/products/marketing_analytics/backend/services/marketing_diagnostic.pyindex d847a12af44a..c7599890f8db 100644--- a/products/marketing_analytics/backend/services/marketing_diagnostic.py+++ b/products/marketing_analytics/backend/services/marketing_diagnostic.py@@ -12,6 +12,7 @@ from dataclasses import asdict, dataclass, fieldfrom typing import Any, Literal, castimport structlog+from asgiref.sync import sync_to_asyncfrom posthog.models.team.team import Teamfrom posthog.models.user import User@@ -36,6 +37,7 @@ from products.marketing_analytics.backend.services.native_integrations import (NATIVE_TO_KEY,NativeIntegration,display_name_for_key,+ get_enabled_native_integrations,)logger = structlog.get_logger(__name__)@@ -157,7 +159,12 @@ async def get_marketing_diagnostic(else:goals = cast(ConversionGoalsListResponse, goals_result)- integrations = _build_integration_diagnostics(data_source, attribution)+ enabled_integrations = await sync_to_async(get_enabled_native_integrations, thread_sensitive=False)(team)+ integrations = [+ integration+ for integration in _build_integration_diagnostics(data_source, attribution)+ if integration.source_type in enabled_integrations+ ]overall = _compute_overall_status(integrations)summary = _build_summary(integrations, overall, goals)top_actions = _global_recommended_actions(integrations, goals)diff --git a/products/marketing_analytics/backend/services/native_integrations.py b/products/marketing_analytics/backend/services/native_integrations.pyindex 733bdb8ddf33..7020418b6bed 100644--- a/products/marketing_analytics/backend/services/native_integrations.py+++ b/products/marketing_analytics/backend/services/native_integrations.py@@ -22,6 +22,7 @@ NativeIntegration = Literal["apple_ads","openai_ads","rokt_ads",+ "twitter_ads","google_ads","meta_ads","bing_ads",@@ -40,6 +41,7 @@ NATIVE_TO_KEY: dict[NativeMarketingSource, NativeIntegration] = {NativeMarketingSource.APPLE_SEARCH_ADS: "apple_ads",NativeMarketingSource.OPEN_AI_ADS: "openai_ads",NativeMarketingSource.ROKT_ADS: "rokt_ads",+ NativeMarketingSource.TWITTER_ADS: "twitter_ads",NativeMarketingSource.GOOGLE_ADS: "google_ads",NativeMarketingSource.META_ADS: "meta_ads",NativeMarketingSource.BING_ADS: "bing_ads",@@ -61,6 +63,7 @@ EXTERNAL_SOURCE_TYPE_TO_NATIVE: dict[str, NativeMarketingSource] = {"AppleSearchAds": NativeMarketingSource.APPLE_SEARCH_ADS,"OpenAIAds": NativeMarketingSource.OPEN_AI_ADS,"RoktAds": NativeMarketingSource.ROKT_ADS,+ "TwitterAds": NativeMarketingSource.TWITTER_ADS,"GoogleAds": NativeMarketingSource.GOOGLE_ADS,"MetaAds": NativeMarketingSource.META_ADS,"BingAds": NativeMarketingSource.BING_ADS,@@ -77,6 +80,7 @@ DISPLAY_NAMES: dict[NativeMarketingSource, str] = {NativeMarketingSource.APPLE_SEARCH_ADS: "Apple Ads",NativeMarketingSource.OPEN_AI_ADS: "OpenAI Ads",NativeMarketingSource.ROKT_ADS: "Rokt Ads",+ NativeMarketingSource.TWITTER_ADS: "X Ads",NativeMarketingSource.GOOGLE_ADS: "Google Ads",NativeMarketingSource.META_ADS: "Meta Ads",NativeMarketingSource.BING_ADS: "Bing Ads",@@ -99,6 +103,7 @@ OAUTH_KIND_BY_NATIVE: dict[NativeMarketingSource, str] = {NativeMarketingSource.PINTEREST_ADS: "pinterest-ads",NativeMarketingSource.SNAPCHAT_ADS: "snapchat",NativeMarketingSource.TIK_TOK_ADS: "tiktok-ads",+ NativeMarketingSource.TWITTER_ADS: "twitter-ads",}@@ -107,6 +112,7 @@ NATIVE_SOURCE_FEATURE_FLAGS: dict[str, str] = {"AppleSearchAds": "marketing-analytics-apple-ads","OpenAIAds": "marketing-analytics-openai-ads","RoktAds": "marketing-analytics-rokt-ads",+ "TwitterAds": "marketing-analytics-twitter-ads",}@@ -125,6 +131,14 @@ def is_native_source_enabled(source_type: str, team: "Team") -> bool:)+def get_enabled_native_integrations(team: "Team") -> dict[str, NativeMarketingSource]:+ return {+ source_type: native+ for source_type, native in EXTERNAL_SOURCE_TYPE_TO_NATIVE.items()+ if is_native_source_enabled(source_type, team)+ }++def display_name_for_key(key: NativeIntegration) -> str:return DISPLAY_NAMES[KEY_TO_NATIVE[key]]diff --git a/products/marketing_analytics/backend/services/test_attribution_health.py b/products/marketing_analytics/backend/services/test_attribution_health.pyindex da2917205ba9..ffed64a3f0e9 100644--- a/products/marketing_analytics/backend/services/test_attribution_health.py+++ b/products/marketing_analytics/backend/services/test_attribution_health.py@@ -49,6 +49,12 @@ class TestGetAttributionHealth(SimpleTestCase):def setUp(self):super().setUp()self.team = Team(id=1)+ flag_patcher = patch(+ "products.marketing_analytics.backend.services.native_integrations.get_feature_flag_or_none",+ return_value=True,+ )+ self.mock_flag = flag_patcher.start()+ self.addCleanup(flag_patcher.stop)from products.marketing_analytics.backend.services.native_integrations import canonical_source_aliasesfetch_patcher = patch(@@ -158,6 +164,27 @@ class TestGetAttributionHealth(SimpleTestCase):assert response.total_events_with_utm == 300assert response.total_events_matched_to_any_integration == 300+ @parameterized.expand([(True, None), (False, None), (True, "TwitterAds"), (False, "TwitterAds")])+ @pytest.mark.asyncio+ async def test_disabled_sources_are_not_attribution_targets(self, enabled: bool, source_type: str | None) -> None:+ self.mock_flag.return_value = enabled+ self.mock_fetch.return_value = [+ _UtmRow(raw_utm_source="twitter", event_count=20, last_seen_at=None),+ _UtmRow(raw_utm_source="twitter_paid", event_count=10, last_seen_at=None),+ _UtmRow(raw_utm_source="google", event_count=50, last_seen_at=None),+ ]++ response = await get_attribution_health(self.team, source_type=source_type)++ assert any(e.integration_key == "twitter_ads" for e in response.integrations) is enabled+ assert any(e.integration_key == "google_ads" for e in response.integrations) is (source_type is None)+ assert response.total_events_with_utm == 80+ assert response.total_events_matched_to_any_integration == (70 if enabled else 50)+ assert response.total_events_unmatched == (10 if enabled else 30)+ samples = {s.raw_value: s for s in response.all_utm_source_samples}+ assert samples["twitter"].matched_integration == ("twitter_ads" if enabled else None)+ assert samples["twitter_paid"].suggested_integration == ("twitter_ads" if enabled else None)+@pytest.mark.asyncioasync def test_unknown_source_type_filter_returns_empty(self):self.mock_fetch.return_value = [@@ -391,6 +418,15 @@ class TestAttributionHealthSourceTypeFilterClickhouse(ClickhouseTestMixin, BaseTclass TestAttributionHealthPaidSignalClickhouse(ClickhouseTestMixin, BaseTest):CLASS_DATA_LEVEL_SETUP = False+ def setUp(self) -> None:+ super().setUp()+ flag_patcher = patch(+ "products.marketing_analytics.backend.services.native_integrations.get_feature_flag_or_none",+ return_value=True,+ )+ flag_patcher.start()+ self.addCleanup(flag_patcher.stop)+@parameterized.expand([("google", "google_ads", "gclid"),diff --git a/products/marketing_analytics/backend/services/test_conversion_goals_inspector.py b/products/marketing_analytics/backend/services/test_conversion_goals_inspector.pyindex 83b4c7e52596..751b7ef0ca42 100644--- a/products/marketing_analytics/backend/services/test_conversion_goals_inspector.py+++ b/products/marketing_analytics/backend/services/test_conversion_goals_inspector.py@@ -256,7 +256,8 @@ class TestExplainConversionGoal(_InspectorMixin):("uuid-1", ts1, "user-a", "purchase", "facebook", "spring_sale"),("uuid-2", ts1, "user-b", "purchase", "google", "spring_sale"),("uuid-3", ts2, "user-c", "purchase", None, None),- ("uuid-4", ts2, "user-d", "purchase", "twitter", "tweet_drive"), # no alias hit+ ("uuid-4", ts2, "user-d", "purchase", "twitter", "tweet_drive"),+ ("uuid-5", ts2, "user-e", "purchase", "unmapped_source", "summer_sale"),]with patch("products.marketing_analytics.backend.services.conversion_goals_inspector._query_goal_events",@@ -268,25 +269,27 @@ class TestExplainConversionGoal(_InspectorMixin):period=DateRange(date_from="2026-04-01T00:00:00+00:00", date_to="2026-04-03T00:00:00+00:00"),)- assert explanation.total_count == 4- assert explanation.integrated_count == 2- # 1 row had utm_source=None (without_utm), 1 row had utm_source='twitter' (unmatched_with_utm)+ assert explanation.total_count == 5+ assert explanation.integrated_count == 3+ # 1 row had utm_source=None (without_utm), 1 row had utm_source='unmapped_source' (unmatched_with_utm)assert explanation.events_without_utm_source == 1assert explanation.events_with_unmatched_utm_source == 1assert explanation.non_integrated_count == 2- assert dict(explanation.by_event) == {"purchase": 4}+ assert dict(explanation.by_event) == {"purchase": 5}utm_dict = dict(explanation.by_utm_source)assert utm_dict.get("facebook") == 1assert utm_dict.get("google") == 1assert utm_dict.get("twitter") == 1+ assert utm_dict.get("unmapped_source") == 1integration_dict = dict(explanation.by_matched_integration)assert integration_dict.get("meta_ads") == 1assert integration_dict.get("google_ads") == 1- assert "twitter" not in integration_dict+ assert integration_dict.get("twitter_ads") == 1+ assert "unmapped_source" not in integration_dict- assert len(explanation.samples) == 4+ assert len(explanation.samples) == 5@pytest.mark.asyncioasync def test_events_goal_caps_samples(self):diff --git a/products/marketing_analytics/backend/services/test_marketing_diagnostic.py b/products/marketing_analytics/backend/services/test_marketing_diagnostic.pyindex 51a88edf13a2..937dec28edd7 100644--- a/products/marketing_analytics/backend/services/test_marketing_diagnostic.py+++ b/products/marketing_analytics/backend/services/test_marketing_diagnostic.py@@ -153,6 +153,12 @@ class TestGetMarketingDiagnostic(SimpleTestCase):def setUp(self):super().setUp()self.team = Team(id=1)+ flag_patcher = patch(+ "products.marketing_analytics.backend.services.native_integrations.get_feature_flag_or_none",+ return_value=True,+ )+ self.mock_flag = flag_patcher.start()+ self.addCleanup(flag_patcher.stop)ds_patcher = patch("products.marketing_analytics.backend.services.marketing_diagnostic.get_data_source_health",new_callable=AsyncMock,@@ -228,6 +234,30 @@ class TestGetMarketingDiagnostic(SimpleTestCase):assert bool(response.recommended_actions) is (paid > 0)assert response.overall_status == ("degraded" if paid else "no_sources")+ @parameterized.expand([(True,), (False,)])+ @pytest.mark.asyncio+ async def test_connection_recommendations_respect_source_flag(self, enabled: bool) -> None:+ self.mock_flag.return_value = enabled+ self.mock_ds.return_value = DataSourceHealthResponse(integrations=[_ds_entry()])+ self.mock_attr.return_value = AttributionHealthResponse(+ lookback_days=7,+ integrations=[+ _attr_entry(),+ _attr_entry(+ integration_key="twitter_ads",+ display_name="X Ads",+ events_matched_paid_last_7d=100,+ ),+ ],+ )++ response = await get_marketing_diagnostic(self.team, include_conversion_goals=False)++ assert any(i.integration_key == "twitter_ads" for i in response.integrations) is enabled+ assert any(i.integration_key == "google_ads" for i in response.integrations)+ assert any("Connect X Ads" in a.title for a in response.recommended_actions) is enabled+ assert response.overall_status == ("degraded" if enabled else "healthy")+@pytest.mark.asyncioasync def test_sync_broken_propagates_to_overall(self):self.mock_ds.return_value = DataSourceHealthResponse(diff --git a/products/marketing_analytics/backend/services/test_native_integrations.py b/products/marketing_analytics/backend/services/test_native_integrations.pyindex cd3c54855412..45f73090d516 100644--- a/products/marketing_analytics/backend/services/test_native_integrations.py+++ b/products/marketing_analytics/backend/services/test_native_integrations.py@@ -144,9 +144,9 @@ class TestStructuralInvariants:assert isinstance(source_type, str)def test_every_oauth_kind_is_one_the_authorize_endpoint_accepts(self):- # Spelled out means it can drift, and a kind `authorize` rejects is a Connect button- # that 400s. `supported_kinds` is what that endpoint validates against.- unknown = set(OAUTH_KIND_BY_NATIVE.values()) - set(OauthIntegration.supported_kinds)+ # X Ads uses a separate OAuth 1.0a branch in IntegrationViewSet.authorize.+ supported_kinds = set(OauthIntegration.supported_kinds) | {"twitter-ads"}+ unknown = set(OAUTH_KIND_BY_NATIVE.values()) - supported_kindsassert not unknown, f"{sorted(unknown)} are not kinds the authorize endpoint accepts"@@ -166,6 +166,7 @@ class TestNativeSourceFeatureFlags:for source, flag in [("AmazonAds", "marketing-analytics-amazon-ads"),("RoktAds", "marketing-analytics-rokt-ads"),+ ("TwitterAds", "marketing-analytics-twitter-ads"),("AppleSearchAds", "marketing-analytics-apple-ads"),("OpenAIAds", "marketing-analytics-openai-ads"),]diff --git a/products/marketing_analytics/frontend/components/AddIntegrationButton.stories.tsx b/products/marketing_analytics/frontend/components/AddIntegrationButton.stories.tsxindex f9c365d3b8bd..99af0f0f76a1 100644--- a/products/marketing_analytics/frontend/components/AddIntegrationButton.stories.tsx+++ b/products/marketing_analytics/frontend/components/AddIntegrationButton.stories.tsx@@ -59,6 +59,7 @@ const meta: Meta<typeof AddIntegrationButton> = {AppleSearchAds: 'apple_search_ads.png',OpenAIAds: 'openai_ads.svg',AmazonAds: 'amazon_ads.png',+ TwitterAds: 'twitter_ads.png',BigQuery: 'bigquery.png',}).map(([name, icon]) => [name,@@ -75,6 +76,7 @@ const meta: Meta<typeof AddIntegrationButton> = {FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS,FEATURE_FLAGS.MARKETING_ANALYTICS_OPENAI_ADS,FEATURE_FLAGS.MARKETING_ANALYTICS_AMAZON_ADS,+ FEATURE_FLAGS.MARKETING_ANALYTICS_TWITTER_ADS,],testOptions: { viewport: { width: 520, height: 1024 } },},diff --git a/products/marketing_analytics/frontend/components/newAdSourcesLogic.ts b/products/marketing_analytics/frontend/components/newAdSourcesLogic.tsindex 3199ce129c43..0535b5550ee7 100644--- a/products/marketing_analytics/frontend/components/newAdSourcesLogic.ts+++ b/products/marketing_analytics/frontend/components/newAdSourcesLogic.ts@@ -10,7 +10,7 @@ import { UserType } from '~/types'// Persisted on the user; changing this key shows the announcement again everywhere.export const NEW_AD_SOURCES_SEEN_KEY = 'marketing-new-ad-sources-v1'-const NEW_AD_SOURCES = new Set<NativeMarketingSource>(['AppleSearchAds', 'OpenAIAds', 'AmazonAds'])+const NEW_AD_SOURCES = new Set<NativeMarketingSource>(['AppleSearchAds', 'OpenAIAds', 'AmazonAds', 'TwitterAds'])// Generated by kea-typegen. Update if you're an agent, ignore if you're human.export interface newAdSourcesLogicValues {@@ -57,6 +57,7 @@ export interface newAdSourcesLogicMeta {| 'RoktAds'| 'SnapchatAds'| 'TikTokAds'+ | 'TwitterAds')[],dismissedUserId: number | null) => booleandiff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/twitter_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/twitter_ads/source.pyindex 34fc40980191..3e45cc7d9691 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/twitter_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/twitter_ads/source.py@@ -9,6 +9,7 @@ from products.warehouse_sources.backend.facade.source_config import (SourceConfig,SourceFieldOauthAccountSelectConfig,SourceFieldOauthConfig,+ SuggestedTable,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.base import FieldType, ResumableSourcefrom products.warehouse_sources.backend.temporal.data_imports.sources.common.canonical_descriptions import (@@ -74,6 +75,17 @@ class TwitterAdsSource(ResumableSource[TwitterAdsSourceConfig, TwitterAdsResumeCreleaseStatus=ReleaseStatus.ALPHA,# Hidden until PostHog's X app is approved for Ads API access and its keys are deployed.featureFlag="dwh-twitter-ads",+ suggestedTables=[+ SuggestedTable(table="campaigns", tooltip="Required for campaign names in Marketing analytics."),+ SuggestedTable(+ table="campaign_stats",+ tooltip="Required for daily spend, clicks, and impressions in Marketing analytics.",+ ),+ SuggestedTable(table="line_items", tooltip="Required for ad group names in Marketing analytics."),+ SuggestedTable(+ table="line_item_stats", tooltip="Required for daily ad group metrics in Marketing analytics."+ ),+ ],fields=cast(list[FieldType],[