Skip to content

: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.

feat(marketing-analytics): integrate apple ads (#106284)

Javier Bahamondes5bf4a09b3c1c
diff --git a/docs/published/handbook/engineering/data-warehouse.md b/docs/published/handbook/engineering/data-warehouse.md
index 98bbe58fdf2e..93e12398ba7e 100644
--- a/docs/published/handbook/engineering/data-warehouse.md
+++ b/docs/published/handbook/engineering/data-warehouse.md
@@ -6,6 +6,21 @@ showTitle: true
This is an internal guide to setting up and working with the data warehouse for PostHog engineers. If you're a PostHog user, check out our [data warehouse docs](https://posthog.com/docs/data-warehouse) instead.
+## Apple Ads in Marketing analytics
+
+Marketing analytics support is controlled by the boolean organization flag `marketing-analytics-apple-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_report` to include Apple Ads in Marketing analytics.
+Sync `ad_groups` and `ad_group_report` to enable the ad group breakdown.
+Apple Ads does not provide an ad-level report through this connector.
+Taps appear as clicks, and installs appear as reported conversions.
+The adapter accepts both Campaign Management API 5 `installs` and Ads Platform API `totalInstalls`, including tables that contain rows from both versions.
+Spend 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.
+
## Adding a new source
Looking 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.yml
index b6aee24948c0..5bc3547e9dff 100644
--- a/frontend/snapshots.yml
+++ b/frontend/snapshots.yml
@@ -10113,9 +10113,9 @@ snapshots:
scenes-app-marketing-analytics-cell-actions--campaign-cell-action-globally-mapped--light:
hash: v1.k794b7964.61e09c9e87341bff85e48a5a849c60271b9343f68156fdbd8254d867efcbe362.8mesQHKUwOThl6lkM5fvaR5z5Iwc2JSF4pZ0iB0Ho34
scenes-app-marketing-analytics-cell-actions--campaign-cell-action-unmapped--dark:
- hash: v1.k794b7964.03ee9191ff2b00ae0f596af20822514005e9b24ecbdca3b8d495ce93ce2d257f.RtA96taGqs-sexJ4fgnmqAsvVxqkiw9DKg9fSfy1XfA
+ hash: v1.k794b7964.8e4c8745ddfeb9e39c12c1de6440ffefbab10c6fdfcbaf2917ec6eeb30c21a3c.bJYM40EyMJDb-CNlZ6VS6F0_q7RzB27y88wyo_vS_pk
scenes-app-marketing-analytics-cell-actions--campaign-cell-action-unmapped--light:
- hash: v1.k794b7964.803a1872f711e52d637522145f54a87636efad5f7e186abce40f4931f5d09c02.pQf5NOMRUZZVtEGDQR487jFH6IzEIWXwiEz25YG67Tk
+ hash: v1.k794b7964.0e25052e261eb633f06f625f042febd96eb40e52650c5b22d41f2594f04d466f.gWGwrfXDOGghOGomTQr7hL7f0slkZGUwWbI2NcbjrrE
scenes-app-marketing-analytics-cell-actions--source-cell-action-custom-mapped--dark:
hash: v1.k794b7964.b54f7b4f93126a339b8d1f2c3052e33195ece30a69558784cf5e3500d1fdff2d.z26YCBpYH_GJ8cTy_m2zptpKY3Y7-ExoHfa-vjsJXuU
scenes-app-marketing-analytics-cell-actions--source-cell-action-custom-mapped--light:
@@ -10124,10 +10124,14 @@ snapshots:
hash: v1.k794b7964.8de1174560039035f352d0866e29e521fd03613192722b8560e8d69bf609f8f9.e4mmLZOJdzz4og90CK4gz4_X9IpmLx4rMUOsLX633-U
scenes-app-marketing-analytics-cell-actions--source-cell-action-default-mapped--light:
hash: v1.k794b7964.97d14625b23a5b9075ec2d5b849f211bd7f1969616f80ad089153098f7e8a197.KQnmMbzq-4zJ6T9IsjXu2FxUXSi_LOcdtULUnNcSVbY
+ scenes-app-marketing-analytics-cell-actions--source-cell-action-integration-disabled--dark:
+ hash: v1.k794b7964.c6e867ffef88bda4d794e14e8744eca639ba95a304c357c2ceb7d2db32322175.-pLeOgYT53mxILlTuOGYjWo0Lw4xYw3BZ58qLZIk450
+ scenes-app-marketing-analytics-cell-actions--source-cell-action-integration-disabled--light:
+ hash: v1.k794b7964.a47387317b5359abf524ddee66c0191f13aa20068299426fd2ba02a2a2b484de.8vAAZrir9sb1KgnInnG0LSGU1ejxmdo9L27tV9HuLPM
scenes-app-marketing-analytics-cell-actions--source-cell-action-unmapped--dark:
- hash: v1.k794b7964.4d75bf1926fdf1fdebad47ad4fd07f4035634bca040c9aeb0fd58e18adaa4fb4.3sBwvXuvVbhUPQY3T9JG4G3LwQL6Tvv_a22YYhQJifo
+ hash: v1.k794b7964.cf10adeda245ccff69e13bd0549d2b1579f5173b93a0b6090dce2b51db242384.oM_0pR3iPTmwIT5GCc7rRMRcHVCZVVRL1_LIjQFT3Ag
scenes-app-marketing-analytics-cell-actions--source-cell-action-unmapped--light:
- hash: v1.k794b7964.c15b997111d34fb17ad2dd192b97c01d0a7ab3a320c5edf9a3e20b0b63a4ff9b.UHxcXJdZkFGXRnzIMFWO99QMD_gZm0V47g8f1j4OFS0
+ hash: v1.k794b7964.82fdca17171ef49bdce7d6a769c88cde001e17f402f1b19e2a3778f0aa274b82.YW7pM5jU-MhVYp1FgIC0MA7wJEWz4eaooeYj6WFpucM
scenes-app-marketing-analytics-dashboard-change-value-cell--bounce-rate--dark:
hash: v1.k794b7964.077ba380688f01ece0aa53fbdd827aa0b79a58e6f952315fe51af26bc835b64a.PRdHzGD2h3pbMEhUAGi2JC6w2vr8_XebNg_iPCpM9bg
scenes-app-marketing-analytics-dashboard-change-value-cell--bounce-rate--light:
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index d9615090c153..552e9efe7da1 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -164,6 +164,7 @@ export const RETENTION_FIRST_EVER_OCCURRENCE = 'retention_first_ever_occurrence'
// variant keys separated by commas, e.g. `multivariate=control,test,something_else`
export const FEATURE_FLAGS = {
POSTHOG_TERMINAL: 'posthog-terminal', // owner: @mariusandra
+
// Eternal feature flags, shouldn't be removed, helpful for debugging/maintenance reasons
BILLING_FORECASTING_ISSUES: 'billing-forecasting-issues', // owner: #team-billing, see `Billing.tsx`, used to raise a warning when billing is having problems
COMING_SOON_WAITLIST_SURVEYS: 'coming-soon-waitlist-surveys', // owner: #team-growth, see `FeaturePreviews.tsx`, swaps concept-stage one-click for an email waitlist survey
@@ -383,6 +384,7 @@ export const FEATURE_FLAGS = {
MANAGED_MIGRATIONS_TRIAL_RUNS: 'managed-migrations-trial-runs', // owner: #team-ingestion, gates trial runs for managed migrations
MANAGED_VIEWSETS: 'managed-viewsets', // owner: @rafaeelaudibert #team-revenue-analytics
MARKETING_ANALYTICS_AI: 'marketing-analytics-ai', // owner: @jabahamondes #team-web-analytics
+ MARKETING_ANALYTICS_APPLE_ADS: 'marketing-analytics-apple-ads', // owner: @jabahamondes #team-web-analytics
MARKETING_ANALYTICS_ATTRIBUTION: 'marketing-analytics-attribution', // owner: @jabahamondes #team-web-analytics — gates the legacy Attribution explorer tab; the new dashboard ignores it
MARKETING_ANALYTICS_COSTS_PRECOMPUTATION: 'marketing-analytics-costs-precomputation', // owner: @jabahamondes #team-web-analytics — gates reading the native cost precompute table
MARKETING_ANALYTICS_EXTENDED_DRILL_DOWN: 'marketing-analytics-extended-drill-down', // owner: @jabahamondes #team-web-analytics
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index 4e25c6f7759a..d370369f4584 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -2057,6 +2057,10 @@
}
]
},
+ "AppleSearchAdsDefaultSources": {
+ "enum": ["apple", "apple_search_ads", "apple_ads", "asa"],
+ "type": "string"
+ },
"ApprovalCardUIStatus": {
"anyOf": [
{
@@ -36390,6 +36394,78 @@
"adStatsTableName"
],
"type": "object"
+ },
+ {
+ "additionalProperties": false,
+ "properties": {
+ "adsetStatsTableName": {
+ "const": "ad_group_report",
+ "type": "string"
+ },
+ "adsetTableName": {
+ "const": "ad_groups",
+ "type": "string"
+ },
+ "campaignTableName": {
+ "const": "campaigns",
+ "type": "string"
+ },
+ "defaultSources": {
+ "items": [
+ {
+ "const": "apple",
+ "type": "string"
+ },
+ {
+ "const": "apple_search_ads",
+ "type": "string"
+ },
+ {
+ "const": "apple_ads",
+ "type": "string"
+ },
+ {
+ "const": "asa",
+ "type": "string"
+ }
+ ],
+ "maxItems": 4,
+ "minItems": 4,
+ "type": "array"
+ },
+ "idField": {
+ "const": "id",
+ "type": "string"
+ },
+ "nameField": {
+ "const": "name",
+ "type": "string"
+ },
+ "primarySource": {
+ "const": "apple",
+ "type": "string"
+ },
+ "sourceType": {
+ "const": "AppleSearchAds",
+ "type": "string"
+ },
+ "statsTableName": {
+ "const": "campaign_report",
+ "type": "string"
+ }
+ },
+ "required": [
+ "sourceType",
+ "nameField",
+ "idField",
+ "campaignTableName",
+ "statsTableName",
+ "defaultSources",
+ "primarySource",
+ "adsetTableName",
+ "adsetStatsTableName"
+ ],
+ "type": "object"
}
]
},
@@ -38297,7 +38373,8 @@
"RedditAds",
"BingAds",
"SnapchatAds",
- "PinterestAds"
+ "PinterestAds",
+ "AppleSearchAds"
],
"type": "string"
},
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 07262fd73809..9adbf57553b3 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -8394,6 +8394,7 @@ export const VALID_NATIVE_MARKETING_SOURCES = [
'BingAds',
'SnapchatAds',
'PinterestAds',
+ 'AppleSearchAds',
] as const
export type NativeMarketingSource = (typeof VALID_NATIVE_MARKETING_SOURCES)[number]
@@ -8564,10 +8565,24 @@ export const MARKETING_INTEGRATION_CONFIGS = {
adTableName: 'ads' as const,
adStatsTableName: 'ad_analytics' as const,
},
+ AppleSearchAds: {
+ sourceType: 'AppleSearchAds' as const,
+ nameField: 'name',
+ idField: 'id',
+ campaignTableName: 'campaigns',
+ statsTableName: 'campaign_report',
+ defaultSources: ['apple', 'apple_search_ads', 'apple_ads', 'asa'] as const,
+ primarySource: 'apple',
+ adsetTableName: 'ad_groups' as const,
+ adsetStatsTableName: 'ad_group_report' as const,
+ },
} as const
export type MarketingIntegrationConfig = (typeof MARKETING_INTEGRATION_CONFIGS)[NativeMarketingSource]
+export type AppleSearchAdsDefaultSources =
+ (typeof MARKETING_INTEGRATION_CONFIGS)['AppleSearchAds']['defaultSources'][number]
+
export type GoogleAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['GoogleAds']['defaultSources'][number]
export type LinkedinAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['LinkedinAds']['defaultSources'][number]
export type MetaAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['MetaAds']['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.tsx
index 19f1ec9cf097..bb5f9a3797e5 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
@@ -1,15 +1,34 @@
import { Meta, StoryObj } from '@storybook/react'
+import { useValues } from 'kea'
+import { FEATURE_FLAGS } from 'lib/constants'
import { LemonMenuItem, LemonMenuItems, LemonMenuOverlay, LemonMenuOverlayProps } from 'lib/lemon-ui/LemonMenu'
+import { featureFlagLogic } from 'lib/logic/featureFlagLogic'
import { mswDecorator } from '~/mocks/browser'
-import { VALID_NATIVE_MARKETING_SOURCES } from '~/queries/schema/schema-general'
+import { NativeMarketingSource } from '~/queries/schema/schema-general'
+import { getEnabledNativeMarketingSources } from '../../logic/utils'
import { MappingTypes } from './mappingUtils'
import { buildCampaignMappingMenuItems, buildSourceMappingMenuItems } from './menuBuilders'
// Mock icons for marketing sources - these are the paths returned by the backend
-const MARKETING_SOURCE_ICONS: Record<string, { name: string; iconPath: string; fields: never[]; caption: string }> = {
+const MARKETING_SOURCE_ICONS: Record<
+ NativeMarketingSource,
+ { name: string; iconPath: string; fields: never[]; caption: string }
+> = {
+ PinterestAds: {
+ name: 'PinterestAds',
+ iconPath: '/static/services/pinterest_ads.png',
+ fields: [],
+ caption: 'Pinterest Ads',
+ },
+ AppleSearchAds: {
+ name: 'AppleSearchAds',
+ iconPath: '/static/services/apple_search_ads.png',
+ fields: [],
+ caption: 'Apple Ads',
+ },
GoogleAds: {
name: 'GoogleAds',
iconPath: '/static/services/google-ads.png',
@@ -67,6 +86,7 @@ const meta: Meta<LemonMenuOverlayProps> = {
}),
],
parameters: {
+ featureFlags: [FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS],
docs: {
description: {
component: `
@@ -145,11 +165,12 @@ function MenuDisplay({ items, title }: MenuDisplayProps): JSX.Element {
}
export const SourceCellAction_Unmapped: Story = {
- render: () => {
+ render: function Render() {
+ const { featureFlags } = useValues(featureFlagLogic)
const items = buildSourceMappingMenuItems({
utmSource: 'paid_search',
mappingStatus: { type: MappingTypes.Unmapped },
- availableIntegrations: [...VALID_NATIVE_MARKETING_SOURCES],
+ availableIntegrations: [...getEnabledNativeMarketingSources(featureFlags)],
onOpenIntegrationSettings: () => alert('Opening settings'),
})
@@ -164,6 +185,11 @@ export const SourceCellAction_Unmapped: Story = {
},
}
+export const SourceCellAction_IntegrationDisabled: Story = {
+ ...SourceCellAction_Unmapped,
+ parameters: { featureFlags: [] },
+}
+
export const SourceCellAction_CustomMapped: Story = {
render: () => {
const items = buildSourceMappingMenuItems({
@@ -205,12 +231,13 @@ export const SourceCellAction_DefaultMapped: Story = {
/** Campaign Cell Actions Stories */
export const CampaignCellAction_Unmapped: Story = {
- render: () => {
+ render: function Render() {
+ const { featureFlags } = useValues(featureFlagLogic)
const items = buildCampaignMappingMenuItems({
utmCampaign: 'summer_sale_2024',
globalMapping: null,
existingMappings: [],
- availableIntegrations: [...VALID_NATIVE_MARKETING_SOURCES],
+ availableIntegrations: [...getEnabledNativeMarketingSources(featureFlags)],
onOpenIntegrationSettings: () => alert('Opening settings'),
})
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.snap
index 9ab2dd8f8fe3..4e3d3db85c10 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
@@ -1,5 +1,140 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
+exports[`marketing analytics utils createMarketingTile snapshots AppleSearchAds - clicks 1`] = `
+{
+ "custom_name": "prefix.campaign_report clicks",
+ "distinct_id_field": "campaign_id",
+ "id": "AppleSearchAds-stats-table-id",
+ "id_field": "campaign_id",
+ "kind": "DataWarehouseNode",
+ "math": "hogql",
+ "math_hogql": "SUM(ifNull(toFloat(taps), 0))",
+ "name": "apple",
+ "table_name": "prefix.campaign_report",
+ "timestamp_field": "date",
+}
+`;
+
+exports[`marketing analytics utils createMarketingTile snapshots AppleSearchAds - cost 1`] = `
+{
+ "custom_name": "prefix.campaign_report cost",
+ "distinct_id_field": "campaign_id",
+ "id": "AppleSearchAds-stats-table-id",
+ "id_field": "campaign_id",
+ "kind": "DataWarehouseNode",
+ "math": "hogql",
+ "math_hogql": "SUM(toFloat(convertCurrency(coalesce(local_spend.currency, 'USD'), 'USD', toFloat(local_spend.amount), coalesce(toDate(date), today()))))",
+ "name": "apple",
+ "table_name": "prefix.campaign_report",
+ "timestamp_field": "date",
+}
+`;
+
+exports[`marketing analytics utils createMarketingTile snapshots AppleSearchAds - impressions 1`] = `
+{
+ "custom_name": "prefix.campaign_report impressions",
+ "distinct_id_field": "campaign_id",
+ "id": "AppleSearchAds-stats-table-id",
+ "id_field": "campaign_id",
+ "kind": "DataWarehouseNode",
+ "math": "hogql",
+ "math_hogql": "SUM(ifNull(toFloat(impressions), 0))",
+ "name": "apple",
+ "table_name": "prefix.campaign_report",
+ "timestamp_field": "date",
+}
+`;
+
+exports[`marketing analytics utils createMarketingTile snapshots AppleSearchAds - reported_conversion (missing conversion fields) 1`] = `
+{
+ "custom_name": "prefix.campaign_report reported_conversion",
+ "distinct_id_field": "campaign_id",
+ "id": "AppleSearchAds-stats-table-id",
+ "id_field": "campaign_id",
+ "kind": "DataWarehouseNode",
+ "math": "hogql",
+ "math_hogql": "0",
+ "name": "apple",
+ "table_name": "prefix.campaign_report",
+ "timestamp_field": "date",
+}
+`;
+
+exports[`marketing analytics utils createMarketingTile snapshots AppleSearchAds - reported_conversion 1`] = `
+{
+ "custom_name": "prefix.campaign_report reported_conversion",
+ "distinct_id_field": "campaign_id",
+ "id": "AppleSearchAds-stats-table-id",
+ "id_field": "campaign_id",
+ "kind": "DataWarehouseNode",
+ "math": "hogql",
+ "math_hogql": "SUM(coalesce(toFloat(total_installs), 0))",
+ "name": "apple",
+ "table_name": "prefix.campaign_report",
+ "timestamp_field": "date",
+}
+`;
+
+exports[`marketing analytics utils createMarketingTile snapshots AppleSearchAds - reported_conversion_value (missing conversion fields) 1`] = `
+{
+ "custom_name": "prefix.campaign_report reported_conversion_value",
+ "distinct_id_field": "campaign_id",
+ "id": "AppleSearchAds-stats-table-id",
+ "id_field": "campaign_id",
+ "kind": "DataWarehouseNode",
+ "math": "hogql",
+ "math_hogql": "0",
+ "name": "apple",
+ "table_name": "prefix.campaign_report",
+ "timestamp_field": "date",
+}
+`;
+
+exports[`marketing analytics utils createMarketingTile snapshots AppleSearchAds - reported_conversion_value 1`] = `
+{
+ "custom_name": "prefix.campaign_report reported_conversion_value",
+ "distinct_id_field": "campaign_id",
+ "id": "AppleSearchAds-stats-table-id",
+ "id_field": "campaign_id",
+ "kind": "DataWarehouseNode",
+ "math": "hogql",
+ "math_hogql": "0",
+ "name": "apple",
+ "table_name": "prefix.campaign_report",
+ "timestamp_field": "date",
+}
+`;
+
+exports[`marketing analytics utils createMarketingTile snapshots AppleSearchAds - roas (missing conversion fields) 1`] = `
+{
+ "custom_name": "prefix.campaign_report roas",
+ "distinct_id_field": "campaign_id",
+ "id": "AppleSearchAds-stats-table-id",
+ "id_field": "campaign_id",
+ "kind": "DataWarehouseNode",
+ "math": "hogql",
+ "math_hogql": "0",
+ "name": "apple",
+ "table_name": "prefix.campaign_report",
+ "timestamp_field": "date",
+}
+`;
+
+exports[`marketing analytics utils createMarketingTile snapshots AppleSearchAds - roas 1`] = `
+{
+ "custom_name": "prefix.campaign_report roas",
+ "distinct_id_field": "campaign_id",
+ "id": "AppleSearchAds-stats-table-id",
+ "id_field": "campaign_id",
+ "kind": "DataWarehouseNode",
+ "math": "hogql",
+ "math_hogql": "0",
+ "name": "apple",
+ "table_name": "prefix.campaign_report",
+ "timestamp_field": "date",
+}
+`;
+
exports[`marketing analytics utils createMarketingTile snapshots BingAds - clicks 1`] = `
{
"custom_name": "prefix.campaign_performance_report 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.ts
index 3535604d8e44..622c0c653d50 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
@@ -12,6 +12,7 @@ import { urls } from 'scenes/urls'
import {
ConversionGoalFilter,
+ MARKETING_INTEGRATION_CONFIGS,
DatabaseSchemaDataWarehouseTable,
InsightVizNode,
TrendsQuery,
@@ -540,4 +541,43 @@ 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,
+ ],
+ })
+ ).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
+ )
+ }
+ })
})
diff --git a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts
index f1edf3bccba9..51ce2d3bb763 100644
--- a/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts
+++ b/frontend/src/scenes/web-analytics/tabs/marketing-analytics/frontend/logic/marketingAnalyticsLogic.ts
@@ -64,6 +64,7 @@ import {
NEEDED_FIELDS_FOR_NATIVE_MARKETING_ANALYTICS,
findSchemaByFieldName,
generateUniqueName,
+ getEnabledNativeMarketingSources,
sanitizeIntegrationFilter,
validColumnsForTiles,
} from './utils'
@@ -637,7 +638,10 @@ export interface marketingAnalyticsLogicMeta {
[x: string]: SourceMap
} | null
) => ExternalTable[]
- nativeSources: (dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null) => ExternalDataSource[]
+ nativeSources: (
+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null,
+ featureFlags: FeatureFlagsSet
+ ) => ExternalDataSource[]
validNativeSources: (
nativeSources: ExternalDataSource[],
dataWarehouseTables: DatabaseSchemaDataWarehouseTable[]
@@ -1163,13 +1167,18 @@ export const marketingAnalyticsLogic = kea<marketingAnalyticsLogicType>([
},
],
nativeSources: [
- (s) => [s.dataWarehouseSources],
+ (s) => [s.dataWarehouseSources, s.featureFlags],
(
- dataWarehouseSources: null | import('../../../../../../lib/api').PaginatedResponse<ExternalDataSource>
- ): ExternalDataSource[] =>
- dataWarehouseSources?.results.filter((source) =>
- VALID_NATIVE_MARKETING_SOURCES.includes(source.source_type as NativeMarketingSource)
- ) ?? [],
+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null,
+ featureFlags: FeatureFlagsSet
+ ): ExternalDataSource[] => {
+ const enabledSources = getEnabledNativeMarketingSources(featureFlags)
+ return (
+ dataWarehouseSources?.results.filter((source) =>
+ enabledSources.includes(source.source_type as NativeMarketingSource)
+ ) ?? []
+ )
+ },
],
validNativeSources: [
(s) => [s.nativeSources, s.dataWarehouseTables],
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.ts
index 83d735758d58..9900f7257f91 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
@@ -4,6 +4,7 @@ import { router } from 'kea-router'
import posthog from 'posthog-js'
import api from 'lib/api'
+import { featureFlagLogic, type FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
import { removeProjectIdIfPresent } from 'lib/utils/kea-router'
import { teamLogic } from 'scenes/teamLogic'
import { urls } from 'scenes/urls'
@@ -33,7 +34,12 @@ import type { PaginatedResponse } from '../../../../../../lib/api'
import type { ProductIntentProperties } from '../../../../../../lib/utils/product-intents'
import type { TeamPublicType, TeamType } from '../../../../../../types'
import { IntegrationSettingsTab } from '../components/settings/IntegrationSettingsModal'
-import { DEFAULT_ATTRIBUTION_WINDOW_DAYS, extractSchemaName, generateUniqueName } from './utils'
+import {
+ DEFAULT_ATTRIBUTION_WINDOW_DAYS,
+ extractSchemaName,
+ generateUniqueName,
+ getEnabledNativeMarketingSources,
+} from './utils'
export interface IntegrationSettingsModalState {
isOpen: boolean
@@ -74,6 +80,7 @@ export type SetupEntryPoint =
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
export interface marketingAnalyticsSettingsLogicValues {
+ featureFlags: FeatureFlagsSet // featureFlagLogic
dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null // sourceManagementLogic
dataWarehouseTables: DatabaseSchemaDataWarehouseTable[] // sourceManagementLogic
currentTeam: TeamPublicType | TeamType | null // teamLogic
@@ -139,6 +146,7 @@ export interface marketingAnalyticsSettingsLogicActions {
initialTab: IntegrationSettingsTab
initialUtmValue: string
integration:
+ | 'AppleSearchAds'
| 'BingAds'
| 'GoogleAds'
| 'LinkedinAds'
@@ -224,7 +232,8 @@ export interface marketingAnalyticsSettingsLogicMeta {
filter_test_accounts: (marketingAnalyticsConfig: MarketingAnalyticsConfig | null) => boolean
integrationCampaignTables: (
dataWarehouseTables: DatabaseSchemaDataWarehouseTable[],
- dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null
+ dataWarehouseSources: PaginatedResponse<ExternalDataSource> | null,
+ featureFlags: FeatureFlagsSet
) => Record<string, string>
}
}
@@ -244,6 +253,8 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
['currentTeam', 'currentTeamId'],
sourceManagementLogic,
['dataWarehouseTables', 'dataWarehouseSources'],
+ featureFlagLogic,
+ ['featureFlags'],
],
actions: [teamLogic, ['updateCurrentTeam', 'addProductIntent']],
})),
@@ -539,18 +550,20 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
},
],
integrationCampaignTables: [
- (s) => [s.dataWarehouseTables, s.dataWarehouseSources],
+ (s) => [s.dataWarehouseTables, s.dataWarehouseSources, s.featureFlags],
(
dataWarehouseTables: DatabaseSchemaDataWarehouseTable[],
- dataWarehouseSources: { results?: ExternalDataSource[] } | null
+ dataWarehouseSources: { results?: ExternalDataSource[] } | null,
+ featureFlags: FeatureFlagsSet
): Record<string, string> => {
const result: Record<string, string> = {}
const sources = dataWarehouseSources?.results || []
+ const enabledSources = getEnabledNativeMarketingSources(featureFlags)
// For each native source, find its campaign table
for (const source of sources) {
const sourceType = source.source_type
- if (!isNativeMarketingSource(sourceType)) {
+ if (!isNativeMarketingSource(sourceType) || !enabledSources.includes(sourceType)) {
continue
}
const campaignTableName = MARKETING_INTEGRATION_CONFIGS[sourceType]?.campaignTableName
@@ -568,7 +581,7 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
// keyword — Google Ads `campaign_budget` — and then every query against
// the resolved table failed on the missing campaign columns.
for (const table of sourceTables) {
- if (extractSchemaName(table.name, sourceType) === campaignTableName) {
+ if (extractSchemaName(table.name, sourceType) === campaignTableName.toLowerCase()) {
result[sourceType] = table.name
break
}
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.ts
index 1e952ed043b8..c7003b408efb 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
@@ -1,3 +1,5 @@
+import { FEATURE_FLAGS } from 'lib/constants'
+
import {
ConversionGoalFilter,
DatabaseSchemaDataWarehouseTable,
@@ -26,9 +28,11 @@ import {
describe('marketing analytics utils', () => {
describe('getEnabledNativeMarketingSources', () => {
- it('returns every native source when no source is flag-gated', () => {
- const result = getEnabledNativeMarketingSources({})
- expect([...result]).toEqual([...VALID_NATIVE_MARKETING_SOURCES])
+ 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 }
+ expect(getEnabledNativeMarketingSources(flags)).toEqual(
+ VALID_NATIVE_MARKETING_SOURCES.filter((source) => source !== 'AppleSearchAds' || enabled === true)
+ )
})
})
@@ -271,6 +275,7 @@ describe('marketing analytics utils', () => {
// All fields each source could reference, so the mock table has them all
const sourceFields: Record<NativeMarketingSource, string[]> = {
+ AppleSearchAds: ['local_spend', 'impressions', 'taps', 'total_installs'],
GoogleAds: [
'metrics_cost_micros',
'metrics_impressions',
@@ -322,6 +327,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'],
GoogleAds: ['metrics_cost_micros', 'metrics_impressions', 'metrics_clicks', 'customer_currency_code'],
RedditAds: ['spend', 'impressions', 'clicks', 'currency'],
LinkedinAds: ['cost_in_usd', 'impressions', 'clicks'],
@@ -363,6 +369,13 @@ describe('marketing analytics utils', () => {
}
}
+ it.each(['', 'custom_', 'warehouse.custom_'])('resolves AppleSearchAds tables with prefix %s', (prefix) => {
+ const source = makeMockSource('AppleSearchAds', sourceFields.AppleSearchAds)
+ source.tables[0].name = `${prefix}applesearchads_${MARKETING_INTEGRATION_CONFIGS.AppleSearchAds.statsTableName.toLowerCase()}`
+ const result = createMarketingTile(source, MarketingAnalyticsColumnsSchemaNames.Cost, 'EUR')
+ expect(result?.table_name).toBe(source.tables[0].name)
+ })
+
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.ts
index 16997cca1a7b..2e8f1dd8bc60 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
@@ -1,4 +1,4 @@
-import type { FeatureFlagKey } from 'lib/constants'
+import { FEATURE_FLAGS, type FeatureFlagKey } from 'lib/constants'
import {
AttributionMode,
@@ -30,10 +30,9 @@ export const VALID_SELF_MANAGED_MARKETING_SOURCES: ManualLinkSourceType[] = [
'azure',
]
-// Map of native sources that require a feature flag to be enabled. Empty today
-// (all current sources are fully rolled out), but kept so a new source can be
-// gated behind a flag while it's being rolled out.
-export const NATIVE_SOURCE_FEATURE_FLAGS: Partial<Record<NativeMarketingSource, FeatureFlagKey>> = {}
+export const NATIVE_SOURCE_FEATURE_FLAGS: Partial<Record<NativeMarketingSource, FeatureFlagKey>> = {
+ AppleSearchAds: FEATURE_FLAGS.MARKETING_ANALYTICS_APPLE_ADS,
+}
/**
* Filter native marketing sources based on feature flags
@@ -46,7 +45,7 @@ export function getEnabledNativeMarketingSources(
return VALID_NATIVE_MARKETING_SOURCES.filter((source) => {
const featureFlagKey = NATIVE_SOURCE_FEATURE_FLAGS[source]
if (featureFlagKey) {
- return !!featureFlags[featureFlagKey]
+ return featureFlags[featureFlagKey] === true
}
return true
})
@@ -71,6 +70,7 @@ const NATIVE_SOURCE_DISPLAY_LABELS: Record<NativeMarketingSource, string> = {
BingAds: 'Bing Ads',
SnapchatAds: 'Snapchat Ads',
PinterestAds: 'Pinterest Ads',
+ AppleSearchAds: 'Apple Ads',
}
export function nativeSourceDisplayLabel(sourceType: string): string {
return NATIVE_SOURCE_DISPLAY_LABELS[sourceType as NativeMarketingSource] ?? sourceType
@@ -320,6 +320,7 @@ interface SourceColumnMappings {
costNeedsDivision?: boolean
currencyColumn?: string
fallbackCurrency?: string
+ currencyTimestampColumn?: string
}
interface ConversionExprResult extends Partial<DataWarehouseNode> {
@@ -359,6 +360,32 @@ function buildConversionExpr(
}
const sourceTileConfigs: Record<NativeMarketingSource, SourceTileConfig> = {
+ AppleSearchAds: {
+ idField: 'campaign_id',
+ timestampField: 'date',
+ columnMappings: {
+ cost: 'local_spend.amount',
+ impressions: 'impressions',
+ clicks: 'taps',
+ reportedConversion: 'total_installs',
+ reportedConversionValue: '0',
+ currencyColumn: 'local_spend.currency',
+ currencyTimestampColumn: 'date',
+ },
+ specialConversionLogic: (table, tileColumnSelection) => {
+ if (tileColumnSelection === MarketingAnalyticsColumnsSchemaNames.ReportedConversion) {
+ return buildConversionExpr(
+ ['total_installs', 'installs'],
+ table,
+ (fields) => `SUM(coalesce(${fields.map((field) => `toFloat(${field})`).join(', ')}, 0))`
+ )
+ }
+ if (tileColumnSelection === 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`.
@@ -644,10 +671,13 @@ function wrapWithCurrencyConversion(
): string {
const currencyColumn = mappings.currencyColumn
const fallbackCurrency = mappings.fallbackCurrency
- const hasCurrencyColumn = currencyColumn && table.fields && currencyColumn in table.fields
+ const hasCurrencyColumn = currencyColumn && table.fields && currencyColumn.split('.')[0] in table.fields
if (hasCurrencyColumn) {
- return `SUM(toFloat(convertCurrency(coalesce(${currencyColumn}, '${baseCurrency}'), '${baseCurrency}', ${valueExpr})))`
+ const dateArgument = mappings.currencyTimestampColumn
+ ? `, coalesce(toDate(${mappings.currencyTimestampColumn}), today())`
+ : ''
+ return `SUM(toFloat(convertCurrency(coalesce(${currencyColumn}, '${baseCurrency}'), '${baseCurrency}', ${valueExpr}${dateArgument})))`
}
if (fallbackCurrency) {
return `toFloat(convertCurrency('${fallbackCurrency}', '${baseCurrency}', SUM(${valueExpr})))`
@@ -663,7 +693,7 @@ function wrapAggregatedWithCurrencyConversion(
): string {
const currencyColumn = mappings.currencyColumn
const fallbackCurrency = mappings.fallbackCurrency
- const hasCurrencyColumn = currencyColumn && table.fields && currencyColumn in table.fields
+ const hasCurrencyColumn = currencyColumn && table.fields && currencyColumn.split('.')[0] in table.fields
if (hasCurrencyColumn) {
return `toFloat(convertCurrency(any(coalesce(${currencyColumn}, '${baseCurrency}')), '${baseCurrency}', ${aggregatedExpr}))`
@@ -700,7 +730,9 @@ export function createMarketingTile(
return null
}
- const table = source.tables.find((t) => t.name.split('.').pop() === integrationConfig.statsTableName)
+ const table = source.tables.find(
+ (t) => extractSchemaName(t.name, sourceType) === integrationConfig.statsTableName.toLowerCase()
+ )
if (!table) {
return null
}
@@ -727,7 +759,10 @@ export function createMarketingTile(
MarketingAnalyticsColumnsSchemaNames.ReportedConversion,
tileConfig.columnMappings.reportedConversion
)
- const mathHogql = conversionExpr === '0' ? '0' : `SUM(${costExpr}) / nullIf(${conversionExpr}, 0)`
+ const totalCostExpr = tileConfig.columnMappings.currencyTimestampColumn
+ ? wrapWithCurrencyConversion(costExpr, tileConfig.columnMappings, table, baseCurrency)
+ : `SUM(${costExpr})`
+ const mathHogql = conversionExpr === '0' ? '0' : `${totalCostExpr} / nullIf(${conversionExpr}, 0)`
return buildNativeTileNode(table, integrationConfig, tileConfig, tileColumnSelection, mathHogql)
}
diff --git a/posthog/schema.py b/posthog/schema.py
index 9d0602e0a8b7..addb75f57880 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -30,6 +30,7 @@ from posthog.schema_enums import (
AlertConditionType as AlertConditionType,
AlertState as AlertState,
AnnotationScope as AnnotationScope,
+ AppleSearchAdsDefaultSources as AppleSearchAdsDefaultSources,
ApprovalDecisionStatus as ApprovalDecisionStatus,
ArtifactContentType as ArtifactContentType,
ArtifactSource as ArtifactSource,
@@ -2105,6 +2106,21 @@ class MarketingIntegrationConfig8(BaseModel):
statsTableName: Literal["campaign_analytics"] = "campaign_analytics"
+class MarketingIntegrationConfig9(BaseModel):
+ model_config = ConfigDict(
+ extra="forbid",
+ )
+ adsetStatsTableName: Literal["ad_group_report"] = "ad_group_report"
+ adsetTableName: Literal["ad_groups"] = "ad_groups"
+ campaignTableName: Literal["campaigns"] = "campaigns"
+ defaultSources: list[str] = Field(..., max_length=4, min_length=4)
+ idField: Literal["id"] = "id"
+ nameField: Literal["name"] = "name"
+ primarySource: Literal["apple"] = "apple"
+ sourceType: Literal["AppleSearchAds"] = "AppleSearchAds"
+ statsTableName: Literal["campaign_report"] = "campaign_report"
+
+
class MarketingIntegrationConfig(
RootModel[
MarketingIntegrationConfig1
@@ -2115,6 +2131,7 @@ class MarketingIntegrationConfig(
| MarketingIntegrationConfig6
| MarketingIntegrationConfig7
| MarketingIntegrationConfig8
+ | MarketingIntegrationConfig9
]
):
root: (
@@ -2126,6 +2143,7 @@ class MarketingIntegrationConfig(
| MarketingIntegrationConfig6
| MarketingIntegrationConfig7
| MarketingIntegrationConfig8
+ | MarketingIntegrationConfig9
)
diff --git a/posthog/schema_enums.py b/posthog/schema_enums.py
index cc673055c0cd..91e226d3eda1 100644
--- a/posthog/schema_enums.py
+++ b/posthog/schema_enums.py
@@ -174,6 +174,13 @@ class AnnotationScope(StrEnum):
ORGANIZATION = "organization"
+class AppleSearchAdsDefaultSources(StrEnum):
+ APPLE = "apple"
+ APPLE_SEARCH_ADS = "apple_search_ads"
+ APPLE_ADS = "apple_ads"
+ ASA = "asa"
+
+
class ApprovalDecisionStatus(StrEnum):
PENDING = "pending"
APPROVED = "approved"
@@ -2085,6 +2092,7 @@ class NativeMarketingSource(StrEnum):
BING_ADS = "BingAds"
SNAPCHAT_ADS = "SnapchatAds"
PINTEREST_ADS = "PinterestAds"
+ APPLE_SEARCH_ADS = "AppleSearchAds"
class NodeKind(StrEnum):
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.ambr
index 6a4073830b09..276d774404d2 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(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_69)s)), events__session.`$entry_utm_source`, %(hogql_val_70)s)))))), and(and(equals(events.event, %(hogql_val_71)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), minus(conv_bounds.first_conversion, 345600)), lessOrEquals(toUnixTimestamp(events__session.`$start_timestamp`), conv_bounds.last_conversion)))), -500) AS touchpoints
+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id, arraySlice(arraySort(groupArrayIf(tuple(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_19)s)), coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_20)s), ''), 'null'), '^"|"$', ''), %(hogql_val_21)s), 0.0)), and(equals(events.event, %(hogql_val_22)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_23)s), toDateTime(%(hogql_val_24)s, %(hogql_val_25)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_26)s), toDateTime64(%(hogql_val_27)s, 6, %(hogql_val_28)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_29)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_30)s), toDateTime(%(hogql_val_31)s, %(hogql_val_32)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_33)s), toDateTime64(%(hogql_val_34)s, 6, %(hogql_val_35)s)))) AS conversion_count, arraySlice(arraySort(groupUniqArrayIf(tuple(toUnixTimestamp(events__session.`$start_timestamp`), if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_36)s)), events__session.`$entry_utm_source`, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s]), %(hogql_val_41)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_42)s)), events__session.`$entry_utm_source`, %(hogql_val_43)s)), [%(hogql_val_44)s, %(hogql_val_45)s, %(hogql_val_46)s, %(hogql_val_47)s, %(hogql_val_48)s, %(hogql_val_49)s, %(hogql_val_50)s, %(hogql_val_51)s]), %(hogql_val_52)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_53)s)), events__session.`$entry_utm_source`, %(hogql_val_54)s)), [%(hogql_val_55)s]), %(hogql_val_56)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_57)s)), events__session.`$entry_utm_source`, %(hogql_val_58)s)), [%(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s, %(hogql_val_62)s, %(hogql_val_63)s, %(hogql_val_64)s, %(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s]), %(hogql_val_68)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_69)s)), events__session.`$entry_utm_source`, %(hogql_val_70)s)), [%(hogql_val_71)s, %(hogql_val_72)s, %(hogql_val_73)s]), %(hogql_val_74)s, if(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
FROM 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_v7
FROM 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_72)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_73)s, %(hogql_val_74)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_75)s, 6, %(hogql_val_76)s))), and(equals(events.event, %(hogql_val_77)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_78)s, %(hogql_val_79)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_80)s, 6, %(hogql_val_81)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_82)s)), minus(conv_bounds.first_conversion, 345600)))))
+ 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)))))
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 touchpoints
FROM (
- 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(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_74)s)), cached_sessions.utm_source, %(hogql_val_75)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]), %(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
FROM 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_conversion
FROM 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.ambr
index f11d0cab41e2..8dd9052aede6 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(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s))))) AS breakdown_value, uniq(if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id)) AS visitors
+ SELECT if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(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
FROM 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
FROM person_distinct_id_overrides
@@ -77,21 +77,21 @@
FROM raw_sessions
WHERE 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_43)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_44)s, %(hogql_val_45)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_46)s, 6, %(hogql_val_47)s)))
+ 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)))
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_67)s)), coalesce(accurateCastOrNull(replaceRegexpAll(nullIf(nullIf(JSONExtractRaw(events.properties, %(hogql_val_68)s), ''), 'null'), '^"|"$', ''), %(hogql_val_69)s), 0.0)), and(equals(events.event, %(hogql_val_70)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_71)s), toDateTime(%(hogql_val_72)s, %(hogql_val_73)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_74)s), toDateTime64(%(hogql_val_75)s, 6, %(hogql_val_76)s))))), -500) AS conversions, countIf(and(equals(events.event, %(hogql_val_77)s), greaterOrEquals(toTimeZone(events.timestamp, %(hogql_val_78)s), toDateTime(%(hogql_val_79)s, %(hogql_val_80)s)), lessOrEquals(toTimeZone(events.timestamp, %(hogql_val_81)s), toDateTime64(%(hogql_val_82)s, 6, %(hogql_val_83)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_84)s)), events__session.`$entry_utm_source`, %(hogql_val_85)s)), [%(hogql_val_86)s, %(hogql_val_87)s, %(hogql_val_88)s]), %(hogql_val_89)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_90)s)), events__session.`$entry_utm_source`, %(hogql_val_91)s)), [%(hogql_val_92)s, %(hogql_val_93)s, %(hogql_val_94)s, %(hogql_val_95)s, %(hogql_val_96)s, %(hogql_val_97)s, %(hogql_val_98)s, %(hogql_val_99)s]), %(hogql_val_100)s, if(in(lower(if(notEmpty(ifNull(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, 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]), %(hogql_val_116)s, if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_117)s)), events__session.`$entry_utm_source`, %(hogql_val_118)s)))))), and(and(equals(events.event, %(hogql_val_119)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_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
FROM events LEFT JOIN (
- SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_48)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_49)s), %(hogql_val_50)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7
+ 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
FROM 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_51)s, %(hogql_val_52)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_53)s, 6, %(hogql_val_54)s), toIntervalDay(3)))), and(greaterOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), minus(minus(toDateTime(%(hogql_val_55)s, %(hogql_val_56)s), toIntervalSecond(345600)), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime64(%(hogql_val_57)s, 6, %(hogql_val_58)s), toIntervalDay(3))))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_59)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_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 (
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
FROM person_distinct_id_overrides
WHERE equals(person_distinct_id_overrides.team_id, 420)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING 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_60)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_61)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_66)s))) AS first_conversion, max(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_67)s))) AS last_conversion
FROM 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
FROM person_distinct_id_overrides
@@ -99,12 +99,12 @@
GROUP BY person_distinct_id_overrides.distinct_id
HAVING 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, toDateTime64(%(hogql_val_65)s, 6, %(hogql_val_66)s)))
+ 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)))
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_120)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_121)s, %(hogql_val_122)s)), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_123)s, 6, %(hogql_val_124)s))), and(equals(events.event, %(hogql_val_125)s), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_126)s, %(hogql_val_127)s), toIntervalSecond(345600))), lessOrEquals(events.timestamp, toDateTime64(%(hogql_val_128)s, 6, %(hogql_val_129)s)), greaterOrEquals(toUnixTimestamp(toTimeZone(events.timestamp, %(hogql_val_130)s)), minus(conv_bounds.first_conversion, 345600)))))
+ 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)))))
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_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_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_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
FROM 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_position
FROM 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_value
FROM per_conversion_dim
GROUP BY per_conversion_dim.breakdown_value), attribution_rows AS (
- 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_key
+ 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
FROM 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_key
FROM 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 visitors
FROM (
- 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(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_74)s)), cached_sessions.utm_source, %(hogql_val_75)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]), %(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
FROM resolved_cached_sessions AS cached_sessions
WHERE and(greaterOrEquals(cached_sessions.max_event_timestamp, toDateTime64('2022-12-28 00:00:00.000000', 6, 'UTC')), lessOrEquals(cached_sessions.min_event_timestamp, toDateTime64('2023-01-31 23:59:59.999999', 6, 'UTC')))) AS s
GROUP 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 touchpoints
FROM (
- 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_76)s)), cached_sessions.utm_source, %(hogql_val_77)s)), [%(hogql_val_78)s, %(hogql_val_79)s, %(hogql_val_80)s]), %(hogql_val_81)s, if(in(lower(if(notEmpty(ifNull(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, %(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, 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, %(hogql_val_101)s, %(hogql_val_102)s, %(hogql_val_103)s, %(hogql_val_104)s, %(hogql_val_105)s, %(hogql_val_106)s, %(hogql_val_107)s]), %(hogql_val_108)s, if(notEmpty(ifNull(cached_sessions.utm_source, %(hogql_val_109)s)), cached_sessions.utm_source, %(hogql_val_110)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_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
FROM 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_conversion
FROM 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_111)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_112)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_113)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_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
FROM 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_position
FROM 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_value
FROM per_conversion_dim
GROUP BY per_conversion_dim.breakdown_value), attribution_rows AS (
- SELECT coalesce(nullIf(attribution_totals.breakdown_value, %(hogql_val_114)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_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
FROM 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_key
FROM 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.ambr
index b8ad2dce0f61..67e80ee06133 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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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_1
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
@@ -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(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')))), ['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
FROM
(
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.ambr
index 30c7f6fa406a..a383e9c0c097 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(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')))), ['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
FROM (
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_weight
FROM (
@@ -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(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')))), ['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
FROM (
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_value
FROM (
@@ -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(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')))), ['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
FROM (
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_value
FROM (
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.ambr
index 8ce548afdff1..638f4c562609 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 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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
FROM
(
@@ -175,7 +175,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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
FROM
(
@@ -337,7 +337,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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
FROM
(
@@ -499,7 +499,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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
FROM
(
@@ -663,7 +663,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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,
0 AS conversion_1,
0 AS conversion_2
@@ -810,7 +810,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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,
0 AS conversion_0,
count() AS conversion_1,
0 AS conversion_2
@@ -957,7 +957,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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,
0 AS conversion_0,
0 AS conversion_1,
count() AS conversion_2
@@ -1122,7 +1122,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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,
0 AS conversion_1
FROM
@@ -1268,7 +1268,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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,
0 AS conversion_0,
count() AS conversion_1
FROM
diff --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.ambr
index 6fcd70322a49..68ed2ec4d225 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_0
FROM (
- SELECT if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign, if(notEmpty(campaign_id), campaign_id, '-') AS id, if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source, count() AS conversion_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')))), ['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
FROM (
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_value
FROM (
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.ambr
index 3f9b040cfa8b..1f227f8be757 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 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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
FROM
(
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.ambr
index b288bae98728..a321b26905e4 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 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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
FROM
(
@@ -301,7 +301,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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
FROM
(
@@ -498,7 +498,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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
FROM
(
@@ -662,7 +662,7 @@
SELECT
if(notEmpty(campaign_name), campaign_name, 'organic') AS campaign,
if(notEmpty(campaign_id), campaign_id, '-') AS id,
- if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['microsoft', 'msads', 'bing_video']), 'bing', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['facebook', 'instagram', 'messenger', 'fb', 'whatsapp', 'audience_network', 'facebook_marketplace', 'threads']), 'meta', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['li']), 'linkedin', if(in(lower(if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic')))), ['adwords', 'youtube', 'display', 'gmail', 'google_maps', 'google_play', 'google_discover', 'admob', 'waze']), 'google', if(notEmpty(source_name), source_name, if(notEmpty(gclid_name), 'google', if(notEmpty(gad_source_name), 'google', 'organic'))))))) AS source,
+ 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
FROM
(
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.ambr
index fa9206197302..703ce0c503d3 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 @@
SELECT
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, '')), 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(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')), ['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
FROM
events
WHERE
@@ -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(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s))))), events__session.`$start_timestamp`) AS breakdown_value
+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(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
FROM 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_v7
FROM raw_sessions
@@ -208,7 +208,7 @@
GROUP BY person_distinct_id_overrides.distinct_id
HAVING 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_43)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_44)s, %(hogql_val_45)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_46)s, %(hogql_val_47)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_48)s, %(hogql_val_49)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_50)s, %(hogql_val_51)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_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), (
SELECT DISTINCT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id
FROM 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_id
HAVING 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_52)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_53)s, %(hogql_val_54)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_55)s, %(hogql_val_56)s))))))
+ 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))))))
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_57)s, toStartOfWeek(toDateTime(%(hogql_val_58)s, %(hogql_val_59)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_60)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_index
FROM 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
FROM person_distinct_id_overrides
@@ -227,14 +227,14 @@
GROUP BY person_distinct_id_overrides.distinct_id
HAVING 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_61)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_62)s, %(hogql_val_63)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_64)s, %(hogql_val_65)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_id
FROM acquisition)))
GROUP BY actor_id, activity_index), cohort_sizes AS MATERIALIZED (
- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_66)s, toStartOfWeek(toDateTime(%(hogql_val_67)s, %(hogql_val_68)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_69)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_size
FROM acquisition
GROUP BY acquisition.breakdown_value, cohort_index), matrix AS (
- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_70)s, toStartOfWeek(toDateTime(%(hogql_val_71)s, %(hogql_val_72)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_73)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_74)s, toStartOfWeek(toDateTime(%(hogql_val_75)s, %(hogql_val_76)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_77)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 count
FROM acquisition INNER JOIN activity ON equals(activity.actor_id, acquisition.actor_id)
GROUP BY acquisition.breakdown_value, cohort_index, intervals_from_base
HAVING and(ifNull(greaterOrEquals(intervals_from_base, 0), 0), ifNull(less(intervals_from_base, 4), 0))), folded_sizes AS (
@@ -243,7 +243,7 @@
FROM cohort_sizes
GROUP BY cohort_sizes.breakdown_value
ORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC
- LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_78)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_size
FROM cohort_sizes
GROUP BY breakdown_value, cohort_sizes.cohort_index), folded_matrix AS (
SELECT if(globalIn(matrix.breakdown_value, (
@@ -251,7 +251,7 @@
FROM cohort_sizes
GROUP BY cohort_sizes.breakdown_value
ORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC
- LIMIT 20)), matrix.breakdown_value, %(hogql_val_79)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 count
FROM matrix
GROUP 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(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s))))), events__session.`$start_timestamp`) AS breakdown_value
+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS cohort_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_8)s)), events__session.`$entry_utm_source`, %(hogql_val_9)s)), [%(hogql_val_10)s, %(hogql_val_11)s, %(hogql_val_12)s]), %(hogql_val_13)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_14)s)), events__session.`$entry_utm_source`, %(hogql_val_15)s)), [%(hogql_val_16)s, %(hogql_val_17)s, %(hogql_val_18)s, %(hogql_val_19)s, %(hogql_val_20)s, %(hogql_val_21)s, %(hogql_val_22)s, %(hogql_val_23)s]), %(hogql_val_24)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_25)s)), events__session.`$entry_utm_source`, %(hogql_val_26)s)), [%(hogql_val_27)s]), %(hogql_val_28)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_29)s)), events__session.`$entry_utm_source`, %(hogql_val_30)s)), [%(hogql_val_31)s, %(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s, %(hogql_val_35)s, %(hogql_val_36)s, %(hogql_val_37)s, %(hogql_val_38)s, %(hogql_val_39)s]), %(hogql_val_40)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_41)s)), events__session.`$entry_utm_source`, %(hogql_val_42)s)), [%(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(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
FROM 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_v7
FROM raw_sessions
@@ -346,9 +346,9 @@
GROUP BY person_distinct_id_overrides.distinct_id
HAVING 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_43)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_44)s, %(hogql_val_45)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_46)s, %(hogql_val_47)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_48)s, %(hogql_val_49)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_50)s, %(hogql_val_51)s)), 0))
+ 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))
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_52)s, toStartOfWeek(toDateTime(%(hogql_val_53)s, %(hogql_val_54)s), 0), toStartOfWeek(toTimeZone(events.timestamp, %(hogql_val_55)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_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
FROM 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
FROM person_distinct_id_overrides
@@ -356,14 +356,14 @@
GROUP BY person_distinct_id_overrides.distinct_id
HAVING 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_56)s), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_57)s, %(hogql_val_58)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_59)s, %(hogql_val_60)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_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), (
SELECT acquisition.actor_id AS actor_id
FROM acquisition)))
GROUP BY actor_id, activity_index), cohort_sizes AS MATERIALIZED (
- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_61)s, toStartOfWeek(toDateTime(%(hogql_val_62)s, %(hogql_val_63)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_64)s), 0)) AS cohort_index, count(acquisition.actor_id) AS cohort_size
+ 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
FROM acquisition
GROUP BY acquisition.breakdown_value, cohort_index), matrix AS (
- SELECT acquisition.breakdown_value AS breakdown_value, dateDiff(%(hogql_val_65)s, toStartOfWeek(toDateTime(%(hogql_val_66)s, %(hogql_val_67)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_68)s), 0)) AS cohort_index, minus(activity.activity_index, dateDiff(%(hogql_val_69)s, toStartOfWeek(toDateTime(%(hogql_val_70)s, %(hogql_val_71)s), 0), toStartOfWeek(toTimeZone(acquisition.cohort_at, %(hogql_val_72)s), 0))) AS intervals_from_base, count(DISTINCT acquisition.actor_id) AS count
+ 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
FROM acquisition INNER JOIN activity ON equals(activity.actor_id, acquisition.actor_id)
GROUP BY acquisition.breakdown_value, cohort_index, intervals_from_base
HAVING and(ifNull(greaterOrEquals(intervals_from_base, 0), 0), ifNull(less(intervals_from_base, 4), 0))), folded_sizes AS (
@@ -372,7 +372,7 @@
FROM cohort_sizes
GROUP BY cohort_sizes.breakdown_value
ORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC
- LIMIT 20)), cohort_sizes.breakdown_value, %(hogql_val_73)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_79)s) AS breakdown_value, cohort_sizes.cohort_index AS cohort_index, sum(cohort_sizes.cohort_size) AS cohort_size
FROM cohort_sizes
GROUP BY breakdown_value, cohort_sizes.cohort_index), folded_matrix AS (
SELECT if(globalIn(matrix.breakdown_value, (
@@ -380,7 +380,7 @@
FROM cohort_sizes
GROUP BY cohort_sizes.breakdown_value
ORDER BY sum(cohort_sizes.cohort_size) DESC, cohort_sizes.breakdown_value ASC
- LIMIT 20)), matrix.breakdown_value, %(hogql_val_74)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_80)s) AS breakdown_value, matrix.cohort_index AS cohort_index, matrix.intervals_from_base AS intervals_from_base, sum(matrix.count) AS count
FROM matrix
GROUP 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(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_63)s)), events__session.`$entry_utm_source`, %(hogql_val_64)s))))), events__session.`$start_timestamp`) AS breakdown_value, 0 AS previous, %(hogql_val_65)s AS observation_end, argMin(events.`$session_id`, events__session.`$start_timestamp`) AS first_session_id
+ SELECT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS actor_id, min(events__session.`$start_timestamp`) AS first_session_at, argMin(if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_30)s)), events__session.`$entry_utm_source`, %(hogql_val_31)s)), [%(hogql_val_32)s, %(hogql_val_33)s, %(hogql_val_34)s]), %(hogql_val_35)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_36)s)), events__session.`$entry_utm_source`, %(hogql_val_37)s)), [%(hogql_val_38)s, %(hogql_val_39)s, %(hogql_val_40)s, %(hogql_val_41)s, %(hogql_val_42)s, %(hogql_val_43)s, %(hogql_val_44)s, %(hogql_val_45)s]), %(hogql_val_46)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_47)s)), events__session.`$entry_utm_source`, %(hogql_val_48)s)), [%(hogql_val_49)s]), %(hogql_val_50)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_51)s)), events__session.`$entry_utm_source`, %(hogql_val_52)s)), [%(hogql_val_53)s, %(hogql_val_54)s, %(hogql_val_55)s, %(hogql_val_56)s, %(hogql_val_57)s, %(hogql_val_58)s, %(hogql_val_59)s, %(hogql_val_60)s, %(hogql_val_61)s]), %(hogql_val_62)s, if(in(lower(if(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_63)s)), events__session.`$entry_utm_source`, %(hogql_val_64)s)), [%(hogql_val_65)s, %(hogql_val_66)s, %(hogql_val_67)s]), %(hogql_val_68)s, if(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
FROM 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_v7
FROM raw_sessions
@@ -406,7 +406,7 @@
GROUP BY person_distinct_id_overrides.distinct_id
HAVING 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_66)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_67)s, %(hogql_val_68)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_69)s, %(hogql_val_70)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_71)s, %(hogql_val_72)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_73)s, %(hogql_val_74)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_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), (
SELECT DISTINCT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id
FROM 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_id
HAVING equals(argMax(person_distinct_id_overrides.is_deleted, person_distinct_id_overrides.version), 0)
SETTINGS optimize_aggregation_in_order=1) AS events__override ON equals(events.distinct_id, events__override.distinct_id)
- WHERE and(equals(events.team_id, 420), equals(events.event, %(hogql_val_75)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_76)s, %(hogql_val_77)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_78)s, %(hogql_val_79)s))))))
+ 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))))))
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_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(notEmpty(ifNull(events__session.`$entry_utm_source`, %(hogql_val_121)s)), events__session.`$entry_utm_source`, %(hogql_val_122)s))))), events__session.`$start_timestamp`) AS breakdown_value, 1 AS previous, %(hogql_val_123)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_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
FROM events LEFT JOIN (
- SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_80)s)) AS `$start_timestamp`, nullIf(nullIf(argMinMerge(raw_sessions.initial_utm_source), %(hogql_val_81)s), %(hogql_val_82)s) AS `$entry_utm_source`, raw_sessions.session_id_v7 AS session_id_v7
+ 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
FROM 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_83)s, %(hogql_val_84)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_85)s, %(hogql_val_86)s), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_87)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_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 (
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
FROM person_distinct_id_overrides
WHERE equals(person_distinct_id_overrides.team_id, 420)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING 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_124)s), notEmpty(events.`$session_id`), greater(toUnixTimestamp(events__session.`$start_timestamp`), 0)), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_125)s, %(hogql_val_126)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_127)s, %(hogql_val_128)s)), ifNull(greaterOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_129)s, %(hogql_val_130)s)), 0), ifNull(lessOrEquals(events__session.`$start_timestamp`, toDateTime(%(hogql_val_131)s, %(hogql_val_132)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_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), (
SELECT DISTINCT if(not(empty(events__override.distinct_id)), events__override.person_id, events.person_id) AS person_id
FROM 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_id
HAVING 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_133)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, minus(toDateTime(%(hogql_val_134)s, %(hogql_val_135)s), toIntervalDay(90))), less(events.timestamp, toDateTime(%(hogql_val_136)s, %(hogql_val_137)s))))))
+ 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))))))
GROUP BY actor_id), activity AS (
SELECT acquisition.actor_id AS actor_id, acquisition.previous AS previous, min(events__session.`$start_timestamp`) AS returned_at
FROM events LEFT JOIN (
- SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_138)s)) AS `$start_timestamp`, raw_sessions.session_id_v7 AS session_id_v7
+ SELECT min(toTimeZone(raw_sessions.min_timestamp, %(hogql_val_150)s)) AS `$start_timestamp`, raw_sessions.session_id_v7 AS session_id_v7
FROM 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_139)s, %(hogql_val_140)s), toIntervalDay(3))), lessOrEquals(fromUnixTimestamp(intDiv(toUInt64(bitShiftRight(raw_sessions.session_id_v7, 80)), 1000)), plus(toDateTime(%(hogql_val_141)s, %(hogql_val_142)s), toIntervalDay(3))))
- GROUP BY raw_sessions.session_id_v7) AS events__session ON equals(toUInt128(accurateCastOrNull(events.`$session_id`, %(hogql_val_143)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_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 (
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
FROM person_distinct_id_overrides
WHERE equals(person_distinct_id_overrides.team_id, 420)
GROUP BY person_distinct_id_overrides.distinct_id
HAVING 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_144)s), notEmpty(events.`$session_id`), greaterOrEquals(events.timestamp, toDateTime(%(hogql_val_145)s, %(hogql_val_146)s)), lessOrEquals(events.timestamp, toDateTime(%(hogql_val_147)s, %(hogql_val_148)s)), notEquals(events.`$session_id`, acquisition.first_session_id), greater(toDate(events__session.`$start_timestamp`), toDate(toTimeZone(acquisition.first_session_at, %(hogql_val_149)s))), lessOrEquals(events__session.`$start_timestamp`, plus(toTimeZone(acquisition.first_session_at, %(hogql_val_150)s), toIntervalDay(30))), ifNull(lessOrEquals(events__session.`$start_timestamp`, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_151)s)), 0))
+ 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))
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_152)s) AS first_session_at, parseDateTime64BestEffortOrNull(acquisition.observation_end, 6, %(hogql_val_153)s) AS observation_end, toTimeZone(activity.returned_at, %(hogql_val_154)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_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
FROM 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_value
diff --git a/products/marketing_analytics/backend/hogql_queries/adapters/apple_search_ads.py b/products/marketing_analytics/backend/hogql_queries/adapters/apple_search_ads.py
new file mode 100644
index 000000000000..fa4ccb3a6a12
--- /dev/null
+++ b/products/marketing_analytics/backend/hogql_queries/adapters/apple_search_ads.py
@@ -0,0 +1,80 @@
+from posthog.schema import MarketingAnalyticsDrillDownLevel, NativeMarketingSource
+
+from posthog.hogql import ast
+from posthog.hogql.parser import parse_expr
+
+from ..constants import INTEGRATION_DEFAULT_SOURCES, INTEGRATION_PRIMARY_SOURCE
+from .base import HierarchicalNativeAdsConfig, MarketingSourceAdapter, ValidationResult
+
+
+class AppleSearchAdsAdapter(MarketingSourceAdapter[HierarchicalNativeAdsConfig]):
+ _source_type = NativeMarketingSource.APPLE_SEARCH_ADS
+ _stats_date_column = "date"
+ _campaign_stats_fk_column = "campaign_id"
+ _adset_campaign_fk_column = "campaign_id"
+ _adset_stats_fk_column = "ad_group_id"
+
+ @classmethod
+ def get_source_identifier_mapping(cls) -> dict[str, list[str]]:
+ return {INTEGRATION_PRIMARY_SOURCE[cls._source_type]: list(INTEGRATION_DEFAULT_SOURCES[cls._source_type])}
+
+ def get_source_type(self) -> str:
+ return self._source_type.value
+
+ def validate(self) -> ValidationResult:
+ tables = self._level_tables()
+ required_columns = [
+ (tables.entity_table, (tables.entity_id_column, tables.entity_name_column)),
+ (tables.stats_table, (tables.stats_entity_id_column, "date", "impressions", "taps", "local_spend")),
+ ]
+ if self.context.drill_down_level == MarketingAnalyticsDrillDownLevel.AD_GROUP:
+ required_columns.extend(
+ [
+ (tables.entity_table, (self._adset_campaign_fk_column,)),
+ (self.config.campaign_table, (self._campaign_pk_column, self._campaign_name_column)),
+ ]
+ )
+ errors = [
+ f"Apple Ads is missing '{column}' in '{table.name}'. Sync this table again."
+ for table, columns in required_columns
+ for column in columns
+ if not self._table_has_column(table, column)
+ ]
+ return ValidationResult(is_valid=not errors, errors=errors)
+
+ def _sum_metric(self, *columns: str) -> ast.Expr:
+ table = self._level_tables().stats_table
+ fields: list[ast.Expr] = [
+ ast.Call(name="toFloat", args=[ast.Field(chain=[table.name, column])])
+ for column in columns
+ if self._table_has_column(table, column)
+ ]
+ if not fields:
+ return ast.Constant(value=0)
+ return ast.Call(name="sum", args=[ast.Call(name="coalesce", args=[*fields, ast.Constant(value=0)])])
+
+ def _get_impressions_field(self) -> ast.Expr:
+ return self._sum_metric("impressions")
+
+ def _get_clicks_field(self) -> ast.Expr:
+ return self._sum_metric("taps")
+
+ def _get_cost_field(self) -> ast.Expr:
+ table = self._level_tables().stats_table
+ # Apple stores spend as a JSON money object in account currency, including under API v1.
+ return parse_expr(
+ "sum(toFloat(convertCurrency({spend}.currency, {currency}, "
+ "coalesce(toFloat({spend}.amount), 0), coalesce(toDate({date}), today()))))",
+ placeholders={
+ "spend": ast.Field(chain=[table.name, "local_spend"]),
+ "currency": ast.Constant(value=self.context.base_currency),
+ "date": ast.Field(chain=[table.name, "date"]),
+ },
+ )
+
+ def _get_reported_conversion_field(self) -> ast.Expr:
+ # API v1 renamed installs; repinned sources can contain both column generations.
+ return self._sum_metric("total_installs", "installs")
+
+ def _get_reported_conversion_value_field(self) -> ast.Expr:
+ return ast.Constant(value=0)
diff --git a/products/marketing_analytics/backend/hogql_queries/adapters/factory.py b/products/marketing_analytics/backend/hogql_queries/adapters/factory.py
index 7eb83333bef7..65557c252176 100644
--- a/products/marketing_analytics/backend/hogql_queries/adapters/factory.py
+++ b/products/marketing_analytics/backend/hogql_queries/adapters/factory.py
@@ -20,6 +20,7 @@ from products.marketing_analytics.backend.hogql_queries.adapters.pinterest_ads i
from products.marketing_analytics.backend.hogql_queries.adapters.reddit_ads import RedditAdsAdapter
from products.marketing_analytics.backend.hogql_queries.adapters.snapchat_ads import SnapchatAdsAdapter
from products.marketing_analytics.backend.hogql_queries.adapters.tiktok_ads import TikTokAdsAdapter
+from products.marketing_analytics.backend.services.native_integrations import is_native_source_enabled
from products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSource
from ..constants import (
@@ -30,6 +31,7 @@ from ..constants import (
build_fallback_empty_query_ast,
)
from ..utils import map_url_to_provider
+from .apple_search_ads import AppleSearchAdsAdapter
from .base import (
BingAdsConfig,
ExternalConfig,
@@ -76,6 +78,7 @@ class MarketingSourceFactory:
# Registry of adapter classes
_adapter_registry: dict[str, type[MarketingSourceAdapter]] = {
# Native adapters
+ "AppleSearchAds": AppleSearchAdsAdapter,
"GoogleAds": GoogleAdsAdapter,
"LinkedinAds": LinkedinAdsAdapter,
"RedditAds": RedditAdsAdapter,
@@ -96,6 +99,7 @@ class MarketingSourceFactory:
# A new native source needs an entry here, in TABLE_PATTERNS (constants.py), and
# 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),
"GoogleAds": (NativeMarketingSource.GOOGLE_ADS, GoogleAdsConfig),
"LinkedinAds": (NativeMarketingSource.LINKEDIN_ADS, LinkedinAdsConfig),
"RedditAds": (NativeMarketingSource.REDDIT_ADS, RedditAdsConfig),
@@ -205,6 +209,8 @@ class MarketingSourceFactory:
for source in self._external_sources:
if source.source_type not in VALID_NATIVE_MARKETING_SOURCES:
continue
+ if not is_native_source_enabled(source.source_type, self.context.team):
+ continue
tables = self._tables_by_source_id.get(str(source.id), [])
if not tables:
diff --git a/products/marketing_analytics/backend/hogql_queries/adapters/test_apple_search_ads.py b/products/marketing_analytics/backend/hogql_queries/adapters/test_apple_search_ads.py
new file mode 100644
index 000000000000..2e67b2d3a0c5
--- /dev/null
+++ b/products/marketing_analytics/backend/hogql_queries/adapters/test_apple_search_ads.py
@@ -0,0 +1,125 @@
+from datetime import UTC, datetime
+
+from unittest.mock import PropertyMock, patch
+
+from django.test import SimpleTestCase
+
+from parameterized import parameterized
+
+from posthog.schema import DateRange, MarketingAnalyticsDrillDownLevel
+
+from posthog.hogql import ast
+from posthog.hogql.placeholders import replace_placeholders
+
+from posthog.hogql_queries.utils.query_date_range import QueryDateRange
+from posthog.models import Team
+from posthog.models.team.team_marketing_analytics_config import TeamMarketingAnalyticsConfig
+
+from products.warehouse_sources.backend.facade.models import DataWarehouseTable
+
+from .apple_search_ads import AppleSearchAdsAdapter
+from .base import HierarchicalNativeAdsConfig, QueryContext
+
+
+class TestAppleSearchAdsAdapter(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, columns: list[str], level: MarketingAnalyticsDrillDownLevel) -> AppleSearchAdsAdapter:
+ def table(name: str, fields: list[str]) -> DataWarehouseTable:
+ return DataWarehouseTable(name=f"applesearchads_{name}", columns=dict.fromkeys(fields, "String"))
+
+ metrics = ["date", "impressions", "taps", "local_spend", *columns]
+ return AppleSearchAdsAdapter(
+ HierarchicalNativeAdsConfig(
+ source_type="AppleSearchAds",
+ source_id="apple-source",
+ campaign_table=table("campaigns", ["id", "name"]),
+ stats_table=table("campaign_report", ["campaign_id", *metrics]),
+ adset_table=table("ad_groups", ["id", "name", "campaign_id"]),
+ adset_stats_table=table("ad_group_report", ["ad_group_id", *metrics]),
+ ),
+ 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=level,
+ ),
+ )
+
+ @parameterized.expand(
+ [
+ ("v5", ["installs"], "installs"),
+ ("v1", ["total_installs"], "total_installs"),
+ ("repinned", ["total_installs", "installs"], "total_installs"),
+ ]
+ )
+ def test_campaign_queries_use_daily_money_and_versioned_installs(
+ self, _name: str, columns: list[str], conversion_column: str
+ ) -> None:
+ adapter = self._adapter(columns, MarketingAnalyticsDrillDownLevel.CAMPAIGN)
+ assert adapter.validate().is_valid
+ for query in (adapter.build_query(), adapter.build_materialization_query("apple-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 "applesearchads_campaign_report.local_spend['amount']" in sql
+ assert "applesearchads_campaign_report.local_spend['currency']" in sql
+ assert "'EUR'" in sql
+ assert "toDate(applesearchads_campaign_report.date)" in sql
+ assert f"applesearchads_campaign_report.{conversion_column}" in sql
+ assert "applesearchads_campaign_report.taps" in sql
+ if len(columns) == 2:
+ assert (
+ "coalesce(toFloat(applesearchads_campaign_report.total_installs), toFloat(applesearchads_campaign_report.installs), 0)"
+ in sql
+ )
+
+ def test_ad_group_query_joins_campaign_and_uses_ad_group_report(self) -> None:
+ adapter = self._adapter(["total_installs"], MarketingAnalyticsDrillDownLevel.AD_GROUP)
+ assert adapter.supports_level(MarketingAnalyticsDrillDownLevel.AD_GROUP)
+ assert not adapter.supports_level(MarketingAnalyticsDrillDownLevel.AD)
+ query = adapter.build_query()
+ assert query is not None
+ sql = query.to_hogql()
+ assert "applesearchads_ad_group_report.ad_group_id" in sql
+ assert "applesearchads_ad_groups.campaign_id" in sql
+ assert "applesearchads_ad_group_report.local_spend['amount']" in sql
+ assert "applesearchads_campaign_report" not in sql
+
+ @parameterized.expand(
+ [
+ (MarketingAnalyticsDrillDownLevel.CAMPAIGN, "stats_table", "local_spend"),
+ (MarketingAnalyticsDrillDownLevel.AD_GROUP, "adset_table", "campaign_id"),
+ (MarketingAnalyticsDrillDownLevel.AD_GROUP, "campaign_table", "id"),
+ (MarketingAnalyticsDrillDownLevel.AD_GROUP, "campaign_table", "name"),
+ ]
+ )
+ def test_missing_required_columns_are_reported_as_invalid(
+ self, level: MarketingAnalyticsDrillDownLevel, table_name: str, column: str
+ ) -> None:
+ adapter = self._adapter(["total_installs"], level)
+ table = getattr(adapter.config, table_name)
+ assert table.columns is not None
+ del table.columns[column]
+ result = adapter.validate()
+ assert not result.is_valid
+ assert column in result.errors[0]
diff --git a/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py b/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py
index b62d73031ca0..86d2a36c576f 100644
--- a/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py
+++ b/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py
@@ -2,9 +2,10 @@ from datetime import datetime
from typing import cast
from posthog.test.base import BaseTest
-from unittest.mock import Mock
+from unittest.mock import Mock, patch
from django.core.exceptions import ValidationError
+from django.test import SimpleTestCase
from parameterized import parameterized
@@ -27,7 +28,8 @@ from products.marketing_analytics.backend.hogql_queries.adapters.base import (
)
from products.marketing_analytics.backend.hogql_queries.adapters.factory import MarketingSourceFactory
from products.marketing_analytics.backend.hogql_queries.adapters.meta_ads import MetaAdsAdapter
-from products.warehouse_sources.backend.facade.models import DataWarehouseTable
+from products.marketing_analytics.backend.hogql_queries.constants import TABLE_PATTERNS
+from products.warehouse_sources.backend.facade.models import DataWarehouseTable, ExternalDataSource
class FactoryTestMixin:
@@ -547,3 +549,36 @@ class TestNativeCampaignTableResolution(FactoryTestMixin, BaseTest):
assert config is not None
assert config.campaign_table is campaign
assert config.stats_table is stats
+
+
+class TestNativeSourceKillSwitch(SimpleTestCase):
+ @parameterized.expand([(False,), (True,)])
+ def test_factory_excludes_disabled_source_without_affecting_google(self, enabled: bool) -> None:
+ team = Team(id=1)
+ factory = MarketingSourceFactory.__new__(MarketingSourceFactory)
+ factory.context = Mock(spec=QueryContext, team=team)
+ factory.logger = Mock()
+ factory._warehouse_tables = []
+ factory._external_sources = []
+ factory._tables_by_source_id = {}
+ for source_type in ("GoogleAds", "AppleSearchAds"):
+ source = ExternalDataSource(source_type=source_type)
+ patterns = TABLE_PATTERNS[NativeMarketingSource(source_type)]
+ tables = [
+ DataWarehouseTable(name=f"{source_type}_{name}", external_data_source=source)
+ for name in {patterns["campaign_table_name"], patterns["stats_table_keywords"][0]}
+ ]
+ factory._external_sources.append(source)
+ factory._warehouse_tables.extend(tables)
+ factory._tables_by_source_id[str(source.id)] = tables
+
+ with patch(
+ "products.marketing_analytics.backend.services.native_integrations.feature_enabled_or_false",
+ return_value=enabled,
+ ):
+ adapters = factory.create_adapters()
+
+ assert [adapter.get_source_type() for adapter in adapters] == (
+ ["GoogleAds", "AppleSearchAds"] if enabled else ["GoogleAds"]
+ )
+ factory.logger.exception.assert_not_called()
diff --git a/products/marketing_analytics/backend/hogql_queries/constants.py b/products/marketing_analytics/backend/hogql_queries/constants.py
index 2ba8c186c77d..0676cd601fe0 100644
--- a/products/marketing_analytics/backend/hogql_queries/constants.py
+++ b/products/marketing_analytics/backend/hogql_queries/constants.py
@@ -6,6 +6,7 @@ from typing import Optional, TypedDict, Union
from pydantic import BaseModel
from posthog.schema import (
+ AppleSearchAdsDefaultSources,
BingAdsDefaultSources,
DefaultChannelTypes,
GoogleAdsDefaultSources,
@@ -24,6 +25,7 @@ from posthog.schema import (
MarketingIntegrationConfig6,
MarketingIntegrationConfig7,
MarketingIntegrationConfig8,
+ MarketingIntegrationConfig9,
MetaAdsConversionFallbackActionTypes,
MetaAdsConversionOmniActionTypes,
MetaAdsConversionSpecificActionTypes,
@@ -508,6 +510,7 @@ _ALL_CONFIG_MODELS: list[type[BaseModel]] = [
MarketingIntegrationConfig6,
MarketingIntegrationConfig7,
MarketingIntegrationConfig8,
+ MarketingIntegrationConfig9,
]
@@ -537,6 +540,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.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.py
index 45bbb245c4e5..4fda4347690e 100644
--- a/products/marketing_analytics/backend/services/data_source_health.py
+++ b/products/marketing_analytics/backend/services/data_source_health.py
@@ -20,6 +20,7 @@ from products.marketing_analytics.backend.hogql_queries.constants import (
from products.marketing_analytics.backend.services.native_integrations import (
DISPLAY_NAMES,
EXTERNAL_SOURCE_TYPE_TO_NATIVE,
+ is_native_source_enabled,
)
from products.warehouse_sources.backend.facade.models import ExternalDataJob, ExternalDataSchema, ExternalDataSource
from products.warehouse_sources.backend.facade.types import ExternalDataJobStatus
@@ -124,7 +125,9 @@ async def get_data_source_health(
`marketing_analytics_config.sources_map` instead of triggering another
Postgres roundtrip. None → service loads it itself.
"""
- targets = EXTERNAL_SOURCE_TYPE_TO_NATIVE
+ targets = {
+ key: native for key, native in EXTERNAL_SOURCE_TYPE_TO_NATIVE.items() if is_native_source_enabled(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.py
index 6f89ad2978a4..887ce61ca01b 100644
--- a/products/marketing_analytics/backend/services/native_integrations.py
+++ b/products/marketing_analytics/backend/services/native_integrations.py
@@ -8,11 +8,17 @@ else before lookup.
from collections.abc import Iterator, Mapping
from functools import cache
from types import MappingProxyType
-from typing import Literal
+from typing import TYPE_CHECKING, Literal
from posthog.schema import NativeMarketingSource
+from posthog.ph_client import feature_enabled_or_false
+
+if TYPE_CHECKING:
+ from posthog.models.team import Team
+
NativeIntegration = Literal[
+ "apple_ads",
"google_ads",
"meta_ads",
"bing_ads",
@@ -27,6 +33,7 @@ NativeIntegration = Literal[
# Mapping from NativeMarketingSource to the snake-case key used everywhere
# downstream (URL params, scope hints, suggestion targets).
NATIVE_TO_KEY: dict[NativeMarketingSource, NativeIntegration] = {
+ NativeMarketingSource.APPLE_SEARCH_ADS: "apple_ads",
NativeMarketingSource.GOOGLE_ADS: "google_ads",
NativeMarketingSource.META_ADS: "meta_ads",
NativeMarketingSource.BING_ADS: "bing_ads",
@@ -44,6 +51,7 @@ KEY_TO_NATIVE: dict[NativeIntegration, NativeMarketingSource] = {v: k for k, v i
# layer uses) to NativeMarketingSource. Pinned explicitly because
# ExternalDataSourceType has many non-marketing entries.
EXTERNAL_SOURCE_TYPE_TO_NATIVE: dict[str, NativeMarketingSource] = {
+ "AppleSearchAds": NativeMarketingSource.APPLE_SEARCH_ADS,
"GoogleAds": NativeMarketingSource.GOOGLE_ADS,
"MetaAds": NativeMarketingSource.META_ADS,
"BingAds": NativeMarketingSource.BING_ADS,
@@ -56,6 +64,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.GOOGLE_ADS: "Google Ads",
NativeMarketingSource.META_ADS: "Meta Ads",
NativeMarketingSource.BING_ADS: "Bing Ads",
@@ -81,6 +90,23 @@ OAUTH_KIND_BY_NATIVE: dict[NativeMarketingSource, str] = {
}
+NATIVE_SOURCE_FEATURE_FLAGS: dict[str, str] = {
+ "AppleSearchAds": "marketing-analytics-apple-ads",
+}
+
+
+def is_native_source_enabled(source_type: str, team: "Team") -> bool:
+ flag = NATIVE_SOURCE_FEATURE_FLAGS.get(source_type)
+ if flag is None:
+ return True
+ return feature_enabled_or_false(
+ flag,
+ str(team.uuid),
+ groups={"organization": str(team.organization_id)},
+ group_properties={"organization": {"id": str(team.organization_id)}},
+ )
+
+
def display_name_for_key(key: NativeIntegration) -> str:
return DISPLAY_NAMES[KEY_TO_NATIVE[key]]
diff --git a/products/marketing_analytics/backend/services/test_native_integrations.py b/products/marketing_analytics/backend/services/test_native_integrations.py
index 1459ea666ce6..476abcae7f67 100644
--- a/products/marketing_analytics/backend/services/test_native_integrations.py
+++ b/products/marketing_analytics/backend/services/test_native_integrations.py
@@ -1,6 +1,11 @@
+from unittest.mock import patch
+
from parameterized import parameterized
+from posthog.schema import NativeMarketingSource
+
from posthog.models.integration import OauthIntegration
+from posthog.models.team import Team
from products.marketing_analytics.backend.services.native_integrations import (
DISPLAY_NAMES,
@@ -11,6 +16,7 @@ from products.marketing_analytics.backend.services.native_integrations import (
aliases_for,
canonical_source_aliases,
display_name_for_key,
+ is_native_source_enabled,
lookup_alias,
normalize,
)
@@ -104,6 +110,7 @@ class TestAliasesFor:
class TestDisplayNames:
@parameterized.expand(
[
+ ("apple_ads", "Apple Ads"),
("google_ads", "Google Ads"),
("meta_ads", "Meta Ads"),
("bing_ads", "Bing Ads"),
@@ -120,13 +127,15 @@ class TestDisplayNames:
class TestStructuralInvariants:
def test_native_to_key_is_bijection_with_key_to_native(self):
+ assert set(NATIVE_TO_KEY) == set(NativeMarketingSource)
assert {v: k for k, v in NATIVE_TO_KEY.items()} == KEY_TO_NATIVE
def test_display_names_cover_all_natives(self):
- for native in NATIVE_TO_KEY.keys():
+ for native in NativeMarketingSource:
assert native in DISPLAY_NAMES
def test_external_source_type_resolves_to_native(self):
+ assert set(EXTERNAL_SOURCE_TYPE_TO_NATIVE.values()) == set(NativeMarketingSource)
for source_type, native in EXTERNAL_SOURCE_TYPE_TO_NATIVE.items():
assert native in NATIVE_TO_KEY
assert isinstance(source_type, str)
@@ -138,6 +147,25 @@ class TestStructuralInvariants:
assert not unknown, f"{sorted(unknown)} are not kinds the authorize endpoint accepts"
- def test_every_native_integration_has_an_oauth_kind(self):
- for native in NATIVE_TO_KEY:
- assert native in OAUTH_KIND_BY_NATIVE, f"{native} has no OAuth kind, so it can't be connected"
+ def test_only_credential_based_integrations_lack_an_oauth_kind(self) -> None:
+ assert set(NativeMarketingSource) - set(OAUTH_KIND_BY_NATIVE) == {NativeMarketingSource.APPLE_SEARCH_ADS}
+
+
+class TestNativeSourceFeatureFlags:
+ @parameterized.expand([(False,), (True,)])
+ def test_source_rollout_does_not_disable_existing_integrations(self, 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
+ evaluate.assert_called_once_with(
+ "marketing-analytics-apple-ads",
+ str(team.uuid),
+ groups={"organization": str(team.organization_id)},
+ group_properties={"organization": {"id": str(team.organization_id)}},
+ )
+ evaluate.reset_mock()
+ assert is_native_source_enabled("GoogleAds", team)
+ evaluate.assert_not_called()