: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 openai ads (#106292)
Javier Bahamondes05e393fda227
diff --git a/docs/published/handbook/engineering/data-warehouse.md b/docs/published/handbook/engineering/data-warehouse.mdindex 93e12398ba7e..f3272500e16d 100644--- a/docs/published/handbook/engineering/data-warehouse.md+++ b/docs/published/handbook/engineering/data-warehouse.md@@ -21,6 +21,20 @@ The adapter accepts both Campaign Management API 5 `installs` and Ads Platform ASpend uses the currency in Apple's `localSpend` object and the reporting date to convert into the project's currency.Apple does not report conversion revenue through these reports, so reported conversion value is zero.+## OpenAI Ads in Marketing analytics++Marketing analytics support is controlled by the boolean organization flag `marketing-analytics-openai-ads` and is off by default.+Enable the flag for an organization to show the integration and include its data in live and precomputed marketing queries.+Disable it to stop using the integration in Marketing analytics without deleting the connection or its imported data.+Data warehouse syncs continue independently of this flag.++Sync `campaigns` and `campaign_insights` to include OpenAI Ads campaign delivery in Marketing analytics.+Spend is already in major currency units; the importer adds `currency_code` from the account metadata so reports can convert spend at each bucket date.+Existing connections need a full resync of `campaign_insights` to populate currency on historical rows.+Cost tiles are unavailable without the currency column; queries with empty historical currency values stop with a resync message.+Reported conversions and revenue are zero because the importer currently requests delivery metrics only.+Ad groups and individual ads are not included in the native integration.+## Adding a new sourceLooking to add a new source to data warehouse? [We have a detailed guide in the codebase](https://github.com/PostHog/posthog/blob/master/products/warehouse_sources/backend/temporal/data_imports/sources/README.md).diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex 6c611a204e0c..7761d6e4e692 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -10149,9 +10149,9 @@ snapshots:scenes-app-marketing-analytics-cell-actions--campaign-cell-action-globally-mapped--light:hash: v1.k794b7964.61e09c9e87341bff85e48a5a849c60271b9343f68156fdbd8254d867efcbe362.8mesQHKUwOThl6lkM5fvaR5z5Iwc2JSF4pZ0iB0Ho34scenes-app-marketing-analytics-cell-actions--campaign-cell-action-unmapped--dark:- hash: v1.k794b7964.8e4c8745ddfeb9e39c12c1de6440ffefbab10c6fdfcbaf2917ec6eeb30c21a3c.bJYM40EyMJDb-CNlZ6VS6F0_q7RzB27y88wyo_vS_pk+ hash: v1.k794b7964.f5266399f092411bbe18d8b35f72dee1a8bfbe3df16728f5b20e23a8b2fac41a.MIsGe8h0CayTSbg-lsCoTeDRZRVNU-fGrmTzksvi9ioscenes-app-marketing-analytics-cell-actions--campaign-cell-action-unmapped--light:- hash: v1.k794b7964.0e25052e261eb633f06f625f042febd96eb40e52650c5b22d41f2594f04d466f.gWGwrfXDOGghOGomTQr7hL7f0slkZGUwWbI2NcbjrrE+ hash: v1.k794b7964.3d75928c8d9413c248f3ae2341ca2775ba62b62e093d6d6bf84f7e15a731905d.KYdvSw7hLTVNJSf0NjYoh2k1xJFearMFckiokWOoqbcscenes-app-marketing-analytics-cell-actions--source-cell-action-custom-mapped--dark:hash: v1.k794b7964.b54f7b4f93126a339b8d1f2c3052e33195ece30a69558784cf5e3500d1fdff2d.z26YCBpYH_GJ8cTy_m2zptpKY3Y7-ExoHfa-vjsJXuUscenes-app-marketing-analytics-cell-actions--source-cell-action-custom-mapped--light:@@ -10165,9 +10165,9 @@ snapshots:scenes-app-marketing-analytics-cell-actions--source-cell-action-integration-disabled--light:hash: v1.k794b7964.a47387317b5359abf524ddee66c0191f13aa20068299426fd2ba02a2a2b484de.8vAAZrir9sb1KgnInnG0LSGU1ejxmdo9L27tV9HuLPMscenes-app-marketing-analytics-cell-actions--source-cell-action-unmapped--dark:- hash: v1.k794b7964.cf10adeda245ccff69e13bd0549d2b1579f5173b93a0b6090dce2b51db242384.oM_0pR3iPTmwIT5GCc7rRMRcHVCZVVRL1_LIjQFT3Ag+ hash: v1.k794b7964.6b2d3d0ea747d89cd5d8003ad5652110defff20c6d72b2281cc379e2c6fddff1.j1PVCswW5wNUlN4r73b1E763-Y_1x3in29kKrVPHeGsscenes-app-marketing-analytics-cell-actions--source-cell-action-unmapped--light:- hash: v1.k794b7964.82fdca17171ef49bdce7d6a769c88cde001e17f402f1b19e2a3778f0aa274b82.YW7pM5jU-MhVYp1FgIC0MA7wJEWz4eaooeYj6WFpucM+ hash: v1.k794b7964.5370c38c333a9ed59c62f0a38f5289e1b184db5528ab590fd5188bf4a49e3554.eRp0bm6akYSB-PVs0946LcXqze_inC4rRfq_OpRdkwwscenes-app-marketing-analytics-dashboard-change-value-cell--bounce-rate--dark:hash: v1.k794b7964.077ba380688f01ece0aa53fbdd827aa0b79a58e6f952315fe51af26bc835b64a.PRdHzGD2h3pbMEhUAGi2JC6w2vr8_XebNg_iPCpM9bgscenes-app-marketing-analytics-dashboard-change-value-cell--bounce-rate--light:diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsxindex f4cf3897aca8..12c66ac56318 100644--- a/frontend/src/lib/constants.tsx+++ b/frontend/src/lib/constants.tsx@@ -390,6 +390,7 @@ export const FEATURE_FLAGS = {MARKETING_ANALYTICS_MCP: 'marketing-analytics-mcp', // owner: @jabahamondes #team-web-analytics — gates MCP tool exposure (read-only marketing-analytics tools)MARKETING_ANALYTICS_MULTI_TOUCH_ATTRIBUTION: 'marketing-analytics-multi-touch-attribution', // owner: @jabahamondes #team-web-analyticsMARKETING_ANALYTICS_NEW_DASHBOARD: 'new-marketing-analytics-dashboard', // owner: @jabahamondes #team-web-analytics — gates the redesigned dashboard and all of its sections+ MARKETING_ANALYTICS_OPENAI_ADS: 'marketing-analytics-openai-ads', // owner: @jabahamondes #team-web-analyticsMARKETING_ANALYTICS_RETENTION: 'marketing-analytics-retention', // owner: @jabahamondes #team-web-analytics — gates the legacy Retention explorer tab; the new dashboard ignores itMARKETING_ANALYTICS_RETURN_METRICS: 'marketing-analytics-return-metrics', // owner: @jabahamondes #team-web-analytics — gates the ROAS columnMARKETING_ANALYTICS_SETUP: 'marketing-analytics-setup', // owner: @jabahamondes #team-web-analytics — gates the Setup tab and its setup_plan / apply_setup_ops endpointsdiff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.jsonindex 7a99d8c3ebcc..c9a8ad77829b 100644--- a/frontend/src/queries/schema.json+++ b/frontend/src/queries/schema.json@@ -36473,6 +36473,64 @@"adsetStatsTableName"],"type": "object"+ },+ {+ "additionalProperties": false,+ "properties": {+ "campaignTableName": {+ "const": "campaigns",+ "type": "string"+ },+ "defaultSources": {+ "items": [+ {+ "const": "openai",+ "type": "string"+ },+ {+ "const": "chatgpt",+ "type": "string"+ },+ {+ "const": "openai_ads",+ "type": "string"+ }+ ],+ "maxItems": 3,+ "minItems": 3,+ "type": "array"+ },+ "idField": {+ "const": "id",+ "type": "string"+ },+ "nameField": {+ "const": "name",+ "type": "string"+ },+ "primarySource": {+ "const": "openai",+ "type": "string"+ },+ "sourceType": {+ "const": "OpenAIAds",+ "type": "string"+ },+ "statsTableName": {+ "const": "campaign_insights",+ "type": "string"+ }+ },+ "required": [+ "sourceType",+ "nameField",+ "idField",+ "campaignTableName",+ "statsTableName",+ "defaultSources",+ "primarySource"+ ],+ "type": "object"}]},@@ -38381,7 +38439,8 @@"BingAds","SnapchatAds","PinterestAds",- "AppleSearchAds"+ "AppleSearchAds",+ "OpenAIAds"],"type": "string"},@@ -38660,6 +38719,10 @@"required": ["type"],"type": "object"},+ "OpenAIAdsDefaultSources": {+ "enum": ["openai", "chatgpt", "openai_ads"],+ "type": "string"+ },"PCADetectorConfig": {"additionalProperties": false,"properties": {diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.tsindex b7bdec67d7ec..14ed7b7f39b4 100644--- a/frontend/src/queries/schema/schema-general.ts+++ b/frontend/src/queries/schema/schema-general.ts@@ -8397,6 +8397,7 @@ export const VALID_NATIVE_MARKETING_SOURCES = ['SnapchatAds','PinterestAds','AppleSearchAds',+ 'OpenAIAds',] as constexport type NativeMarketingSource = (typeof VALID_NATIVE_MARKETING_SOURCES)[number]@@ -8578,12 +8579,22 @@ export const MARKETING_INTEGRATION_CONFIGS = {adsetTableName: 'ad_groups' as const,adsetStatsTableName: 'ad_group_report' as const,},+ OpenAIAds: {+ sourceType: 'OpenAIAds' as const,+ nameField: 'name',+ idField: 'id',+ campaignTableName: 'campaigns',+ statsTableName: 'campaign_insights',+ defaultSources: ['openai', 'chatgpt', 'openai_ads'] as const,+ primarySource: 'openai',+ },} as constexport type MarketingIntegrationConfig = (typeof MARKETING_INTEGRATION_CONFIGS)[NativeMarketingSource]export type AppleSearchAdsDefaultSources =(typeof MARKETING_INTEGRATION_CONFIGS)['AppleSearchAds']['defaultSources'][number]+export type OpenAIAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['OpenAIAds']['defaultSources'][number]export type GoogleAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['GoogleAds']['defaultSources'][number]export type LinkedinAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['LinkedinAds']['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 bb5f9a3797e5..49e6ca579bf8 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@@ -29,6 +29,7 @@ const MARKETING_SOURCE_ICONS: Record<fields: [],caption: 'Apple Ads',},+ OpenAIAds: { name: 'OpenAIAds', iconPath: '/static/services/openai_ads.svg', fields: [], caption: 'OpenAI Ads' },GoogleAds: {name: 'GoogleAds',iconPath: '/static/services/google-ads.png',@@ -86,7 +87,7 @@ const meta: Meta<LemonMenuOverlayProps> = {}),],parameters: {- featureFlags: [FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS],+ featureFlags: [FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS, FEATURE_FLAGS.MARKETING_ANALYTICS_OPENAI_ADS],docs: {description: {component: `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 4e3d3db85c10..65cf8e63f2c5 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@@ -675,6 +675,141 @@ exports[`marketing analytics utils createMarketingTile snapshots MetaAds - roas}`;+exports[`marketing analytics utils createMarketingTile snapshots OpenAIAds - clicks 1`] = `+{+ "custom_name": "prefix.campaign_insights clicks",+ "distinct_id_field": "campaign_id",+ "id": "OpenAIAds-stats-table-id",+ "id_field": "campaign_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "SUM(ifNull(toFloat(clicks), 0))",+ "name": "openai",+ "table_name": "prefix.campaign_insights",+ "timestamp_field": "start_time",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots OpenAIAds - cost 1`] = `+{+ "custom_name": "prefix.campaign_insights cost",+ "distinct_id_field": "campaign_id",+ "id": "OpenAIAds-stats-table-id",+ "id_field": "campaign_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "SUM(toFloat(convertCurrency(coalesce(currency_code, 'USD'), 'USD', toFloat(spend), coalesce(toDate(start_time), today())))) + throwIf(countIf(empty(coalesce(currency_code, ''))) > 0, 'OpenAI Ads currency is missing. Fully resync campaign_insights, then try again.')",+ "name": "openai",+ "table_name": "prefix.campaign_insights",+ "timestamp_field": "start_time",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots OpenAIAds - impressions 1`] = `+{+ "custom_name": "prefix.campaign_insights impressions",+ "distinct_id_field": "campaign_id",+ "id": "OpenAIAds-stats-table-id",+ "id_field": "campaign_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "SUM(ifNull(toFloat(impressions), 0))",+ "name": "openai",+ "table_name": "prefix.campaign_insights",+ "timestamp_field": "start_time",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots OpenAIAds - reported_conversion (missing conversion fields) 1`] = `+{+ "custom_name": "prefix.campaign_insights reported_conversion",+ "distinct_id_field": "campaign_id",+ "id": "OpenAIAds-stats-table-id",+ "id_field": "campaign_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "openai",+ "table_name": "prefix.campaign_insights",+ "timestamp_field": "start_time",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots OpenAIAds - reported_conversion 1`] = `+{+ "custom_name": "prefix.campaign_insights reported_conversion",+ "distinct_id_field": "campaign_id",+ "id": "OpenAIAds-stats-table-id",+ "id_field": "campaign_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "openai",+ "table_name": "prefix.campaign_insights",+ "timestamp_field": "start_time",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots OpenAIAds - reported_conversion_value (missing conversion fields) 1`] = `+{+ "custom_name": "prefix.campaign_insights reported_conversion_value",+ "distinct_id_field": "campaign_id",+ "id": "OpenAIAds-stats-table-id",+ "id_field": "campaign_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "openai",+ "table_name": "prefix.campaign_insights",+ "timestamp_field": "start_time",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots OpenAIAds - reported_conversion_value 1`] = `+{+ "custom_name": "prefix.campaign_insights reported_conversion_value",+ "distinct_id_field": "campaign_id",+ "id": "OpenAIAds-stats-table-id",+ "id_field": "campaign_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "openai",+ "table_name": "prefix.campaign_insights",+ "timestamp_field": "start_time",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots OpenAIAds - roas (missing conversion fields) 1`] = `+{+ "custom_name": "prefix.campaign_insights roas",+ "distinct_id_field": "campaign_id",+ "id": "OpenAIAds-stats-table-id",+ "id_field": "campaign_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "openai",+ "table_name": "prefix.campaign_insights",+ "timestamp_field": "start_time",+}+`;++exports[`marketing analytics utils createMarketingTile snapshots OpenAIAds - roas 1`] = `+{+ "custom_name": "prefix.campaign_insights roas",+ "distinct_id_field": "campaign_id",+ "id": "OpenAIAds-stats-table-id",+ "id_field": "campaign_id",+ "kind": "DataWarehouseNode",+ "math": "hogql",+ "math_hogql": "0",+ "name": "openai",+ "table_name": "prefix.campaign_insights",+ "timestamp_field": "start_time",+}+`;+exports[`marketing analytics utils createMarketingTile snapshots PinterestAds - clicks 1`] = `{"custom_name": "prefix.campaign_analytics clicks",diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.tsindex 622c0c653d50..f65260692adf 100644--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.test.ts@@ -542,42 +542,48 @@ describe('marketingAnalyticsLogic', () => {})- it('removes AppleSearchAds from connected sources and mapping menus when its flag turns off', async () => {- logic = marketingAnalyticsLogic()- logic.mount()- await expectLogic(logic).toFinishAllListeners()- const campaignSchema = MARKETING_INTEGRATION_CONFIGS.AppleSearchAds.campaignTableName- await expectLogic(logic, () =>- logic.actions.loadSourcesSuccess({- count: 2,- next: null,- previous: null,- results: [- { id: 'new-source', source_type: 'AppleSearchAds', schemas: [] } as unknown as ExternalDataSource,- { id: 'google-source', source_type: 'GoogleAds', schemas: [] } as unknown as ExternalDataSource,- ],+ it.each([+ ['AppleSearchAds', FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS],+ ['OpenAIAds', FEATURE_FLAGS.MARKETING_ANALYTICS_OPENAI_ADS],+ ] as const)(+ 'removes %s from connected sources and mapping menus when its flag turns off',+ async (sourceType, flag) => {+ logic = marketingAnalyticsLogic()+ logic.mount()+ await expectLogic(logic).toFinishAllListeners()+ const campaignSchema = MARKETING_INTEGRATION_CONFIGS[sourceType].campaignTableName+ await expectLogic(logic, () =>+ logic.actions.loadSourcesSuccess({+ count: 2,+ next: null,+ previous: null,+ results: [+ { id: 'new-source', source_type: sourceType, schemas: [] } as unknown as ExternalDataSource,+ { id: 'google-source', source_type: 'GoogleAds', schemas: [] } as unknown as ExternalDataSource,+ ],+ })+ ).toFinishAllListeners()+ databaseTableListLogic.actions.loadDatabaseSuccess({+ tables: {+ campaign: {+ id: 'campaign-table',+ name: `${sourceType}_${campaignSchema}`,+ type: 'data_warehouse',+ source: { id: 'new-source', source_type: sourceType },+ fields: {},+ } as DatabaseSchemaDataWarehouseTable,+ },+ joins: [],})- ).toFinishAllListeners()- databaseTableListLogic.actions.loadDatabaseSuccess({- tables: {- campaign: {- id: 'campaign-table',- name: `AppleSearchAds_${campaignSchema}`,- type: 'data_warehouse',- source: { id: 'new-source', source_type: 'AppleSearchAds' },- fields: {},- } as DatabaseSchemaDataWarehouseTable,- },- joins: [],- })- for (const enabled of [false, true, false]) {- featureFlagLogic.actions.setFeatureFlags([], { [FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS]: enabled })- expect(logic.values.nativeSources.map((source) => source.source_type)).toEqual(- enabled ? ['AppleSearchAds', 'GoogleAds'] : ['GoogleAds']- )- expect(marketingAnalyticsSettingsLogic.values.integrationCampaignTables.AppleSearchAds).toBe(- enabled ? `AppleSearchAds_${campaignSchema}` : undefined- )+ for (const enabled of [false, true, false]) {+ featureFlagLogic.actions.setFeatureFlags([], { [flag]: enabled })+ expect(logic.values.nativeSources.map((source) => source.source_type)).toEqual(+ enabled ? [sourceType, 'GoogleAds'] : ['GoogleAds']+ )+ expect(marketingAnalyticsSettingsLogic.values.integrationCampaignTables[sourceType]).toBe(+ enabled ? `${sourceType}_${campaignSchema}` : undefined+ )+ }}- })+ )})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 9900f7257f91..356612407abe 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@@ -151,6 +151,7 @@ export interface marketingAnalyticsSettingsLogicActions {| 'GoogleAds'| 'LinkedinAds'| 'MetaAds'+ | 'OpenAIAds'| 'PinterestAds'| 'RedditAds'| 'SnapchatAds'diff --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 c7003b408efb..6f358c3c59a5 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@@ -27,11 +27,14 @@ import {} from './utils'describe('marketing analytics utils', () => {- describe('getEnabledNativeMarketingSources', () => {- it.each([undefined, false, true, 'test'])('gates AppleSearchAds when its flag is %s', (enabled) => {- const flags = enabled === undefined ? {} : { [FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS]: enabled }+ describe.each([+ ['AppleSearchAds', FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS, FEATURE_FLAGS.MARKETING_ANALYTICS_OPENAI_ADS],+ ['OpenAIAds', FEATURE_FLAGS.MARKETING_ANALYTICS_OPENAI_ADS, FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS],+ ] as const)('getEnabledNativeMarketingSources: %s', (sourceType, flag, otherFlag) => {+ it.each([undefined, false, true, 'test'])('gates the source when its flag is %s', (enabled) => {+ const flags = { [otherFlag]: true, ...(enabled === undefined ? {} : { [flag]: enabled }) }expect(getEnabledNativeMarketingSources(flags)).toEqual(- VALID_NATIVE_MARKETING_SOURCES.filter((source) => source !== 'AppleSearchAds' || enabled === true)+ VALID_NATIVE_MARKETING_SOURCES.filter((source) => source !== sourceType || enabled === true))})})@@ -276,6 +279,7 @@ describe('marketing analytics utils', () => {// All fields each source could reference, so the mock table has them allconst sourceFields: Record<NativeMarketingSource, string[]> = {AppleSearchAds: ['local_spend', 'impressions', 'taps', 'total_installs'],+ OpenAIAds: ['campaign_id', 'start_time', 'spend', 'impressions', 'clicks', 'currency_code'],GoogleAds: ['metrics_cost_micros','metrics_impressions',@@ -328,6 +332,7 @@ describe('marketing analytics utils', () => {// Minimal fields: only non-conversion columns (cost, impressions, clicks, currency)const minimalSourceFields: Record<NativeMarketingSource, string[]> = {AppleSearchAds: ['local_spend', 'impressions', 'taps'],+ OpenAIAds: ['campaign_id', 'start_time', 'spend', 'impressions', 'clicks', 'currency_code'],GoogleAds: ['metrics_cost_micros', 'metrics_impressions', 'metrics_clicks', 'customer_currency_code'],RedditAds: ['spend', 'impressions', 'clicks', 'currency'],LinkedinAds: ['cost_in_usd', 'impressions', 'clicks'],@@ -376,6 +381,32 @@ describe('marketing analytics utils', () => {expect(result?.table_name).toBe(source.tables[0].name)})+ it.each(['', 'custom_', 'warehouse.custom_'])('resolves OpenAIAds tables with prefix %s', (prefix) => {+ const source = makeMockSource('OpenAIAds', sourceFields.OpenAIAds)+ source.tables[0].name = `${prefix}openaiads_${MARKETING_INTEGRATION_CONFIGS.OpenAIAds.statsTableName.toLowerCase()}`+ const result = createMarketingTile(source, MarketingAnalyticsColumnsSchemaNames.Cost, 'EUR')+ expect(result?.table_name).toBe(source.tables[0].name)+ })++ it.each(['currency_code', 'start_time', 'spend', 'campaign_id', 'clicks', 'impressions'])(+ 'omits OpenAI Ads cost tiles missing %s',+ (field) => {+ const source = makeMockSource(+ 'OpenAIAds',+ sourceFields.OpenAIAds.filter((name) => name !== field)+ )+ expect(createMarketingTile(source, MarketingAnalyticsColumnsSchemaNames.Cost, 'EUR')).toBeNull()+ }+ )++ it('keeps OpenAI Ads impressions available without currency', () => {+ const source = makeMockSource(+ 'OpenAIAds',+ sourceFields.OpenAIAds.filter((name) => name !== 'currency_code')+ )+ expect(createMarketingTile(source, MarketingAnalyticsColumnsSchemaNames.Impressions, 'EUR')).not.toBeNull()+ })+const testCases = VALID_NATIVE_MARKETING_SOURCES.flatMap((sourceType) =>ALL_TILE_COLUMNS.map((column) =>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 2e8f1dd8bc60..6c5c06f73168 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@@ -32,6 +32,7 @@ export const VALID_SELF_MANAGED_MARKETING_SOURCES: ManualLinkSourceType[] = [export const NATIVE_SOURCE_FEATURE_FLAGS: Partial<Record<NativeMarketingSource, FeatureFlagKey>> = {AppleSearchAds: FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS,+ OpenAIAds: FEATURE_FLAGS.MARKETING_ANALYTICS_OPENAI_ADS,}/**@@ -71,6 +72,7 @@ const NATIVE_SOURCE_DISPLAY_LABELS: Record<NativeMarketingSource, string> = {SnapchatAds: 'Snapchat Ads',PinterestAds: 'Pinterest Ads',AppleSearchAds: 'Apple Ads',+ OpenAIAds: 'OpenAI Ads',}export function nativeSourceDisplayLabel(sourceType: string): string {return NATIVE_SOURCE_DISPLAY_LABELS[sourceType as NativeMarketingSource] ?? sourceType@@ -321,6 +323,7 @@ interface SourceColumnMappings {currencyColumn?: stringfallbackCurrency?: stringcurrencyTimestampColumn?: string+ missingCurrencyMessage?: string}interface ConversionExprResult extends Partial<DataWarehouseNode> {@@ -386,6 +389,29 @@ const sourceTileConfigs: Record<NativeMarketingSource, SourceTileConfig> = {return null},},+ OpenAIAds: {+ idField: 'campaign_id',+ timestampField: 'start_time',+ columnMappings: {+ cost: 'spend',+ impressions: 'impressions',+ clicks: 'clicks',+ reportedConversion: '0',+ reportedConversionValue: '0',+ currencyColumn: 'currency_code',+ currencyTimestampColumn: 'start_time',+ missingCurrencyMessage: 'OpenAI Ads currency is missing. Fully resync campaign_insights, then try again.',+ },+ specialConversionLogic: (_table, column) => {+ if (+ column === MarketingAnalyticsColumnsSchemaNames.ReportedConversion ||+ column === MarketingAnalyticsColumnsSchemaNames.ReportedConversionValue+ ) {+ return { math: HogQLMathType.HogQL, math_hogql: '0' }+ }+ return null+ },+ },GoogleAds: {// idField is a column on the stats table, which flattens `campaign.id` to// `campaign_id` and has no bare `id`.@@ -677,7 +703,10 @@ function wrapWithCurrencyConversion(const dateArgument = mappings.currencyTimestampColumn? `, coalesce(toDate(${mappings.currencyTimestampColumn}), today())`: ''- return `SUM(toFloat(convertCurrency(coalesce(${currencyColumn}, '${baseCurrency}'), '${baseCurrency}', ${valueExpr}${dateArgument})))`+ const converted = `SUM(toFloat(convertCurrency(coalesce(${currencyColumn}, '${baseCurrency}'), '${baseCurrency}', ${valueExpr}${dateArgument})))`+ return mappings.missingCurrencyMessage+ ? `${converted} + throwIf(countIf(empty(coalesce(${currencyColumn}, ''))) > 0, '${mappings.missingCurrencyMessage}')`+ : converted}if (fallbackCurrency) {return `toFloat(convertCurrency('${fallbackCurrency}', '${baseCurrency}', SUM(${valueExpr})))`@@ -737,6 +766,15 @@ export function createMarketingTile(return null}+ if (sourceType === 'OpenAIAds') {+ if (!['campaign_id', 'start_time', 'impressions', 'clicks', 'spend'].every((field) => field in table.fields)) {+ return null+ }+ if (tileColumnSelection === MarketingAnalyticsColumnsSchemaNames.Cost && !('currency_code' in table.fields)) {+ return null+ }+ }+// Handle ROAS (Return on Ad Spend) - calculated as conversion_value / costif (tileColumnSelection === 'roas') {const costExpr = buildNativeCostExpr(tileConfig.columnMappings)diff --git a/posthog/schema.py b/posthog/schema.pyindex 495fd76cdfe7..696be586eab1 100644--- a/posthog/schema.py+++ b/posthog/schema.py@@ -207,6 +207,7 @@ from posthog.schema_enums import (NativeMarketingSource as NativeMarketingSource,NeighborDirection as NeighborDirection,NodeKind as NodeKind,+ OpenAIAdsDefaultSources as OpenAIAdsDefaultSources,Operator as Operator,OrderBy as OrderBy,OrderDirection as OrderDirection,@@ -2121,6 +2122,19 @@ class MarketingIntegrationConfig9(BaseModel):statsTableName: Literal["campaign_report"] = "campaign_report"+class MarketingIntegrationConfig10(BaseModel):+ model_config = ConfigDict(+ extra="forbid",+ )+ campaignTableName: Literal["campaigns"] = "campaigns"+ defaultSources: list[str] = Field(..., max_length=3, min_length=3)+ idField: Literal["id"] = "id"+ nameField: Literal["name"] = "name"+ primarySource: Literal["openai"] = "openai"+ sourceType: Literal["OpenAIAds"] = "OpenAIAds"+ statsTableName: Literal["campaign_insights"] = "campaign_insights"++class MarketingIntegrationConfig(RootModel[MarketingIntegrationConfig1@@ -2132,6 +2146,7 @@ class MarketingIntegrationConfig(| MarketingIntegrationConfig7| MarketingIntegrationConfig8| MarketingIntegrationConfig9+ | MarketingIntegrationConfig10]):root: (@@ -2144,6 +2159,7 @@ class MarketingIntegrationConfig(| MarketingIntegrationConfig7| MarketingIntegrationConfig8| MarketingIntegrationConfig9+ | MarketingIntegrationConfig10)diff --git a/posthog/schema_enums.py b/posthog/schema_enums.pyindex 91e226d3eda1..06b594ced8a6 100644--- a/posthog/schema_enums.py+++ b/posthog/schema_enums.py@@ -2093,6 +2093,7 @@ class NativeMarketingSource(StrEnum):SNAPCHAT_ADS = "SnapchatAds"PINTEREST_ADS = "PinterestAds"APPLE_SEARCH_ADS = "AppleSearchAds"+ OPEN_AI_ADS = "OpenAIAds"class NodeKind(StrEnum):@@ -2213,6 +2214,12 @@ class NodeKind(StrEnum):PROPERTY_VALUES_QUERY = "PropertyValuesQuery"+class OpenAIAdsDefaultSources(StrEnum):+ OPENAI = "openai"+ CHATGPT = "chatgpt"+ OPENAI_ADS = "openai_ads"++class PathType(StrEnum):FIELD_PAGEVIEW = "$pageview"FIELD_SCREEN = "$screen"diff --git a/products/marketing_analytics/backend/demo/health.py b/products/marketing_analytics/backend/demo/health.pyindex 896ab58b029b..16ffba83b8f2 100644--- a/products/marketing_analytics/backend/demo/health.py+++ b/products/marketing_analytics/backend/demo/health.py@@ -48,7 +48,7 @@ UNCONNECTED_PLATFORMS: frozenset[str] = frozenset({"RedditAds"})# suppresses, so they reach `events_only` and draw no suggestion. That's the mirror of# Reddit and the pair is the point of the fixture. Named here so the dry-run summary can# count them — deriving `events_only` from PLATFORM_STATES alone silently misses them.-ORGANIC_ONLY_PLATFORMS: frozenset[str] = frozenset({"PinterestAds"})+ORGANIC_ONLY_PLATFORMS: frozenset[str] = frozenset({"OpenAIAds", "PinterestAds"})def _create_job(@@ -115,10 +115,10 @@ def stage_schemas_and_jobs(if source is None: # deliberately unconnectedcontinuefor schema_name in schema_names:- schema_status: str | None = ExternalDataSchemaStatus.COMPLETED+ schema_status: str | None = str(ExternalDataSchemaStatus.COMPLETED)should_sync = Trueif state == "tables_failed" and schema_name == schema_names[-1]:- schema_status = ExternalDataSchemaStatus.FAILED+ schema_status = str(ExternalDataSchemaStatus.FAILED)if state == "tables_disabled" and schema_name == schema_names[-1]:should_sync = Falseif state == "never":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 276d774404d2..d7b5fbeab837 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, %(hogql_val_73)s]), %(hogql_val_74)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_75)s)), events__session.`$entry_utm_source`, %(hogql_val_76)s))))))), and(and(equals(events.event, %(hogql_val_77)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, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_74)s)), events__session.`$entry_utm_source`, %(hogql_val_75)s)), [%(hogql_val_76)s, %(hogql_val_77)s, %(hogql_val_78)s]), %(hogql_val_79)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_80)s)), events__session.`$entry_utm_source`, %(hogql_val_81)s)))))))), and(and(equals(events.event, %(hogql_val_82)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_78)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_79)s, %(hogql_val_80)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_81)s, 6, %(hogql_val_82)s))), and(equals(events.event, %(hogql_val_83)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_84)s, %(hogql_val_85)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_86)s, 6, %(hogql_val_87)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_88)s)), minus(conv_bounds.first_conversion, 345600)))))+ WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_83)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_84)s, %(hogql_val_85)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_86)s, 6, %(hogql_val_87)s))), and(equals(events.event, %(hogql_val_88)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_89)s, %(hogql_val_90)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_91)s, 6, %(hogql_val_92)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_93)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@@ -254,7 +254,7 @@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_41)s)), cached_sessions.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(cached_sessions.utm_source, %(hogql_val_47)s)), cached_sessions.utm_source, %(hogql_val_48)s)), [%(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s]), %(hogql_val_57)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_58)s)), cached_sessions.utm_source, %(hogql_val_59)s)), [%(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_62)s)), cached_sessions.utm_source, %(hogql_val_63)s)), [%(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(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(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_80)s)), cached_sessions.utm_source, %(hogql_val_81)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_41)s)), cached_sessions.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(cached_sessions.utm_source, %(hogql_val_47)s)), cached_sessions.utm_source, %(hogql_val_48)s)), [%(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s]), %(hogql_val_57)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_58)s)), cached_sessions.utm_source, %(hogql_val_59)s)), [%(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_62)s)), cached_sessions.utm_source, %(hogql_val_63)s)), [%(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(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, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_79)s)), cached_sessions.utm_source, %(hogql_val_80)s)), [%(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s]), %(hogql_val_84)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_85)s)), cached_sessions.utm_source, %(hogql_val_86)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)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 b124854ac9bb..1646ec9394e7 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, %(hogql_val_71)s]), %(hogql_val_72)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_73)s)), events__session.`$entry_utm_source`, %(hogql_val_74)s))))))), and(and(equals(events.event, %(hogql_val_75)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, 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(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_78)s)), events__session.`$entry_utm_source`, %(hogql_val_79)s)))))))), and(and(equals(events.event, %(hogql_val_80)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_76)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_77)s, %(hogql_val_78)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_79)s, 6, %(hogql_val_80)s))), and(equals(events.event, %(hogql_val_81)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_82)s, %(hogql_val_83)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_84)s, 6, %(hogql_val_85)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_86)s)), minus(conv_bounds.first_conversion, 345600)))))+ WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_81)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_82)s, %(hogql_val_83)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_84)s, 6, %(hogql_val_85)s))), and(equals(events.event, %(hogql_val_86)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_87)s, %(hogql_val_88)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_89)s, 6, %(hogql_val_90)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_91)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@@ -254,7 +254,7 @@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_39)s)), cached_sessions.utm_source, %(hogql_val_40)s)), [%(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_45)s)), cached_sessions.utm_source, %(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, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_56)s)), cached_sessions.utm_source, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_60)s)), cached_sessions.utm_source, %(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, %(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(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_78)s)), cached_sessions.utm_source, %(hogql_val_79)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_39)s)), cached_sessions.utm_source, %(hogql_val_40)s)), [%(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_45)s)), cached_sessions.utm_source, %(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, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_56)s)), cached_sessions.utm_source, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_60)s)), cached_sessions.utm_source, %(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, %(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, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_77)s)), cached_sessions.utm_source, %(hogql_val_78)s)), [%(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s]), %(hogql_val_82)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_83)s)), cached_sessions.utm_source, %(hogql_val_84)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)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 8dd9052aede6..f431c09df15a 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, %(hogql_val_45)s]), %(hogql_val_46)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)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, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_46)s)), events__session.`$entry_utm_source`, %(hogql_val_47)s)), [%(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s]), %(hogql_val_51)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_52)s)), events__session.`$entry_utm_source`, %(hogql_val_53)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_49)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_50)s, %(hogql_val_51)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_52)s, 6, %(hogql_val_53)s)))+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_54)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_55)s, %(hogql_val_56)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_57)s, 6, %(hogql_val_58)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_73)s)), coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_74)s), ''), 'null'), '^"|"$', ''), %(hogql_val_75)s), 0.0)), and(equals(events.event, %(hogql_val_76)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_77)s), toDateTime(%(hogql_val_78)s, %(hogql_val_79)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_80)s), toDateTime64(%(hogql_val_81)s, 6, %(hogql_val_82)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_83)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_84)s), toDateTime(%(hogql_val_85)s, %(hogql_val_86)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_87)s), toDateTime64(%(hogql_val_88)s, 6, %(hogql_val_89)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_90)s)), events__session.`$entry_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(events__session.`$entry_utm_source`, %(hogql_val_96)s)), events__session.`$entry_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(events__session.`$entry_utm_source`, %(hogql_val_107)s)), events__session.`$entry_utm_source`, %(hogql_val_108)s)), [%(hogql_val_109)s]), %(hogql_val_110)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_111)s)), events__session.`$entry_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(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, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_129)s)), events__session.`$entry_utm_source`, %(hogql_val_130)s))))))), and(and(equals(events.event, %(hogql_val_131)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_78)s)), coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_79)s), ''), 'null'), '^"|"$', ''), %(hogql_val_80)s), 0.0)), and(equals(events.event, %(hogql_val_81)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_82)s), toDateTime(%(hogql_val_83)s, %(hogql_val_84)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_85)s), toDateTime64(%(hogql_val_86)s, 6, %(hogql_val_87)s))))), -500) AS conversions, countIf(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)))) 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_95)s)), events__session.`$entry_utm_source`, %(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(events__session.`$entry_utm_source`, %(hogql_val_101)s)), events__session.`$entry_utm_source`, %(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, %(hogql_val_109)s, %(hogql_val_110)s]), %(hogql_val_111)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_112)s)), events__session.`$entry_utm_source`, %(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]), %(hogql_val_127)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_128)s)), events__session.`$entry_utm_source`, %(hogql_val_129)s)), [%(hogql_val_130)s, %(hogql_val_131)s]), %(hogql_val_132)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_133)s)), events__session.`$entry_utm_source`, %(hogql_val_134)s)), [%(hogql_val_135)s, %(hogql_val_136)s, %(hogql_val_137)s]), %(hogql_val_138)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_139)s)), events__session.`$entry_utm_source`, %(hogql_val_140)s)))))))), and(and(equals(events.event, %(hogql_val_141)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_54)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_55)s), %(hogql_val_56)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_59)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_60)s), %(hogql_val_61)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_57)s, %(hogql_val_58)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_59)s, 6, %(hogql_val_60)s), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_61)s, %(hogql_val_62)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_63)s, 6, %(hogql_val_64)s), toIntervalDay(3))))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_65)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_62)s, %(hogql_val_63)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_64)s, 6, %(hogql_val_65)s), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_66)s, %(hogql_val_67)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_68)s, 6, %(hogql_val_69)s), toIntervalDay(3))))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_70)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_66)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_67)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_71)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_72)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_68)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_71)s, 6, %(hogql_val_72)s)))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_73)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_74)s, %(hogql_val_75)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_76)s, 6, %(hogql_val_77)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_132)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_133)s, %(hogql_val_134)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_135)s, 6, %(hogql_val_136)s))), and(equals(events.event, %(hogql_val_137)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_138)s, %(hogql_val_139)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_140)s, 6, %(hogql_val_141)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_142)s)), minus(conv_bounds.first_conversion, 345600)))))+ WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_142)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_143)s, %(hogql_val_144)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_145)s, 6, %(hogql_val_146)s))), and(equals(events.event, %(hogql_val_147)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_148)s, %(hogql_val_149)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_150)s, 6, %(hogql_val_151)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_152)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_143)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_144)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_145)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 (@@ -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_146)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)@@ -322,7 +322,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_41)s)), cached_sessions.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(cached_sessions.utm_source, %(hogql_val_47)s)), cached_sessions.utm_source, %(hogql_val_48)s)), [%(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s]), %(hogql_val_57)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_58)s)), cached_sessions.utm_source, %(hogql_val_59)s)), [%(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_62)s)), cached_sessions.utm_source, %(hogql_val_63)s)), [%(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(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(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_80)s)), cached_sessions.utm_source, %(hogql_val_81)s)))))) AS breakdown_value+ SELECT cached_sessions.person_id AS person_id, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_41)s)), cached_sessions.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(cached_sessions.utm_source, %(hogql_val_47)s)), cached_sessions.utm_source, %(hogql_val_48)s)), [%(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s, %(hogql_val_52)s, %(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s]), %(hogql_val_57)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_58)s)), cached_sessions.utm_source, %(hogql_val_59)s)), [%(hogql_val_60)s]), %(hogql_val_61)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_62)s)), cached_sessions.utm_source, %(hogql_val_63)s)), [%(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s, %(hogql_val_68)s, %(hogql_val_69)s, %(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, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_79)s)), cached_sessions.utm_source, %(hogql_val_80)s)), [%(hogql_val_81)s, %(hogql_val_82)s, %(hogql_val_83)s]), %(hogql_val_84)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_85)s)), cached_sessions.utm_source, %(hogql_val_86)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 (@@ -332,7 +332,7 @@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_82)s)), cached_sessions.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(cached_sessions.utm_source, %(hogql_val_88)s)), cached_sessions.utm_source, %(hogql_val_89)s)), [%(hogql_val_90)s, %(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, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_99)s)), cached_sessions.utm_source, %(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, %(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, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_115)s)), cached_sessions.utm_source, %(hogql_val_116)s)), [%(hogql_val_117)s, %(hogql_val_118)s, %(hogql_val_119)s]), %(hogql_val_120)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_121)s)), cached_sessions.utm_source, %(hogql_val_122)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_87)s)), cached_sessions.utm_source, %(hogql_val_88)s)), [%(hogql_val_89)s, %(hogql_val_90)s, %(hogql_val_91)s]), %(hogql_val_92)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_93)s)), cached_sessions.utm_source, %(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]), %(hogql_val_103)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_104)s)), cached_sessions.utm_source, %(hogql_val_105)s)), [%(hogql_val_106)s]), %(hogql_val_107)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_108)s)), cached_sessions.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]), %(hogql_val_119)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_120)s)), cached_sessions.utm_source, %(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(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_131)s)), cached_sessions.utm_source, %(hogql_val_132)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)@@ -340,7 +340,7 @@WHERE 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_123)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_124)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_125)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_133)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_134)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_135)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 (@@ -350,7 +350,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_126)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_136)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 104ad0531dd3..cf98aec5000c 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, %(hogql_val_45)s]), %(hogql_val_46)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)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, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_46)s)), events__session.`$entry_utm_source`, %(hogql_val_47)s)), [%(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s]), %(hogql_val_51)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_52)s)), events__session.`$entry_utm_source`, %(hogql_val_53)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_49)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_50)s, %(hogql_val_51)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_52)s, 6, %(hogql_val_53)s)))+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_54)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_55)s, %(hogql_val_56)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_57)s, 6, %(hogql_val_58)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_73)s)), coalesce(accurateCastOrNull(events.properties.revenue, 'Float64'), 0.0)), and(equals(events.event, %(hogql_val_74)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_75)s), toDateTime(%(hogql_val_76)s, %(hogql_val_77)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_78)s), toDateTime64(%(hogql_val_79)s, 6, %(hogql_val_80)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_81)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_82)s), toDateTime(%(hogql_val_83)s, %(hogql_val_84)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_85)s), toDateTime64(%(hogql_val_86)s, 6, %(hogql_val_87)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_88)s)), events__session.`$entry_utm_source`, %(hogql_val_89)s)), [%(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s]), %(hogql_val_93)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_94)s)), events__session.`$entry_utm_source`, %(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, %(hogql_val_103)s]), %(hogql_val_104)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_105)s)), events__session.`$entry_utm_source`, %(hogql_val_106)s)), [%(hogql_val_107)s]), %(hogql_val_108)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_109)s)), events__session.`$entry_utm_source`, %(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, %(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, %(hogql_val_125)s]), %(hogql_val_126)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_127)s)), events__session.`$entry_utm_source`, %(hogql_val_128)s))))))), and(and(equals(events.event, %(hogql_val_129)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_78)s)), coalesce(accurateCastOrNull(events.properties.revenue, 'Float64'), 0.0)), and(equals(events.event, %(hogql_val_79)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_80)s), toDateTime(%(hogql_val_81)s, %(hogql_val_82)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_83)s), toDateTime64(%(hogql_val_84)s, 6, %(hogql_val_85)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_86)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_87)s), toDateTime(%(hogql_val_88)s, %(hogql_val_89)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_90)s), toDateTime64(%(hogql_val_91)s, 6, %(hogql_val_92)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_93)s)), events__session.`$entry_utm_source`, %(hogql_val_94)s)), [%(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s]), %(hogql_val_98)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_99)s)), events__session.`$entry_utm_source`, %(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]), %(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, 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]), %(hogql_val_125)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_126)s)), events__session.`$entry_utm_source`, %(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, %(hogql_val_135)s]), %(hogql_val_136)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_137)s)), events__session.`$entry_utm_source`, %(hogql_val_138)s)))))))), and(and(equals(events.event, %(hogql_val_139)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_54)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_55)s), %(hogql_val_56)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_59)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_60)s), %(hogql_val_61)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_57)s, %(hogql_val_58)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_59)s, 6, %(hogql_val_60)s), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_61)s, %(hogql_val_62)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_63)s, 6, %(hogql_val_64)s), toIntervalDay(3))))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_65)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_62)s, %(hogql_val_63)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_64)s, 6, %(hogql_val_65)s), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_66)s, %(hogql_val_67)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_68)s, 6, %(hogql_val_69)s), toIntervalDay(3))))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_70)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_66)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_67)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_71)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_72)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_68)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_71)s, 6, %(hogql_val_72)s)))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_73)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_74)s, %(hogql_val_75)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_76)s, 6, %(hogql_val_77)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_130)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_131)s, %(hogql_val_132)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_133)s, 6, %(hogql_val_134)s))), and(equals(events.event, %(hogql_val_135)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_136)s, %(hogql_val_137)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_138)s, 6, %(hogql_val_139)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_140)s)), minus(conv_bounds.first_conversion, 345600)))))+ WHERE and(equals(events.team_id, 420), or(and(equals(events.event, %(hogql_val_140)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_141)s, %(hogql_val_142)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_143)s, 6, %(hogql_val_144)s))), and(equals(events.event, %(hogql_val_145)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_146)s, %(hogql_val_147)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_148)s, 6, %(hogql_val_149)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_150)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_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_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 (@@ -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_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_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)@@ -322,7 +322,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_39)s)), cached_sessions.utm_source, %(hogql_val_40)s)), [%(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_45)s)), cached_sessions.utm_source, %(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, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_56)s)), cached_sessions.utm_source, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_60)s)), cached_sessions.utm_source, %(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, %(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(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_78)s)), cached_sessions.utm_source, %(hogql_val_79)s)))))) AS breakdown_value+ SELECT cached_sessions.person_id AS person_id, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_39)s)), cached_sessions.utm_source, %(hogql_val_40)s)), [%(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s]), %(hogql_val_44)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_45)s)), cached_sessions.utm_source, %(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, %(hogql_val_53)s, %(hogql_val_54)s]), %(hogql_val_55)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_56)s)), cached_sessions.utm_source, %(hogql_val_57)s)), [%(hogql_val_58)s]), %(hogql_val_59)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_60)s)), cached_sessions.utm_source, %(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, %(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, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_77)s)), cached_sessions.utm_source, %(hogql_val_78)s)), [%(hogql_val_79)s, %(hogql_val_80)s, %(hogql_val_81)s]), %(hogql_val_82)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_83)s)), cached_sessions.utm_source, %(hogql_val_84)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 (@@ -332,7 +332,7 @@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_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, %(hogql_val_90)s, %(hogql_val_91)s, %(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s]), %(hogql_val_96)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_97)s)), cached_sessions.utm_source, %(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, %(hogql_val_105)s, %(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, 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, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_119)s)), cached_sessions.utm_source, %(hogql_val_120)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_85)s)), cached_sessions.utm_source, %(hogql_val_86)s)), [%(hogql_val_87)s, %(hogql_val_88)s, %(hogql_val_89)s]), %(hogql_val_90)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_91)s)), cached_sessions.utm_source, %(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]), %(hogql_val_101)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_102)s)), cached_sessions.utm_source, %(hogql_val_103)s)), [%(hogql_val_104)s]), %(hogql_val_105)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_106)s)), cached_sessions.utm_source, %(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]), %(hogql_val_117)s, if(in(lower(if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_118)s)), cached_sessions.utm_source, %(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(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_129)s)), cached_sessions.utm_source, %(hogql_val_130)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)@@ -340,7 +340,7 @@WHERE 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_121)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_122)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_123)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_131)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_132)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_133)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 (@@ -350,7 +350,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_124)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_134)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 67e80ee06133..6e22d857ecdc 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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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 a383e9c0c097..47e898c9f86a 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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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 638f4c562609..53558043c790 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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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 68ed2ec4d225..0e93220d80cf 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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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 1f227f8be757..434ff4ea20b4 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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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 a321b26905e4..dc9d42f855d1 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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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')))), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')))), ['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(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 703ce0c503d3..edc1d8302e8d 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')), ['apple_search_ads', 'apple_ads', 'asa']), 'apple', 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')), ['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(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, %(hogql_val_45)s]), %(hogql_val_46)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)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, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_46)s)), events__session.`$entry_utm_source`, %(hogql_val_47)s)), [%(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s]), %(hogql_val_51)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_52)s)), events__session.`$entry_utm_source`, %(hogql_val_53)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_49)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_50)s, %(hogql_val_51)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_52)s, %(hogql_val_53)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_54)s, %(hogql_val_55)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_56)s, %(hogql_val_57)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_54)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_55)s, %(hogql_val_56)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_57)s, %(hogql_val_58)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_59)s, %(hogql_val_60)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_61)s, %(hogql_val_62)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_58)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_59)s, %(hogql_val_60)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_61)s, %(hogql_val_62)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_63)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_64)s, %(hogql_val_65)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_66)s, %(hogql_val_67)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_63)s, toStartOfWeek(toDateTime(%(hogql_val_64)s, %(hogql_val_65)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_66)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_68)s, toStartOfWeek(toDateTime(%(hogql_val_69)s, %(hogql_val_70)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_71)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_67)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_68)s, %(hogql_val_69)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_70)s, %(hogql_val_71)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_72)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_73)s, %(hogql_val_74)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_75)s, %(hogql_val_76)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_72)s, toStartOfWeek(toDateTime(%(hogql_val_73)s, %(hogql_val_74)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_75)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_size+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_77)s, toStartOfWeek(toDateTime(%(hogql_val_78)s, %(hogql_val_79)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_80)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_76)s, toStartOfWeek(toDateTime(%(hogql_val_77)s, %(hogql_val_78)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_79)s), 0)) AS cohort_index, minus(activity.activity_index, 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 intervals_from_base, count(DISTINCT acquisition.actor_id) AS count+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_81)s, toStartOfWeek(toDateTime(%(hogql_val_82)s, %(hogql_val_83)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_84)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_85)s, toStartOfWeek(toDateTime(%(hogql_val_86)s, %(hogql_val_87)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_88)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_84)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_89)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_85)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_90)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, %(hogql_val_45)s]), %(hogql_val_46)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)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, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_46)s)), events__session.`$entry_utm_source`, %(hogql_val_47)s)), [%(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s]), %(hogql_val_51)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_52)s)), events__session.`$entry_utm_source`, %(hogql_val_53)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_49)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_50)s, %(hogql_val_51)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_52)s, %(hogql_val_53)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_54)s, %(hogql_val_55)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_56)s, %(hogql_val_57)s)), 0))+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_54)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_55)s, %(hogql_val_56)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_57)s, %(hogql_val_58)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_59)s, %(hogql_val_60)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_61)s, %(hogql_val_62)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_58)s, toStartOfWeek(toDateTime(%(hogql_val_59)s, %(hogql_val_60)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_61)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_63)s, toStartOfWeek(toDateTime(%(hogql_val_64)s, %(hogql_val_65)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_66)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_62)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_63)s, %(hogql_val_64)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_65)s, %(hogql_val_66)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_67)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_68)s, %(hogql_val_69)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_70)s, %(hogql_val_71)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_67)s, toStartOfWeek(toDateTime(%(hogql_val_68)s, %(hogql_val_69)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_70)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_size+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_72)s, toStartOfWeek(toDateTime(%(hogql_val_73)s, %(hogql_val_74)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_75)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_71)s, toStartOfWeek(toDateTime(%(hogql_val_72)s, %(hogql_val_73)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_74)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_75)s, toStartOfWeek(toDateTime(%(hogql_val_76)s, %(hogql_val_77)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_78)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS count+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_76)s, toStartOfWeek(toDateTime(%(hogql_val_77)s, %(hogql_val_78)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_79)s), 0)) AS cohort_index, minus(activity.activity_index, 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 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_79)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_84)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_80)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_85)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, %(hogql_val_67)s]), %(hogql_val_68)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_69)s)), events__session.`$entry_utm_source`, %(hogql_val_70)s)))))), events__session.`$start_timestamp`) AS breakdown_value, 0 AS previous, %(hogql_val_71)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, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_68)s)), events__session.`$entry_utm_source`, %(hogql_val_69)s)), [%(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s]), %(hogql_val_73)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_74)s)), events__session.`$entry_utm_source`, %(hogql_val_75)s))))))), events__session.`$start_timestamp`) AS breakdown_value, 0 AS previous, %(hogql_val_76)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_72)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_73)s, %(hogql_val_74)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_75)s, %(hogql_val_76)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_77)s, %(hogql_val_78)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_79)s, %(hogql_val_80)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_77)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_78)s, %(hogql_val_79)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_80)s, %(hogql_val_81)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_82)s, %(hogql_val_83)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_84)s, %(hogql_val_85)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_81)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_82)s, %(hogql_val_83)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_84)s, %(hogql_val_85)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_86)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_87)s, %(hogql_val_88)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_89)s, %(hogql_val_90)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_94)s)), events__session.`$entry_utm_source`, %(hogql_val_95)s)), [%(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s]), %(hogql_val_99)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_100)s)), events__session.`$entry_utm_source`, %(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, %(hogql_val_109)s]), %(hogql_val_110)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_111)s)), events__session.`$entry_utm_source`, %(hogql_val_112)s)), [%(hogql_val_113)s]), %(hogql_val_114)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_115)s)), events__session.`$entry_utm_source`, %(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, %(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, %(hogql_val_131)s]), %(hogql_val_132)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_133)s)), events__session.`$entry_utm_source`, %(hogql_val_134)s)))))), events__session.`$start_timestamp`) AS breakdown_value, 1 AS previous, %(hogql_val_135)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_99)s)), events__session.`$entry_utm_source`, %(hogql_val_100)s)), [%(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s]), %(hogql_val_104)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_105)s)), events__session.`$entry_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, 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, 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]), %(hogql_val_131)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_132)s)), events__session.`$entry_utm_source`, %(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, %(hogql_val_141)s]), %(hogql_val_142)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_143)s)), events__session.`$entry_utm_source`, %(hogql_val_144)s))))))), events__session.`$start_timestamp`) AS breakdown_value, 1 AS previous, %(hogql_val_145)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_86)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_87)s), %(hogql_val_88)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_91)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_92)s), %(hogql_val_93)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_89)s, %(hogql_val_90)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_91)s, %(hogql_val_92)s), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_93)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_94)s, %(hogql_val_95)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_96)s, %(hogql_val_97)s), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_98)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_136)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_137)s, %(hogql_val_138)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_139)s, %(hogql_val_140)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_141)s, %(hogql_val_142)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_143)s, %(hogql_val_144)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_146)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_147)s, %(hogql_val_148)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_149)s, %(hogql_val_150)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_151)s, %(hogql_val_152)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_153)s, %(hogql_val_154)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_145)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_146)s, %(hogql_val_147)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_148)s, %(hogql_val_149)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_155)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_156)s, %(hogql_val_157)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_158)s, %(hogql_val_159)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_150)s)) AS `$start_timestamp`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_160)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_151)s, %(hogql_val_152)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_153)s, %(hogql_val_154)s), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_155)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_161)s, %(hogql_val_162)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_163)s, %(hogql_val_164)s), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_165)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_156)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_157)s, %(hogql_val_158)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_159)s, %(hogql_val_160)s)), notEquals(events.`$session_id`, acquisition.first_session_id), greater(toDate(events__session.`$start_timestamp`), toDate(toTimeZone(acquisition.first_session_at, %(hogql_val_161)s))), lessOrEquals(events__session.`$start_timestamp`, plus(toTimeZone(acquisition.first_session_at, %(hogql_val_162)s), toIntervalDay(30))), ifNull(lessOrEquals(events__session.`$start_timestamp`, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_163)s)), 0))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_166)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_167)s, %(hogql_val_168)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_169)s, %(hogql_val_170)s)), notEquals(events.`$session_id`, acquisition.first_session_id), greater(toDate(events__session.`$start_timestamp`), toDate(toTimeZone(acquisition.first_session_at, %(hogql_val_171)s))), lessOrEquals(events__session.`$start_timestamp`, plus(toTimeZone(acquisition.first_session_at, %(hogql_val_172)s), toIntervalDay(30))), ifNull(lessOrEquals(events__session.`$start_timestamp`, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_173)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_164)s) AS first_session_at, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_165)s) AS observation_end, toTimeZone(activity.returned_at, %(hogql_val_166)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_174)s) AS first_session_at, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_175)s) AS observation_end, toTimeZone(activity.returned_at, %(hogql_val_176)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 78ae490761c6..1a0deeb8fbea 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, %(hogql_val_45)s]), %(hogql_val_46)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)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, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_46)s)), events__session.`$entry_utm_source`, %(hogql_val_47)s)), [%(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s]), %(hogql_val_51)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_52)s)), events__session.`$entry_utm_source`, %(hogql_val_53)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_49)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_50)s, %(hogql_val_51)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_52)s, %(hogql_val_53)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_54)s, %(hogql_val_55)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_56)s, %(hogql_val_57)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_54)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_55)s, %(hogql_val_56)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_57)s, %(hogql_val_58)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_59)s, %(hogql_val_60)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_61)s, %(hogql_val_62)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_58)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_59)s, %(hogql_val_60)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_61)s, %(hogql_val_62)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_63)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_64)s, %(hogql_val_65)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_66)s, %(hogql_val_67)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_63)s, toStartOfWeek(toDateTime(%(hogql_val_64)s, %(hogql_val_65)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_66)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_68)s, toStartOfWeek(toDateTime(%(hogql_val_69)s, %(hogql_val_70)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_71)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_67)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_68)s, %(hogql_val_69)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_70)s, %(hogql_val_71)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_72)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_73)s, %(hogql_val_74)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_75)s, %(hogql_val_76)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_72)s, toStartOfWeek(toDateTime(%(hogql_val_73)s, %(hogql_val_74)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_75)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_size+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_77)s, toStartOfWeek(toDateTime(%(hogql_val_78)s, %(hogql_val_79)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_80)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_76)s, toStartOfWeek(toDateTime(%(hogql_val_77)s, %(hogql_val_78)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_79)s), 0)) AS cohort_index, minus(activity.activity_index, 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 intervals_from_base, count(DISTINCT acquisition.actor_id) AS count+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_81)s, toStartOfWeek(toDateTime(%(hogql_val_82)s, %(hogql_val_83)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_84)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_85)s, toStartOfWeek(toDateTime(%(hogql_val_86)s, %(hogql_val_87)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_88)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_84)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_89)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_85)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_90)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, %(hogql_val_45)s]), %(hogql_val_46)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)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, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_46)s)), events__session.`$entry_utm_source`, %(hogql_val_47)s)), [%(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s]), %(hogql_val_51)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_52)s)), events__session.`$entry_utm_source`, %(hogql_val_53)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_49)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_50)s, %(hogql_val_51)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_52)s, %(hogql_val_53)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_54)s, %(hogql_val_55)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_56)s, %(hogql_val_57)s)), 0))+ WHERE and(equals(events.team_id, 420), and(equals(events.event, %(hogql_val_54)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_55)s, %(hogql_val_56)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_57)s, %(hogql_val_58)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_59)s, %(hogql_val_60)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_61)s, %(hogql_val_62)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_58)s, toStartOfWeek(toDateTime(%(hogql_val_59)s, %(hogql_val_60)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_61)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_63)s, toStartOfWeek(toDateTime(%(hogql_val_64)s, %(hogql_val_65)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_66)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_62)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_63)s, %(hogql_val_64)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_65)s, %(hogql_val_66)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_67)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_68)s, %(hogql_val_69)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_70)s, %(hogql_val_71)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_67)s, toStartOfWeek(toDateTime(%(hogql_val_68)s, %(hogql_val_69)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_70)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_size+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_72)s, toStartOfWeek(toDateTime(%(hogql_val_73)s, %(hogql_val_74)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_75)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_71)s, toStartOfWeek(toDateTime(%(hogql_val_72)s, %(hogql_val_73)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_74)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_75)s, toStartOfWeek(toDateTime(%(hogql_val_76)s, %(hogql_val_77)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_78)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS count+ SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_76)s, toStartOfWeek(toDateTime(%(hogql_val_77)s, %(hogql_val_78)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_79)s), 0)) AS cohort_index, minus(activity.activity_index, 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 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_79)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_84)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_80)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_85)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, %(hogql_val_67)s]), %(hogql_val_68)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_69)s)), events__session.`$entry_utm_source`, %(hogql_val_70)s)))))), events__session.`$start_timestamp`) AS breakdown_value, 0 AS previous, %(hogql_val_71)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, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_68)s)), events__session.`$entry_utm_source`, %(hogql_val_69)s)), [%(hogql_val_70)s, %(hogql_val_71)s, %(hogql_val_72)s]), %(hogql_val_73)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_74)s)), events__session.`$entry_utm_source`, %(hogql_val_75)s))))))), events__session.`$start_timestamp`) AS breakdown_value, 0 AS previous, %(hogql_val_76)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_72)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_73)s, %(hogql_val_74)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_75)s, %(hogql_val_76)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_77)s, %(hogql_val_78)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_79)s, %(hogql_val_80)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_77)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_78)s, %(hogql_val_79)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_80)s, %(hogql_val_81)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_82)s, %(hogql_val_83)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_84)s, %(hogql_val_85)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_81)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_82)s, %(hogql_val_83)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_84)s, %(hogql_val_85)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_86)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_87)s, %(hogql_val_88)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_89)s, %(hogql_val_90)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_94)s)), events__session.`$entry_utm_source`, %(hogql_val_95)s)), [%(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s]), %(hogql_val_99)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_100)s)), events__session.`$entry_utm_source`, %(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, %(hogql_val_109)s]), %(hogql_val_110)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_111)s)), events__session.`$entry_utm_source`, %(hogql_val_112)s)), [%(hogql_val_113)s]), %(hogql_val_114)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_115)s)), events__session.`$entry_utm_source`, %(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, %(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, %(hogql_val_131)s]), %(hogql_val_132)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_133)s)), events__session.`$entry_utm_source`, %(hogql_val_134)s)))))), events__session.`$start_timestamp`) AS breakdown_value, 1 AS previous, %(hogql_val_135)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_99)s)), events__session.`$entry_utm_source`, %(hogql_val_100)s)), [%(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s]), %(hogql_val_104)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_105)s)), events__session.`$entry_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, 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, 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]), %(hogql_val_131)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_132)s)), events__session.`$entry_utm_source`, %(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, %(hogql_val_141)s]), %(hogql_val_142)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_143)s)), events__session.`$entry_utm_source`, %(hogql_val_144)s))))))), events__session.`$start_timestamp`) AS breakdown_value, 1 AS previous, %(hogql_val_145)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_86)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_87)s), %(hogql_val_88)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_91)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_92)s), %(hogql_val_93)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_89)s, %(hogql_val_90)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_91)s, %(hogql_val_92)s), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_93)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_94)s, %(hogql_val_95)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_96)s, %(hogql_val_97)s), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_98)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_136)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_137)s, %(hogql_val_138)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_139)s, %(hogql_val_140)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_141)s, %(hogql_val_142)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_143)s, %(hogql_val_144)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_146)s), notEmpty(events.properties.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_147)s, %(hogql_val_148)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_149)s, %(hogql_val_150)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_151)s, %(hogql_val_152)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_153)s, %(hogql_val_154)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_145)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_146)s, %(hogql_val_147)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_148)s, %(hogql_val_149)s))))))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_155)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_156)s, %(hogql_val_157)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_158)s, %(hogql_val_159)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_150)s)) AS `$start_timestamp`, raw_sessions.session_id_v7 AS session_id_v7+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_160)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_151)s, %(hogql_val_152)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_153)s, %(hogql_val_154)s), toIntervalDay(3))))- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_155)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_161)s, %(hogql_val_162)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_163)s, %(hogql_val_164)s), toIntervalDay(3))))+ GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.properties.`$session_id`, %(hogql_val_165)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_156)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_157)s, %(hogql_val_158)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_159)s, %(hogql_val_160)s)), notEquals(events.properties.`$session_id`, acquisition.first_session_id), greater(toDate(events__session.`$start_timestamp`), toDate(toTimeZone(acquisition.first_session_at, %(hogql_val_161)s))), lessOrEquals(events__session.`$start_timestamp`, plus(toTimeZone(acquisition.first_session_at, %(hogql_val_162)s), toIntervalDay(30))), ifNull(lessOrEquals(events__session.`$start_timestamp`, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_163)s)), 0))+ WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_166)s), notEmpty(events.properties.`$session_id`), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_167)s, %(hogql_val_168)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_169)s, %(hogql_val_170)s)), notEquals(events.properties.`$session_id`, acquisition.first_session_id), greater(toDate(events__session.`$start_timestamp`), toDate(toTimeZone(acquisition.first_session_at, %(hogql_val_171)s))), lessOrEquals(events__session.`$start_timestamp`, plus(toTimeZone(acquisition.first_session_at, %(hogql_val_172)s), toIntervalDay(30))), ifNull(lessOrEquals(events__session.`$start_timestamp`, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_173)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_164)s) AS first_session_at, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_165)s) AS observation_end, toTimeZone(activity.returned_at, %(hogql_val_166)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_174)s) AS first_session_at, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_175)s) AS observation_end, toTimeZone(activity.returned_at, %(hogql_val_176)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 65557c252176..076f45dd0b60 100644--- a/products/marketing_analytics/backend/hogql_queries/adapters/factory.py+++ b/products/marketing_analytics/backend/hogql_queries/adapters/factory.py@@ -48,6 +48,7 @@ from .base import ()from .bigquery import BigQueryAdapterfrom .google_ads import GoogleAdsAdapter+from .openai_ads import OpenAIAdsAdapterfrom .self_managed import AWSAdapter, AzureAdapter, CloudflareR2Adapter, GoogleCloudAdapterlogger = structlog.get_logger(__name__)@@ -79,6 +80,7 @@ class MarketingSourceFactory:_adapter_registry: dict[str, type[MarketingSourceAdapter]] = {# Native adapters"AppleSearchAds": AppleSearchAdsAdapter,+ "OpenAIAds": OpenAIAdsAdapter,"GoogleAds": GoogleAdsAdapter,"LinkedinAds": LinkedinAdsAdapter,"RedditAds": RedditAdsAdapter,@@ -100,6 +102,7 @@ class MarketingSourceFactory:# optionally in NATIVE_SOURCE_HIERARCHY_SCHEMA_NAMES if it has ad-group / ad tables._native_source_specs: dict[str, tuple[NativeMarketingSource, type[HierarchicalNativeAdsConfig]]] = {"AppleSearchAds": (NativeMarketingSource.APPLE_SEARCH_ADS, HierarchicalNativeAdsConfig),+ "OpenAIAds": (NativeMarketingSource.OPEN_AI_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/openai_ads.py b/products/marketing_analytics/backend/hogql_queries/adapters/openai_ads.pynew file mode 100644index 000000000000..d14d0087eb4d--- /dev/null+++ b/products/marketing_analytics/backend/hogql_queries/adapters/openai_ads.py@@ -0,0 +1,79 @@+from posthog.schema import 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 OpenAIAdsAdapter(MarketingSourceAdapter[HierarchicalNativeAdsConfig]):+ _source_type = NativeMarketingSource.OPEN_AI_ADS+ _stats_date_column = "start_time"+ _campaign_stats_fk_column = "campaign_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()+ errors = [+ f"OpenAI Ads is missing '{column}' in '{table.name}'. Sync this table again."+ for table, columns in (+ (tables.entity_table, (tables.entity_id_column, tables.entity_name_column)),+ (+ tables.stats_table,+ (+ tables.stats_entity_id_column,+ "start_time",+ "impressions",+ "clicks",+ "spend",+ "currency_code",+ ),+ ),+ )+ 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, *, monetary: bool = False) -> ast.Expr:+ table = self._level_tables().stats_table+ if not self._table_has_column(table, column):+ return ast.Constant(value=0)+ value: ast.Expr = ast.Call(+ name="coalesce",+ args=[ast.Call(name="toFloat", args=[ast.Field(chain=[table.name, column])]), ast.Constant(value=0)],+ )+ if monetary:+ value = self._apply_currency_conversion(table, table.name, "currency_code", value) or value+ return ast.Call(name="sum", args=[value])++ 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:+ return parse_expr(+ "{spend} + throwIf(countIf(empty(coalesce({currency}, ''))) > 0, {message})",+ placeholders={+ "spend": self._sum_metric("spend", monetary=True),+ "currency": ast.Field(chain=[self._level_tables().stats_table.name, "currency_code"]),+ "message": ast.Constant(+ value="OpenAI Ads currency is missing. Fully resync campaign_insights, then try again."+ ),+ },+ )++ def _get_reported_conversion_field(self) -> ast.Expr:+ 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/adapters/test_factory.py b/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.pyindex 86d2a36c576f..60b4ed142c7f 100644--- a/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py+++ b/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py@@ -561,7 +561,7 @@ class TestNativeSourceKillSwitch(SimpleTestCase):factory._warehouse_tables = []factory._external_sources = []factory._tables_by_source_id = {}- for source_type in ("GoogleAds", "AppleSearchAds"):+ for source_type in ("GoogleAds", "AppleSearchAds", "OpenAIAds"):source = ExternalDataSource(source_type=source_type)patterns = TABLE_PATTERNS[NativeMarketingSource(source_type)]tables = [@@ -579,6 +579,6 @@ class TestNativeSourceKillSwitch(SimpleTestCase):adapters = factory.create_adapters()assert [adapter.get_source_type() for adapter in adapters] == (- ["GoogleAds", "AppleSearchAds"] if enabled else ["GoogleAds"]+ ["GoogleAds", "AppleSearchAds", "OpenAIAds"] if enabled else ["GoogleAds"])factory.logger.exception.assert_not_called()diff --git a/products/marketing_analytics/backend/hogql_queries/adapters/test_openai_ads.py b/products/marketing_analytics/backend/hogql_queries/adapters/test_openai_ads.pynew file mode 100644index 000000000000..1b77e00496c7--- /dev/null+++ b/products/marketing_analytics/backend/hogql_queries/adapters/test_openai_ads.py@@ -0,0 +1,97 @@+from datetime import UTC, datetime++from unittest.mock import PropertyMock, patch++from django.test import SimpleTestCase++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++from .base import HierarchicalNativeAdsConfig, QueryContext+from .openai_ads import OpenAIAdsAdapter+++class TestOpenAIAdsAdapter(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 _adapter(self) -> OpenAIAdsAdapter:+ def table(name: str, fields: list[str]) -> DataWarehouseTable:+ return DataWarehouseTable(name=f"openaiads_{name}", columns=dict.fromkeys(fields, "String"))++ return OpenAIAdsAdapter(+ HierarchicalNativeAdsConfig(+ source_type="OpenAIAds",+ source_id="openai-source",+ campaign_table=table("campaigns", ["id", "name"]),+ stats_table=table(+ "campaign_insights",+ [+ "campaign_id",+ "start_time",+ "spend",+ "impressions",+ "clicks",+ "currency_code",+ ],+ ),+ ),+ 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=MarketingAnalyticsDrillDownLevel.CAMPAIGN,+ ),+ )++ def test_queries_convert_spend_without_treating_it_as_micros(self) -> None:+ adapter = self._adapter()+ assert adapter.validate().is_valid+ for query in (adapter.build_query(), adapter.build_materialization_query("openai-source")):+ assert query is not None+ sql = replace_placeholders(+ query,+ {+ "time_window_min": ast.Constant(value="2026-09-01"),+ "time_window_max": ast.Constant(value="2026-09-03"),+ },+ ).to_hogql()+ assert "openaiads_campaigns.id" in sql+ assert "openaiads_campaign_insights.campaign_id" in sql+ assert "openaiads_campaign_insights.spend" in sql+ assert "openaiads_campaign_insights.currency_code" in sql+ assert "toDate(openaiads_campaign_insights.start_time)" in sql+ assert "'EUR'" in sql+ assert "1000000" not in sql+ assert "countIf(empty(coalesce(openaiads_campaign_insights.currency_code, '')))" in sql+ assert "throwIf(" in sql+ assert "Fully resync campaign_insights" in sql+ assert "0 AS reported_conversion" in sql+ assert not adapter.supports_level(MarketingAnalyticsDrillDownLevel.AD_GROUP)++ def test_old_sync_without_currency_is_invalid(self) -> None:+ adapter = self._adapter()+ assert adapter.config.stats_table.columns is not None+ del adapter.config.stats_table.columns["currency_code"]+ assert not adapter.validate().is_validdiff --git a/products/marketing_analytics/backend/hogql_queries/constants.py b/products/marketing_analytics/backend/hogql_queries/constants.pyindex 0676cd601fe0..385d3f31a0e7 100644--- a/products/marketing_analytics/backend/hogql_queries/constants.py+++ b/products/marketing_analytics/backend/hogql_queries/constants.py@@ -26,12 +26,14 @@ from posthog.schema import (MarketingIntegrationConfig7,MarketingIntegrationConfig8,MarketingIntegrationConfig9,+ MarketingIntegrationConfig10,MetaAdsConversionFallbackActionTypes,MetaAdsConversionOmniActionTypes,MetaAdsConversionSpecificActionTypes,MetaAdsDefaultSources,NativeMarketingSource,NodeKind,+ OpenAIAdsDefaultSources,PinterestAdsDefaultSources,RedditAdsDefaultSources,SnapchatAdsConversionFields,@@ -503,6 +505,7 @@ VALID_SELF_MANAGED_MARKETING_SOURCES = ["aws", "google-cloud", "cloudflare-r2",# Map generated config models to NativeMarketingSource using sourceType field_ALL_CONFIG_MODELS: list[type[BaseModel]] = [MarketingIntegrationConfig1,+ MarketingIntegrationConfig10,MarketingIntegrationConfig2,MarketingIntegrationConfig3,MarketingIntegrationConfig4,@@ -541,6 +544,7 @@ def _get_enum_values(enum_class) -> list[str]:# Mapping from NativeMarketingSource to generated enum types_DEFAULT_SOURCES_ENUMS = {NativeMarketingSource.APPLE_SEARCH_ADS: AppleSearchAdsDefaultSources,+ NativeMarketingSource.OPEN_AI_ADS: OpenAIAdsDefaultSources,NativeMarketingSource.GOOGLE_ADS: GoogleAdsDefaultSources,NativeMarketingSource.LINKEDIN_ADS: LinkedinAdsDefaultSources,NativeMarketingSource.META_ADS: MetaAdsDefaultSources,diff --git a/products/marketing_analytics/backend/services/data_source_health.py b/products/marketing_analytics/backend/services/data_source_health.pyindex 4fda4347690e..fabf55976b45 100644--- a/products/marketing_analytics/backend/services/data_source_health.py+++ b/products/marketing_analytics/backend/services/data_source_health.py@@ -6,6 +6,7 @@ from django.db.models import Sumfrom django.utils import timezoneimport structlog+from asgiref.sync import sync_to_asyncfrom posthog.schema import NativeMarketingSource@@ -126,7 +127,9 @@ async def get_data_source_health(Postgres roundtrip. None → service loads it itself."""targets = {- key: native for key, native in EXTERNAL_SOURCE_TYPE_TO_NATIVE.items() if is_native_source_enabled(key, team)+ 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)}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/native_integrations.py b/products/marketing_analytics/backend/services/native_integrations.pyindex 887ce61ca01b..939fdd43b669 100644--- a/products/marketing_analytics/backend/services/native_integrations.py+++ b/products/marketing_analytics/backend/services/native_integrations.py@@ -19,6 +19,7 @@ if TYPE_CHECKING:NativeIntegration = Literal["apple_ads",+ "openai_ads","google_ads","meta_ads","bing_ads",@@ -34,6 +35,7 @@ NativeIntegration = Literal[# downstream (URL params, scope hints, suggestion targets).NATIVE_TO_KEY: dict[NativeMarketingSource, NativeIntegration] = {NativeMarketingSource.APPLE_SEARCH_ADS: "apple_ads",+ NativeMarketingSource.OPEN_AI_ADS: "openai_ads",NativeMarketingSource.GOOGLE_ADS: "google_ads",NativeMarketingSource.META_ADS: "meta_ads",NativeMarketingSource.BING_ADS: "bing_ads",@@ -52,6 +54,7 @@ KEY_TO_NATIVE: dict[NativeIntegration, NativeMarketingSource] = {v: k for k, v i# ExternalDataSourceType has many non-marketing entries.EXTERNAL_SOURCE_TYPE_TO_NATIVE: dict[str, NativeMarketingSource] = {"AppleSearchAds": NativeMarketingSource.APPLE_SEARCH_ADS,+ "OpenAIAds": NativeMarketingSource.OPEN_AI_ADS,"GoogleAds": NativeMarketingSource.GOOGLE_ADS,"MetaAds": NativeMarketingSource.META_ADS,"BingAds": NativeMarketingSource.BING_ADS,@@ -65,6 +68,7 @@ EXTERNAL_SOURCE_TYPE_TO_NATIVE: dict[str, NativeMarketingSource] = {# Human-facing names for surfaces that produce text (LLMs, UI, error messages).DISPLAY_NAMES: dict[NativeMarketingSource, str] = {NativeMarketingSource.APPLE_SEARCH_ADS: "Apple Ads",+ NativeMarketingSource.OPEN_AI_ADS: "OpenAI Ads",NativeMarketingSource.GOOGLE_ADS: "Google Ads",NativeMarketingSource.META_ADS: "Meta Ads",NativeMarketingSource.BING_ADS: "Bing Ads",@@ -92,6 +96,7 @@ OAUTH_KIND_BY_NATIVE: dict[NativeMarketingSource, str] = {NATIVE_SOURCE_FEATURE_FLAGS: dict[str, str] = {"AppleSearchAds": "marketing-analytics-apple-ads",+ "OpenAIAds": "marketing-analytics-openai-ads",}diff --git a/products/marketing_analytics/backend/services/test_native_integrations.py b/products/marketing_analytics/backend/services/test_native_integrations.pyindex 476abcae7f67..6b78b4342d4e 100644--- a/products/marketing_analytics/backend/services/test_native_integrations.py+++ b/products/marketing_analytics/backend/services/test_native_integrations.py@@ -111,6 +111,7 @@ class TestDisplayNames:@parameterized.expand([("apple_ads", "Apple Ads"),+ ("openai_ads", "OpenAI Ads"),("google_ads", "Google Ads"),("meta_ads", "Meta Ads"),("bing_ads", "Bing Ads"),@@ -148,20 +149,32 @@ class TestStructuralInvariants:assert not unknown, f"{sorted(unknown)} are not kinds the authorize endpoint accepts"def test_only_credential_based_integrations_lack_an_oauth_kind(self) -> None:- assert set(NativeMarketingSource) - set(OAUTH_KIND_BY_NATIVE) == {NativeMarketingSource.APPLE_SEARCH_ADS}+ assert set(NativeMarketingSource) - set(OAUTH_KIND_BY_NATIVE) == {+ NativeMarketingSource.APPLE_SEARCH_ADS,+ NativeMarketingSource.OPEN_AI_ADS,+ }class TestNativeSourceFeatureFlags:- @parameterized.expand([(False,), (True,)])- def test_source_rollout_does_not_disable_existing_integrations(self, enabled: bool) -> None:+ @parameterized.expand(+ [+ (source, flag, enabled)+ for source, flag in [+ ("AppleSearchAds", "marketing-analytics-apple-ads"),+ ("OpenAIAds", "marketing-analytics-openai-ads"),+ ]+ for enabled in [False, True]+ ]+ )+ def test_source_rollout_does_not_disable_existing_integrations(self, source: str, flag: str, enabled: bool) -> None:team = Team(id=1, organization_id="00000000-0000-0000-0000-000000000001")with patch("products.marketing_analytics.backend.services.native_integrations.feature_enabled_or_false",return_value=enabled,) as evaluate:- assert is_native_source_enabled("AppleSearchAds", team) is enabled+ assert is_native_source_enabled(source, team) is enabledevaluate.assert_called_once_with(- "marketing-analytics-apple-ads",+ flag,str(team.uuid),groups={"organization": str(team.organization_id)},group_properties={"organization": {"id": str(team.organization_id)}},diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/canonical_descriptions.pyindex 98bb83ff0323..b444a7ce75b7 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/canonical_descriptions.py@@ -9,6 +9,7 @@ _INSIGHTS_COMMON_COLUMNS = {"readable_time": "Human-readable bucket label, e.g. the bucket's calendar date for daily granularity.","impressions": "Number of times ads were shown during the bucket.","clicks": "Number of clicks recorded during the bucket.",+ "currency_code": "Account currency code fetched from the ad account metadata for this sync.","spend": "Amount spent during the bucket, in the ad account's currency (decimal, not micros).","ctr": "Click-through rate: clicks divided by impressions.","cpc": "Average cost per click, in the ad account's currency.",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/openai_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/openai_ads.pyindex 1894f27e4e70..fca59b965c78 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/openai_ads.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/openai_ads.py@@ -1,6 +1,7 @@+import reimport jsonimport dataclasses-from collections.abc import Iterator+from collections.abc import Callable, Iteratorfrom datetime import UTC, date, datetimefrom typing import Any, Optional@@ -13,7 +14,10 @@ from products.warehouse_sources.backend.temporal.data_imports.sources.common.resrest_api_resource,)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.auth import BearerTokenAuth-from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import BasePaginator+from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.paginators import (+ BasePaginator,+ SinglePagePaginator,+)from products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client import RESTClientfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.resumable import ResumableSourceManagerfrom products.warehouse_sources.backend.temporal.data_imports.sources.common.source_helpers import validate_via_probe@@ -183,6 +187,17 @@ def _make_client(api_key: str) -> RESTClient:)+def _account_currency(api_key: str) -> str:+ for page in _make_client(api_key).paginate(+ path="/v1/ad_account", paginator=SinglePagePaginator(), data_selector="$"+ ):+ for account in page:+ currency = account.get("currency_code")+ if isinstance(currency, str) and re.fullmatch(r"[A-Z]{3}", currency):+ return currency+ raise ValueError("OpenAI Ads did not return an account currency. Check the account settings, then sync again.")++def _list_pages(client: RESTClient, path: str, params: dict[str, Any]) -> Iterator[list[dict[str, Any]]]:yield from client.paginate(path=path,@@ -254,6 +269,7 @@ def openai_ads_source(resume = resumable_source_manager.load_state() if resumable_source_manager.can_resume() else None+ data_map: Callable[[dict[str, Any]], dict[str, Any]] | None = Noneif config.aggregation_level is not None:if resume is not None and resume.since and resume.until:window: SyncWindow[str] = SyncWindow(start=resume.since, end=resume.until)@@ -271,13 +287,17 @@ def openai_ads_source({"type": "date_range", "since": window.start, "until": window.end, "timezone": "UTC"}),}- data_map = _convert_insights_times+ currency = _account_currency(api_key)++ def enrich_insights(row: dict[str, Any]) -> dict[str, Any]:+ return {**_convert_insights_times(row), "currency_code": currency}++ data_map = enrich_insightselse:window = SyncWindow(start="", end="")# An explicit stable sort prevents page-boundary skips/duplicates while paginating the# full campaign list.params = {"limit": LIST_PAGE_SIZE, "order": "asc"}- data_map = Nonerest_config: RESTAPIConfig = {"client": {diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads.pyindex fcce6fcfd234..abc03c8f15bb 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads.py@@ -2,6 +2,7 @@ import jsonfrom datetime import UTC, datetimefrom typing import Any+import pytestimport time_machinefrom unittest import mock@@ -209,12 +210,12 @@ class TestInsights:@mock.patch(CLIENT_SESSION_PATCH)def test_incremental_windows_from_watermark_to_today(self, MockSession) -> None:session = MockSession.return_value- params = _wire(session, [_page([], has_more=False)])+ params = _wire(session, [_response({"currency_code": "EUR"}), _page([], has_more=False)])watermark = datetime(2026, 7, 1, 12, 30, tzinfo=UTC)_rows(_source("campaign_insights", _make_manager(), last_value=watermark))- sent = params[0]["params"]+ sent = params[1]["params"]assert sent["aggregation_level"] == "campaign"assert sent["time_granularity"] == "daily"assert json.loads(sent["time_ranges[]"]) == {@@ -233,11 +234,11 @@ class TestInsights:# Without a watermark we still need a bounded window — the API rejects unbounded/future# ranges — and it must cover all possible history for the product.session = MockSession.return_value- params = _wire(session, [_page([], has_more=False)])+ params = _wire(session, [_response({"currency_code": "EUR"}), _page([], has_more=False)])_rows(_source("ad_account_insights", _make_manager()))- assert json.loads(params[0]["params"]["time_ranges[]"])["since"] == "2025-01-01"+ assert json.loads(params[1]["params"]["time_ranges[]"])["since"] == "2025-01-01"@mock.patch(CLIENT_SESSION_PATCH)def test_bucket_times_become_datetimes(self, MockSession) -> None:@@ -247,6 +248,7 @@ class TestInsights:_wire(session,[+ _response({"currency_code": "EUR"}),_page([{@@ -257,7 +259,7 @@ class TestInsights:}],has_more=False,- )+ ),],)@@ -266,6 +268,8 @@ class TestInsights:assert rows[0]["start_time"] == datetime(2026, 4, 25, tzinfo=UTC)assert rows[0]["end_time"] == datetime(2026, 4, 26, tzinfo=UTC)assert rows[0]["impressions"] == 5+ assert rows[0]["currency_code"] == "EUR"+ assert session.send.call_count == 2@time_machine.travel("2026-07-21", tick=False)@mock.patch(CLIENT_SESSION_PATCH)@@ -274,6 +278,7 @@ class TestInsights:_wire(session,[+ _response({"currency_code": "EUR"}),_page([{"id": "b1", "start_time": 1, "end_time": 2}], has_more=True, last_id="b1"),_page([{"id": "b2", "start_time": 2, "end_time": 3}], has_more=False, last_id="b2"),],@@ -293,16 +298,24 @@ class TestInsights:# A cursor is only valid for the result set it was issued for — recomputing `until` as a# later day on resume would pair it with a different window.session = MockSession.return_value- params = _wire(session, [_page([], has_more=False)])+ params = _wire(session, [_response({"currency_code": "EUR"}), _page([], has_more=False)])resume = OpenAIAdsResumeConfig(cursor="b1", since="2026-06-01", until="2026-07-19")_rows(_source("campaign_insights", _make_manager(resume)))- sent = params[0]["params"]+ sent = params[1]["params"]assert sent["after"] == "b1"window = json.loads(sent["time_ranges[]"])assert (window["since"], window["until"]) == ("2026-06-01", "2026-07-19")+ @mock.patch(CLIENT_SESSION_PATCH)+ def test_missing_account_currency_stops_sync(self, MockSession) -> None:+ session = MockSession.return_value+ _wire(session, [_response({"id": "account_example"})])+ with pytest.raises(ValueError, match="account currency"):+ _rows(_source("campaign_insights", _make_manager()))+ assert session.send.call_count == 1+class TestValidateCredentials:@parameterized.expand(diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads_source.pyindex 22696f73e270..6f50bb399669 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/openai_ads/tests/test_openai_ads_source.py@@ -1,4 +1,4 @@-from unittest.mock import MagicMock+from unittest.mock import MagicMock, patchfrom parameterized import parameterized@@ -75,7 +75,11 @@ class TestOpenAIAdsSourceForPipeline:inputs.db_incremental_field_last_value = Nonemanager = MagicMock()manager.can_resume.return_value = False- response = OpenAIAdsSource().source_for_pipeline(MagicMock(api_key="k"), manager, inputs)+ with patch(+ "products.warehouse_sources.backend.temporal.data_imports.sources.common.rest_source.rest_client.RESTClient.paginate",+ return_value=iter([[{"currency_code": "USD"}]]),+ ):+ response = OpenAIAdsSource().source_for_pipeline(MagicMock(api_key="k"), manager, inputs)assert response.name == endpointassert response.primary_keys == primary_keysassert response.partition_keys == partition_keys