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.

fix(marketing-analytics): stop non-campaign tables from claiming the campaign slot (#80556)

Xander35c32150e297
diff --git a/frontend/src/queries/schema.json b/frontend/src/queries/schema.json
index dabf93d8fcdb..880061256e5d 100644
--- a/frontend/src/queries/schema.json
+++ b/frontend/src/queries/schema.json
@@ -5703,14 +5703,6 @@
"enum": ["bing", "microsoft", "msads", "bing_video"],
"type": "string"
},
- "BingAdsTableExclusions": {
- "enum": ["performance"],
- "type": "string"
- },
- "BingAdsTableKeywords": {
- "enum": ["campaigns"],
- "type": "string"
- },
"BoxPlotDatum": {
"additionalProperties": false,
"properties": {
@@ -27141,14 +27133,6 @@
],
"type": "string"
},
- "GoogleAdsTableExclusions": {
- "enum": ["stats"],
- "type": "string"
- },
- "GoogleAdsTableKeywords": {
- "enum": ["campaign"],
- "type": "string"
- },
"GroupMathType": {
"const": "unique_group",
"type": "string"
@@ -29870,14 +29854,6 @@
"enum": ["linkedin", "li"],
"type": "string"
},
- "LinkedinAdsTableExclusions": {
- "enum": ["stats"],
- "type": "string"
- },
- "LinkedinAdsTableKeywords": {
- "enum": ["campaign_groups"],
- "type": "string"
- },
"LoadingBlock": {
"additionalProperties": false,
"properties": {
@@ -33636,24 +33612,6 @@
"statsTableName": {
"const": "campaign_overview_stats",
"type": "string"
- },
- "tableExclusions": {
- "items": {
- "const": "stats",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
- },
- "tableKeywords": {
- "items": {
- "const": "campaign",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
}
},
"required": [
@@ -33662,8 +33620,6 @@
"idField",
"campaignTableName",
"statsTableName",
- "tableKeywords",
- "tableExclusions",
"defaultSources",
"primarySource",
"adsetTableName",
@@ -33730,24 +33686,6 @@
"statsTableName": {
"const": "campaign_group_stats",
"type": "string"
- },
- "tableExclusions": {
- "items": {
- "const": "stats",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
- },
- "tableKeywords": {
- "items": {
- "const": "campaign_groups",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
}
},
"required": [
@@ -33756,8 +33694,6 @@
"idField",
"campaignTableName",
"statsTableName",
- "tableKeywords",
- "tableExclusions",
"defaultSources",
"primarySource",
"adsetTableName",
@@ -33956,24 +33892,6 @@
"statsTableName": {
"const": "campaign_stats",
"type": "string"
- },
- "tableExclusions": {
- "items": {
- "const": "stats",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
- },
- "tableKeywords": {
- "items": {
- "const": "campaigns",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
}
},
"required": [
@@ -33982,8 +33900,6 @@
"idField",
"campaignTableName",
"statsTableName",
- "tableKeywords",
- "tableExclusions",
"defaultSources",
"primarySource",
"adsetTableName",
@@ -34045,24 +33961,6 @@
"statsTableName": {
"const": "campaign_report",
"type": "string"
- },
- "tableExclusions": {
- "items": {
- "const": "report",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
- },
- "tableKeywords": {
- "items": {
- "const": "campaigns",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
}
},
"required": [
@@ -34071,8 +33969,6 @@
"idField",
"campaignTableName",
"statsTableName",
- "tableKeywords",
- "tableExclusions",
"defaultSources",
"primarySource",
"adsetTableName",
@@ -34133,24 +34029,6 @@
"statsTableName": {
"const": "campaign_report",
"type": "string"
- },
- "tableExclusions": {
- "items": {
- "const": "report",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
- },
- "tableKeywords": {
- "items": {
- "const": "campaigns",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
}
},
"required": [
@@ -34159,8 +34037,6 @@
"idField",
"campaignTableName",
"statsTableName",
- "tableKeywords",
- "tableExclusions",
"defaultSources",
"primarySource",
"adsetTableName",
@@ -34235,24 +34111,6 @@
"statsTableName": {
"const": "campaign_performance_report",
"type": "string"
- },
- "tableExclusions": {
- "items": {
- "const": "performance",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
- },
- "tableKeywords": {
- "items": {
- "const": "campaigns",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
}
},
"required": [
@@ -34261,8 +34119,6 @@
"idField",
"campaignTableName",
"statsTableName",
- "tableKeywords",
- "tableExclusions",
"defaultSources",
"primarySource",
"adsetTableName",
@@ -34361,24 +34217,6 @@
"statsTableName": {
"const": "campaign_stats_daily",
"type": "string"
- },
- "tableExclusions": {
- "items": {
- "const": "stats_daily",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
- },
- "tableKeywords": {
- "items": {
- "const": "campaigns",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
}
},
"required": [
@@ -34387,8 +34225,6 @@
"idField",
"campaignTableName",
"statsTableName",
- "tableKeywords",
- "tableExclusions",
"defaultSources",
"primarySource",
"adsetTableName",
@@ -34451,24 +34287,6 @@
"statsTableName": {
"const": "campaign_analytics",
"type": "string"
- },
- "tableExclusions": {
- "items": {
- "const": "analytics",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
- },
- "tableKeywords": {
- "items": {
- "const": "campaigns",
- "type": "string"
- },
- "maxItems": 1,
- "minItems": 1,
- "type": "array"
}
},
"required": [
@@ -34477,8 +34295,6 @@
"idField",
"campaignTableName",
"statsTableName",
- "tableKeywords",
- "tableExclusions",
"defaultSources",
"primarySource",
"adsetTableName",
@@ -34516,18 +34332,6 @@
},
"statsTableName": {
"type": "string"
- },
- "tableExclusions": {
- "items": {
- "type": "string"
- },
- "type": "array"
- },
- "tableKeywords": {
- "items": {
- "type": "string"
- },
- "type": "array"
}
},
"required": [
@@ -34536,8 +34340,6 @@
"idField",
"campaignTableName",
"statsTableName",
- "tableKeywords",
- "tableExclusions",
"defaultSources",
"primarySource"
],
@@ -35573,14 +35375,6 @@
],
"type": "string"
},
- "MetaAdsTableExclusions": {
- "enum": ["stats"],
- "type": "string"
- },
- "MetaAdsTableKeywords": {
- "enum": ["campaigns"],
- "type": "string"
- },
"MetricPropertyFilter": {
"additionalProperties": false,
"properties": {
@@ -37602,14 +37396,6 @@
"enum": ["pinterest"],
"type": "string"
},
- "PinterestAdsTableExclusions": {
- "enum": ["analytics"],
- "type": "string"
- },
- "PinterestAdsTableKeywords": {
- "enum": ["campaigns"],
- "type": "string"
- },
"PlanningMessage": {
"additionalProperties": false,
"properties": {
@@ -46877,14 +46663,6 @@
"enum": ["reddit"],
"type": "string"
},
- "RedditAdsTableExclusions": {
- "enum": ["report"],
- "type": "string"
- },
- "RedditAdsTableKeywords": {
- "enum": ["campaigns"],
- "type": "string"
- },
"RefreshType": {
"enum": [
"async",
@@ -49034,14 +48812,6 @@
"enum": ["snapchat"],
"type": "string"
},
- "SnapchatAdsTableExclusions": {
- "enum": ["stats_daily"],
- "type": "string"
- },
- "SnapchatAdsTableKeywords": {
- "enum": ["campaigns"],
- "type": "string"
- },
"SourceConfig": {
"additionalProperties": false,
"properties": {
@@ -51016,14 +50786,6 @@
"enum": ["tiktok"],
"type": "string"
},
- "TikTokAdsTableExclusions": {
- "enum": ["report"],
- "type": "string"
- },
- "TikTokAdsTableKeywords": {
- "enum": ["campaigns"],
- "type": "string"
- },
"TileFilters": {
"additionalProperties": false,
"properties": {
diff --git a/frontend/src/queries/schema/schema-general.ts b/frontend/src/queries/schema/schema-general.ts
index 40aa2d2e9e7d..fcae24ace7d3 100644
--- a/frontend/src/queries/schema/schema-general.ts
+++ b/frontend/src/queries/schema/schema-general.ts
@@ -8923,8 +8923,6 @@ export const MARKETING_INTEGRATION_CONFIGS = {
idField: 'campaign_id',
campaignTableName: 'campaign',
statsTableName: 'campaign_overview_stats',
- tableKeywords: ['campaign'] as const,
- tableExclusions: ['stats'] as const,
defaultSources: [
'google',
'adwords',
@@ -8952,8 +8950,6 @@ export const MARKETING_INTEGRATION_CONFIGS = {
idField: 'id',
campaignTableName: 'campaign_groups',
statsTableName: 'campaign_group_stats',
- tableKeywords: ['campaign_groups'] as const,
- tableExclusions: ['stats'] as const,
defaultSources: ['linkedin', 'li'] as const,
primarySource: 'linkedin',
// LinkedIn API hierarchy: Account → CampaignGroup → Campaign → Creative.
@@ -8971,8 +8967,6 @@ export const MARKETING_INTEGRATION_CONFIGS = {
idField: 'id',
campaignTableName: 'campaigns',
statsTableName: 'campaign_stats',
- tableKeywords: ['campaigns'] as const,
- tableExclusions: ['stats'] as const,
defaultSources: [
'meta',
'facebook',
@@ -9017,8 +9011,6 @@ export const MARKETING_INTEGRATION_CONFIGS = {
idField: 'campaign_id',
campaignTableName: 'campaigns',
statsTableName: 'campaign_report',
- tableKeywords: ['campaigns'] as const,
- tableExclusions: ['report'] as const,
defaultSources: ['tiktok'] as const,
primarySource: 'tiktok',
adsetTableName: 'ad_groups' as const,
@@ -9032,8 +9024,6 @@ export const MARKETING_INTEGRATION_CONFIGS = {
idField: 'id',
campaignTableName: 'campaigns',
statsTableName: 'campaign_report',
- tableKeywords: ['campaigns'] as const,
- tableExclusions: ['report'] as const,
defaultSources: ['reddit'] as const,
primarySource: 'reddit',
adsetTableName: 'ad_groups' as const,
@@ -9047,8 +9037,6 @@ export const MARKETING_INTEGRATION_CONFIGS = {
idField: 'id',
campaignTableName: 'campaigns',
statsTableName: 'campaign_performance_report',
- tableKeywords: ['campaigns'] as const,
- tableExclusions: ['performance'] as const,
defaultSources: ['bing', 'microsoft', 'msads', 'bing_video'] as const,
primarySource: 'bing',
// At ad-group / ad level Bing's data import only ships performance *reports* —
@@ -9068,8 +9056,6 @@ export const MARKETING_INTEGRATION_CONFIGS = {
idField: 'id',
campaignTableName: 'campaigns',
statsTableName: 'campaign_stats_daily',
- tableKeywords: ['campaigns'] as const,
- tableExclusions: ['stats_daily'] as const,
defaultSources: ['snapchat'] as const,
primarySource: 'snapchat',
adsetTableName: 'ad_squads' as const,
@@ -9089,8 +9075,6 @@ export const MARKETING_INTEGRATION_CONFIGS = {
idField: 'id',
campaignTableName: 'campaigns',
statsTableName: 'campaign_analytics',
- tableKeywords: ['campaigns'] as const,
- tableExclusions: ['analytics'] as const,
defaultSources: ['pinterest'] as const,
primarySource: 'pinterest',
adsetTableName: 'ad_groups' as const,
@@ -9112,27 +9096,6 @@ export type SnapchatAdsDefaultSources = (typeof MARKETING_INTEGRATION_CONFIGS)['
export type PinterestAdsDefaultSources =
(typeof MARKETING_INTEGRATION_CONFIGS)['PinterestAds']['defaultSources'][number]
-export type GoogleAdsTableKeywords = (typeof MARKETING_INTEGRATION_CONFIGS)['GoogleAds']['tableKeywords'][number]
-export type LinkedinAdsTableKeywords = (typeof MARKETING_INTEGRATION_CONFIGS)['LinkedinAds']['tableKeywords'][number]
-export type MetaAdsTableKeywords = (typeof MARKETING_INTEGRATION_CONFIGS)['MetaAds']['tableKeywords'][number]
-export type TikTokAdsTableKeywords = (typeof MARKETING_INTEGRATION_CONFIGS)['TikTokAds']['tableKeywords'][number]
-export type RedditAdsTableKeywords = (typeof MARKETING_INTEGRATION_CONFIGS)['RedditAds']['tableKeywords'][number]
-export type BingAdsTableKeywords = (typeof MARKETING_INTEGRATION_CONFIGS)['BingAds']['tableKeywords'][number]
-export type SnapchatAdsTableKeywords = (typeof MARKETING_INTEGRATION_CONFIGS)['SnapchatAds']['tableKeywords'][number]
-export type PinterestAdsTableKeywords = (typeof MARKETING_INTEGRATION_CONFIGS)['PinterestAds']['tableKeywords'][number]
-
-export type GoogleAdsTableExclusions = (typeof MARKETING_INTEGRATION_CONFIGS)['GoogleAds']['tableExclusions'][number]
-export type LinkedinAdsTableExclusions =
- (typeof MARKETING_INTEGRATION_CONFIGS)['LinkedinAds']['tableExclusions'][number]
-export type MetaAdsTableExclusions = (typeof MARKETING_INTEGRATION_CONFIGS)['MetaAds']['tableExclusions'][number]
-export type TikTokAdsTableExclusions = (typeof MARKETING_INTEGRATION_CONFIGS)['TikTokAds']['tableExclusions'][number]
-export type RedditAdsTableExclusions = (typeof MARKETING_INTEGRATION_CONFIGS)['RedditAds']['tableExclusions'][number]
-export type BingAdsTableExclusions = (typeof MARKETING_INTEGRATION_CONFIGS)['BingAds']['tableExclusions'][number]
-export type SnapchatAdsTableExclusions =
- (typeof MARKETING_INTEGRATION_CONFIGS)['SnapchatAds']['tableExclusions'][number]
-export type PinterestAdsTableExclusions =
- (typeof MARKETING_INTEGRATION_CONFIGS)['PinterestAds']['tableExclusions'][number]
-
// Conversion fields for Snapchat Ads - extracted as types so they generate as StrEnum in Python
export type SnapchatAdsConversionFields =
(typeof MARKETING_INTEGRATION_CONFIGS)['SnapchatAds']['conversionFields'][number]
@@ -9157,16 +9120,6 @@ export const MARKETING_INTEGRATION_FIELD_MAP = Object.fromEntries(
])
) as unknown as Record<NativeMarketingSource, { nameField: string; idField: string }>
-export const MARKETING_CAMPAIGN_TABLE_PATTERNS = Object.fromEntries(
- VALID_NATIVE_MARKETING_SOURCES.map((source) => [
- source,
- {
- keywords: [...MARKETING_INTEGRATION_CONFIGS[source].tableKeywords],
- exclusions: [...MARKETING_INTEGRATION_CONFIGS[source].tableExclusions],
- },
- ])
-) as unknown as Record<NativeMarketingSource, { keywords: string[]; exclusions: string[] }>
-
export const MARKETING_DEFAULT_SOURCE_MAPPINGS = Object.fromEntries(
VALID_NATIVE_MARKETING_SOURCES.map((source) => [source, [...MARKETING_INTEGRATION_CONFIGS[source].defaultSources]])
) as unknown as Record<NativeMarketingSource, string[]>
@@ -9177,8 +9130,6 @@ export interface MarketingIntegrationConfigType {
idField: string
campaignTableName: string
statsTableName: string
- tableKeywords: string[]
- tableExclusions: string[]
defaultSources: string[]
primarySource: string
}
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 dce4cb08f356..261472bb66ba 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
@@ -10,7 +10,7 @@ import {
ConversionGoalFilter,
DatabaseSchemaDataWarehouseTable,
HogQLQueryResponse,
- MARKETING_CAMPAIGN_TABLE_PATTERNS,
+ MARKETING_INTEGRATION_CONFIGS,
MARKETING_INTEGRATION_FIELD_MAP,
MarketingAnalyticsColumnsSchemaNames,
MarketingAnalyticsConfig,
@@ -29,7 +29,7 @@ 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, generateUniqueName } from './utils'
+import { DEFAULT_ATTRIBUTION_WINDOW_DAYS, extractSchemaName, generateUniqueName } from './utils'
export interface IntegrationSettingsModalState {
isOpen: boolean
@@ -496,8 +496,8 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
if (!isNativeMarketingSource(sourceType)) {
continue
}
- const patterns = MARKETING_CAMPAIGN_TABLE_PATTERNS[sourceType]
- if (!patterns) {
+ const campaignTableName = MARKETING_INTEGRATION_CONFIGS[sourceType]?.campaignTableName
+ if (!campaignTableName) {
continue
}
@@ -506,14 +506,12 @@ export const marketingAnalyticsSettingsLogic = kea<marketingAnalyticsSettingsLog
(table) => table.source?.source_type === sourceType
)
- // Find the campaign table using the same pattern matching as the backend
+ // Match the declared schema name exactly, like the backend factory does.
+ // Keyword matching also claimed unrelated schemas that merely contain the
+ // keyword — Google Ads `campaign_budget` — and then every query against
+ // the resolved table failed on the missing campaign columns.
for (const table of sourceTables) {
- const tableSuffix = table.name.split('.').pop()?.toLowerCase() || ''
-
- const matchesKeyword = patterns.keywords.some((kw: string) => tableSuffix.includes(kw))
- const matchesExclusion = patterns.exclusions.some((ex: string) => tableSuffix.includes(ex))
-
- if (matchesKeyword && !matchesExclusion) {
+ if (extractSchemaName(table.name, sourceType) === campaignTableName) {
result[sourceType] = table.name
break
}
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 a52c6b7d9c96..b5d7a916839e 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
@@ -107,6 +107,16 @@ export const NATIVE_SOURCE_HIERARCHY_SCHEMA_NAMES: Partial<
}).filter((entry): entry is [NativeMarketingSource, NativeSourceHierarchySchemaNames] => entry !== null)
)
+/** Mirrors the backend `_extract_schema_name` (factory.py). Warehouse tables are named
+ * `{user_prefix}{source_type}_{schema_name}`, and the prefix is free text, so it can
+ * repeat the marker — take the last occurrence, which is always the real boundary. */
+export function extractSchemaName(tableName: string, sourceType: string): string {
+ const suffix = tableName.split('.').pop()?.toLowerCase() || ''
+ const marker = `${sourceType.toLowerCase()}_`
+ const index = suffix.lastIndexOf(marker)
+ return index === -1 ? suffix : suffix.slice(index + marker.length)
+}
+
// Old syncs may still use a stats table's pre-rename name — mirrors the backend
// fallback in factory.py.
const LEGACY_TABLE_NAME_FALLBACKS: Partial<Record<NativeMarketingSource, Record<string, string[]>>> = {
diff --git a/posthog/schema.py b/posthog/schema.py
index 42ee341b177b..82673e5bb98d 100644
--- a/posthog/schema.py
+++ b/posthog/schema.py
@@ -51,8 +51,6 @@ from posthog.schema_enums import (
BillingSpendResponseBreakdownType as BillingSpendResponseBreakdownType,
BillingUsageResponseBreakdownType as BillingUsageResponseBreakdownType,
BingAdsDefaultSources as BingAdsDefaultSources,
- BingAdsTableExclusions as BingAdsTableExclusions,
- BingAdsTableKeywords as BingAdsTableKeywords,
BounceRatePageViewMode as BounceRatePageViewMode,
BreakdownAttributionType as BreakdownAttributionType,
BreakdownType as BreakdownType,
@@ -122,8 +120,6 @@ from posthog.schema_enums import (
FunnelVizType as FunnelVizType,
Goal as Goal,
GoogleAdsDefaultSources as GoogleAdsDefaultSources,
- GoogleAdsTableExclusions as GoogleAdsTableExclusions,
- GoogleAdsTableKeywords as GoogleAdsTableKeywords,
GradientScaleMode as GradientScaleMode,
HeatmapSortOrder as HeatmapSortOrder,
HedgehogActorAccessoryOption as HedgehogActorAccessoryOption,
@@ -150,8 +146,6 @@ from posthog.schema_enums import (
LifecycleToggle as LifecycleToggle,
LimitContext as LimitContext,
LinkedinAdsDefaultSources as LinkedinAdsDefaultSources,
- LinkedinAdsTableExclusions as LinkedinAdsTableExclusions,
- LinkedinAdsTableKeywords as LinkedinAdsTableKeywords,
LogPropertyFilterType as LogPropertyFilterType,
LogSeverityLevel as LogSeverityLevel,
LogsOrderBy as LogsOrderBy,
@@ -178,8 +172,6 @@ from posthog.schema_enums import (
MetaAdsConversionOmniActionTypes as MetaAdsConversionOmniActionTypes,
MetaAdsConversionSpecificActionTypes as MetaAdsConversionSpecificActionTypes,
MetaAdsDefaultSources as MetaAdsDefaultSources,
- MetaAdsTableExclusions as MetaAdsTableExclusions,
- MetaAdsTableKeywords as MetaAdsTableKeywords,
Method as Method,
Metric as Metric,
MetricsAggregation as MetricsAggregation,
@@ -208,8 +200,6 @@ from posthog.schema_enums import (
PersonsJoinMode as PersonsJoinMode,
PersonsOnEventsMode as PersonsOnEventsMode,
PinterestAdsDefaultSources as PinterestAdsDefaultSources,
- PinterestAdsTableExclusions as PinterestAdsTableExclusions,
- PinterestAdsTableKeywords as PinterestAdsTableKeywords,
PlanningStepStatus as PlanningStepStatus,
Position as Position,
PrecomputationMode as PrecomputationMode,
@@ -227,8 +217,6 @@ from posthog.schema_enums import (
RecordingOrder as RecordingOrder,
RecordingOrderDirection as RecordingOrderDirection,
RedditAdsDefaultSources as RedditAdsDefaultSources,
- RedditAdsTableExclusions as RedditAdsTableExclusions,
- RedditAdsTableKeywords as RedditAdsTableKeywords,
RefreshType as RefreshType,
ReleaseStatus as ReleaseStatus,
ResultCustomizationBy as ResultCustomizationBy,
@@ -248,8 +236,6 @@ from posthog.schema_enums import (
SnapchatAdsConversionFields as SnapchatAdsConversionFields,
SnapchatAdsConversionValueFields as SnapchatAdsConversionValueFields,
SnapchatAdsDefaultSources as SnapchatAdsDefaultSources,
- SnapchatAdsTableExclusions as SnapchatAdsTableExclusions,
- SnapchatAdsTableKeywords as SnapchatAdsTableKeywords,
SnapshotSource as SnapshotSource,
SourceFieldInputConfigType as SourceFieldInputConfigType,
SourceFieldSelectConfigConverter as SourceFieldSelectConfigConverter,
@@ -276,8 +262,6 @@ from posthog.schema_enums import (
TextMatching as TextMatching,
Theme as Theme,
TikTokAdsDefaultSources as TikTokAdsDefaultSources,
- TikTokAdsTableExclusions as TikTokAdsTableExclusions,
- TikTokAdsTableKeywords as TikTokAdsTableKeywords,
TimeWindowMode as TimeWindowMode,
TraceOrderColumn as TraceOrderColumn,
TraceSpanBreakdownOrderBy as TraceSpanBreakdownOrderBy,
@@ -1807,8 +1791,6 @@ class MarketingIntegrationConfig1(BaseModel):
primarySource: Literal["google"] = "google"
sourceType: Literal["GoogleAds"] = "GoogleAds"
statsTableName: Literal["campaign_overview_stats"] = "campaign_overview_stats"
- tableExclusions: list[str] = Field(..., max_length=1, min_length=1)
- tableKeywords: list[str] = Field(..., max_length=1, min_length=1)
class MarketingIntegrationConfig2(BaseModel):
@@ -1826,8 +1808,6 @@ class MarketingIntegrationConfig2(BaseModel):
primarySource: Literal["linkedin"] = "linkedin"
sourceType: Literal["LinkedinAds"] = "LinkedinAds"
statsTableName: Literal["campaign_group_stats"] = "campaign_group_stats"
- tableExclusions: list[str] = Field(..., max_length=1, min_length=1)
- tableKeywords: list[str] = Field(..., max_length=1, min_length=1)
class ConversionActionTypes(BaseModel):
@@ -1855,8 +1835,6 @@ class MarketingIntegrationConfig3(BaseModel):
primarySource: Literal["meta"] = "meta"
sourceType: Literal["MetaAds"] = "MetaAds"
statsTableName: Literal["campaign_stats"] = "campaign_stats"
- tableExclusions: list[str] = Field(..., max_length=1, min_length=1)
- tableKeywords: list[str] = Field(..., max_length=1, min_length=1)
class MarketingIntegrationConfig4(BaseModel):
@@ -1874,8 +1852,6 @@ class MarketingIntegrationConfig4(BaseModel):
primarySource: Literal["tiktok"] = "tiktok"
sourceType: Literal["TikTokAds"] = "TikTokAds"
statsTableName: Literal["campaign_report"] = "campaign_report"
- tableExclusions: list[str] = Field(..., max_length=1, min_length=1)
- tableKeywords: list[str] = Field(..., max_length=1, min_length=1)
class MarketingIntegrationConfig5(BaseModel):
@@ -1893,8 +1869,6 @@ class MarketingIntegrationConfig5(BaseModel):
primarySource: Literal["reddit"] = "reddit"
sourceType: Literal["RedditAds"] = "RedditAds"
statsTableName: Literal["campaign_report"] = "campaign_report"
- tableExclusions: list[str] = Field(..., max_length=1, min_length=1)
- tableKeywords: list[str] = Field(..., max_length=1, min_length=1)
class MarketingIntegrationConfig6(BaseModel):
@@ -1912,8 +1886,6 @@ class MarketingIntegrationConfig6(BaseModel):
primarySource: Literal["bing"] = "bing"
sourceType: Literal["BingAds"] = "BingAds"
statsTableName: Literal["campaign_performance_report"] = "campaign_performance_report"
- tableExclusions: list[str] = Field(..., max_length=1, min_length=1)
- tableKeywords: list[str] = Field(..., max_length=1, min_length=1)
class MarketingIntegrationConfig7(BaseModel):
@@ -1933,8 +1905,6 @@ class MarketingIntegrationConfig7(BaseModel):
primarySource: Literal["snapchat"] = "snapchat"
sourceType: Literal["SnapchatAds"] = "SnapchatAds"
statsTableName: Literal["campaign_stats_daily"] = "campaign_stats_daily"
- tableExclusions: list[str] = Field(..., max_length=1, min_length=1)
- tableKeywords: list[str] = Field(..., max_length=1, min_length=1)
class MarketingIntegrationConfig8(BaseModel):
@@ -1952,8 +1922,6 @@ class MarketingIntegrationConfig8(BaseModel):
primarySource: Literal["pinterest"] = "pinterest"
sourceType: Literal["PinterestAds"] = "PinterestAds"
statsTableName: Literal["campaign_analytics"] = "campaign_analytics"
- tableExclusions: list[str] = Field(..., max_length=1, min_length=1)
- tableKeywords: list[str] = Field(..., max_length=1, min_length=1)
class MarketingIntegrationConfig(
@@ -5805,8 +5773,6 @@ class MarketingIntegrationConfigType(BaseModel):
primarySource: str
sourceType: NativeMarketingSource
statsTableName: str
- tableExclusions: list[str]
- tableKeywords: list[str]
class MatchedRecording(BaseModel):
diff --git a/posthog/schema_enums.py b/posthog/schema_enums.py
index 038f4e1a600a..533de3164c87 100644
--- a/posthog/schema_enums.py
+++ b/posthog/schema_enums.py
@@ -588,14 +588,6 @@ class BingAdsDefaultSources(StrEnum):
BING_VIDEO = "bing_video"
-class BingAdsTableExclusions(StrEnum):
- PERFORMANCE = "performance"
-
-
-class BingAdsTableKeywords(StrEnum):
- CAMPAIGNS = "campaigns"
-
-
class BreakdownAttributionType(StrEnum):
FIRST_TOUCH = "first_touch"
LAST_TOUCH = "last_touch"
@@ -2711,14 +2703,6 @@ class GoogleAdsDefaultSources(StrEnum):
WAZE = "waze"
-class GoogleAdsTableExclusions(StrEnum):
- STATS = "stats"
-
-
-class GoogleAdsTableKeywords(StrEnum):
- CAMPAIGN = "campaign"
-
-
class GradientScaleMode(StrEnum):
ABSOLUTE = "absolute"
RELATIVE = "relative"
@@ -2968,14 +2952,6 @@ class LinkedinAdsDefaultSources(StrEnum):
LI = "li"
-class LinkedinAdsTableExclusions(StrEnum):
- STATS = "stats"
-
-
-class LinkedinAdsTableKeywords(StrEnum):
- CAMPAIGN_GROUPS = "campaign_groups"
-
-
class MatchedOn(StrEnum):
KEY = "key"
VALUE = "value"
@@ -3158,14 +3134,6 @@ class MetaAdsDefaultSources(StrEnum):
THREADS = "threads"
-class MetaAdsTableExclusions(StrEnum):
- STATS = "stats"
-
-
-class MetaAdsTableKeywords(StrEnum):
- CAMPAIGNS = "campaigns"
-
-
class MetricsAggregation(StrEnum):
SUM = "sum"
AVG = "avg"
@@ -3387,14 +3355,6 @@ class PinterestAdsDefaultSources(StrEnum):
PINTEREST = "pinterest"
-class PinterestAdsTableExclusions(StrEnum):
- ANALYTICS = "analytics"
-
-
-class PinterestAdsTableKeywords(StrEnum):
- CAMPAIGNS = "campaigns"
-
-
class PlanningStepStatus(StrEnum):
PENDING = "pending"
IN_PROGRESS = "in_progress"
@@ -3722,14 +3682,6 @@ class RedditAdsDefaultSources(StrEnum):
REDDIT = "reddit"
-class RedditAdsTableExclusions(StrEnum):
- REPORT = "report"
-
-
-class RedditAdsTableKeywords(StrEnum):
- CAMPAIGNS = "campaigns"
-
-
class RefreshType(StrEnum):
ASYNC_ = "async"
ASYNC_EXCEPT_ON_CACHE_MISS = "async_except_on_cache_miss"
@@ -3846,14 +3798,6 @@ class SnapchatAdsDefaultSources(StrEnum):
SNAPCHAT = "snapchat"
-class SnapchatAdsTableExclusions(StrEnum):
- STATS_DAILY = "stats_daily"
-
-
-class SnapchatAdsTableKeywords(StrEnum):
- CAMPAIGNS = "campaigns"
-
-
class ReleaseStatus(StrEnum):
ALPHA = "alpha"
BETA = "beta"
@@ -4052,14 +3996,6 @@ class TikTokAdsDefaultSources(StrEnum):
TIKTOK = "tiktok"
-class TikTokAdsTableExclusions(StrEnum):
- REPORT = "report"
-
-
-class TikTokAdsTableKeywords(StrEnum):
- CAMPAIGNS = "campaigns"
-
-
class TraceOrderColumn(StrEnum):
TIMESTAMP = "timestamp"
DURATION = "duration"
diff --git a/products/marketing_analytics/backend/hogql_queries/adapters/factory.py b/products/marketing_analytics/backend/hogql_queries/adapters/factory.py
index 0ce3f5608850..7eb83333bef7 100644
--- a/products/marketing_analytics/backend/hogql_queries/adapters/factory.py
+++ b/products/marketing_analytics/backend/hogql_queries/adapters/factory.py
@@ -57,10 +57,14 @@ def _extract_schema_name(table_suffix: str, source_type: str) -> str:
Table names follow the format: {user_prefix}{source_type}_{schema_name}
Exclusions should only match against the schema part, not user prefixes.
For example: 'analytics_pinterestads_campaigns' -> 'campaigns'
+
+ The user prefix is free text, so it can contain the marker itself
+ ('googleads_googleads_campaign'). Take the last occurrence: no schema name
+ contains the marker, so the last one is always the real boundary.
"""
source_type_lower = source_type.lower()
marker = f"{source_type_lower}_"
- idx = table_suffix.find(marker)
+ idx = table_suffix.rfind(marker)
if idx != -1:
return table_suffix[idx + len(marker) :]
return table_suffix
@@ -255,14 +259,13 @@ class MarketingSourceFactory:
table_suffix = table.name.split(".")[-1].lower()
schema_name = _extract_schema_name(table_suffix, source.source_type)
- if any(kw in table_suffix for kw in patterns["campaign_table_keywords"]) and not any(
- ex in schema_name for ex in patterns["campaign_table_exclusions"]
- ):
+ # Exact schema-name match: a keyword match also claims unrelated schemas that
+ # merely contain it, such as Google Ads `campaign_budget`, which has none of
+ # the campaign columns the adapter goes on to reference.
+ if schema_name == patterns["campaign_table_name"]:
campaign_table = table
elif any(kw in table_suffix for kw in patterns["stats_table_keywords"]):
campaign_stats_table = table
- # Exact schema-name match (not keyword) so ad-group / ad tables don't
- # collide with the campaign keyword.
elif schema_name == hierarchy_names.get("adset_table"):
adset_table = table
if adset_unified:
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 320fe0faab14..b62d73031ca0 100644
--- a/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py
+++ b/products/marketing_analytics/backend/hogql_queries/adapters/test_factory.py
@@ -11,7 +11,7 @@ from parameterized import parameterized
from posthog.schema import DateRange, MarketingAnalyticsDrillDownLevel, NativeMarketingSource
from posthog.hogql_queries.utils.query_date_range import QueryDateRange
-from posthog.models.team.team import DEFAULT_CURRENCY
+from posthog.models.team.team import DEFAULT_CURRENCY, Team
from products.marketing_analytics.backend.hogql_queries.adapters.base import (
BingAdsConfig,
@@ -30,6 +30,20 @@ from products.marketing_analytics.backend.hogql_queries.adapters.meta_ads import
from products.warehouse_sources.backend.facade.models import DataWarehouseTable
+class FactoryTestMixin:
+ team: Team
+
+ def _make_factory(self) -> MarketingSourceFactory:
+ date_range = QueryDateRange(
+ date_range=DateRange(date_from="2024-01-01", date_to="2024-01-31"),
+ team=self.team,
+ interval=None,
+ now=datetime.now(),
+ )
+ context = QueryContext(date_range=date_range, team=self.team, base_currency=DEFAULT_CURRENCY)
+ return MarketingSourceFactory(context=context)
+
+
class TestMarketingSourceFactoryCustomSourceMappings(BaseTest):
"""Test suite for MarketingSourceFactory custom source mapping functionality"""
@@ -161,7 +175,7 @@ class TestMarketingSourceFactoryCustomSourceMappings(BaseTest):
assert "custom_source" not in str(mappings)
-class TestMetaAdsConfigDiscovery(BaseTest):
+class TestMetaAdsConfigDiscovery(FactoryTestMixin, BaseTest):
"""Test suite for native config discovery of optional ad-group / ad tables.
The factory must correctly populate `adset_table` / `adset_stats_table` /
@@ -179,16 +193,6 @@ class TestMetaAdsConfigDiscovery(BaseTest):
table.name = f"metaads_{schema_name}"
return cast(DataWarehouseTable, table)
- def _make_factory(self) -> MarketingSourceFactory:
- date_range = QueryDateRange(
- date_range=DateRange(date_from="2024-01-01", date_to="2024-01-31"),
- team=self.team,
- interval=None,
- now=datetime.now(),
- )
- context = QueryContext(date_range=date_range, team=self.team, base_currency=DEFAULT_CURRENCY)
- return MarketingSourceFactory(context=context)
-
def _make_source(self) -> Mock:
source = Mock()
source.id = "meta_source_id"
@@ -273,7 +277,7 @@ class TestMetaAdsConfigDiscovery(BaseTest):
assert self._create_meta_config(factory, tables_no_campaign) is None
-class TestNativeHierarchicalConfigDiscovery(BaseTest):
+class TestNativeHierarchicalConfigDiscovery(FactoryTestMixin, BaseTest):
"""Verifies `_create_native_config` populates adset/ad slots for every native source
that has a hierarchy entry. Without this, a working sync looks dead in the UI: the
factory loads a campaign-only config and `supports_level(AD_GROUP/AD)` returns False.
@@ -404,16 +408,6 @@ class TestNativeHierarchicalConfigDiscovery(BaseTest):
table.name = f"{prefix}_{schema_name}"
return cast(DataWarehouseTable, table)
- def _make_factory(self) -> MarketingSourceFactory:
- date_range = QueryDateRange(
- date_range=DateRange(date_from="2024-01-01", date_to="2024-01-31"),
- team=self.team,
- interval=None,
- now=datetime.now(),
- )
- context = QueryContext(date_range=date_range, team=self.team, base_currency=DEFAULT_CURRENCY)
- return MarketingSourceFactory(context=context)
-
def _make_source(self, source_type: str) -> Mock:
source = Mock()
source.id = f"{source_type}_source_id"
@@ -488,3 +482,68 @@ class TestNativeHierarchicalConfigDiscovery(BaseTest):
assert config.adset_table is config.adset_stats_table, (
f"{source_type}: unified mode should wire the same DataWarehouseTable into both adset slots"
)
+
+
+class TestNativeCampaignTableResolution(FactoryTestMixin, BaseTest):
+ def _make_source(self, prefix: str = "") -> Mock:
+ source = Mock()
+ source.id = "googleads_source_id"
+ source.source_type = "GoogleAds"
+ source.prefix = prefix
+ return source
+
+ def _make_table(self, schema_name: str, prefix: str = "") -> DataWarehouseTable:
+ table = Mock()
+ # Duplicates `build_table_name`, which warehouse_sources keeps out of its public
+ # interface — this format is what the factory parses back apart, so it has to match.
+ table.name = f"{prefix}googleads_{schema_name}".lower()
+ return cast(DataWarehouseTable, table)
+
+ def _create_config(self, tables: list[DataWarehouseTable]) -> GoogleAdsConfig | None:
+ return cast(
+ GoogleAdsConfig | None,
+ self._make_factory()._create_native_config(
+ self._make_source(), tables, NativeMarketingSource.GOOGLE_ADS, GoogleAdsConfig
+ ),
+ )
+
+ @parameterized.expand([("budget_last", False), ("budget_first", True)])
+ def test_campaign_budget_never_wins_the_campaign_slot(self, _name: str, reverse: bool):
+ """`campaign_budget` contains the `campaign` keyword but has no campaign columns,
+ so binding it made every marketing analytics query fail to resolve with
+ `Field not found: campaign_id`. It used to win whenever it came last, and the
+ queryset supplying these tables has no ordering.
+ """
+ campaign = self._make_table("campaign")
+ stats = self._make_table("campaign_overview_stats")
+ budget = self._make_table("campaign_budget")
+ tables = [campaign, stats, budget]
+
+ config = self._create_config(list(reversed(tables)) if reverse else tables)
+
+ assert config is not None
+ assert config.campaign_table is campaign
+ assert config.stats_table is stats
+
+ def test_campaign_budget_without_campaign_yields_no_config(self):
+ """The state already-affected projects are in: `campaign_budget` synced, `campaign`
+ not. Nothing can serve the campaign slot, so the source must be dropped rather
+ than wired up to a table that will fail to resolve at query time.
+ """
+ tables = [self._make_table("campaign_budget"), self._make_table("campaign_overview_stats")]
+
+ assert self._create_config(tables) is None
+
+ @parameterized.expand([("plain", "analytics_"), ("prefix_repeats_source_type", "googleads_")])
+ def test_user_prefix_is_stripped_before_matching(self, _name: str, prefix: str):
+ """The source prefix is free text, so it can repeat the source type. Exact matching
+ only works if the schema name survives prefix stripping in both cases.
+ """
+ campaign = self._make_table("campaign", prefix=prefix)
+ stats = self._make_table("campaign_overview_stats", prefix=prefix)
+
+ config = self._create_config([campaign, stats])
+
+ assert config is not None
+ assert config.campaign_table is campaign
+ assert config.stats_table is stats
diff --git a/products/marketing_analytics/backend/hogql_queries/constants.py b/products/marketing_analytics/backend/hogql_queries/constants.py
index d0380f04fcc2..9679cfedf4b5 100644
--- a/products/marketing_analytics/backend/hogql_queries/constants.py
+++ b/products/marketing_analytics/backend/hogql_queries/constants.py
@@ -7,16 +7,10 @@ from pydantic import BaseModel
from posthog.schema import (
BingAdsDefaultSources,
- BingAdsTableExclusions,
- BingAdsTableKeywords,
DefaultChannelTypes,
GoogleAdsDefaultSources,
- GoogleAdsTableExclusions,
- GoogleAdsTableKeywords,
InfinityValue,
LinkedinAdsDefaultSources,
- LinkedinAdsTableExclusions,
- LinkedinAdsTableKeywords,
MarketingAnalyticsBaseColumns,
MarketingAnalyticsColumnsSchemaNames,
MarketingAnalyticsConstants,
@@ -34,24 +28,14 @@ from posthog.schema import (
MetaAdsConversionOmniActionTypes,
MetaAdsConversionSpecificActionTypes,
MetaAdsDefaultSources,
- MetaAdsTableExclusions,
- MetaAdsTableKeywords,
NativeMarketingSource,
NodeKind,
PinterestAdsDefaultSources,
- PinterestAdsTableExclusions,
- PinterestAdsTableKeywords,
RedditAdsDefaultSources,
- RedditAdsTableExclusions,
- RedditAdsTableKeywords,
SnapchatAdsConversionFields,
SnapchatAdsConversionValueFields,
SnapchatAdsDefaultSources,
- SnapchatAdsTableExclusions,
- SnapchatAdsTableKeywords,
TikTokAdsDefaultSources,
- TikTokAdsTableExclusions,
- TikTokAdsTableKeywords,
WebAnalyticsItemKind,
)
@@ -539,28 +523,6 @@ _DEFAULT_SOURCES_ENUMS = {
NativeMarketingSource.PINTEREST_ADS: PinterestAdsDefaultSources,
}
-_TABLE_KEYWORDS_ENUMS = {
- NativeMarketingSource.GOOGLE_ADS: GoogleAdsTableKeywords,
- NativeMarketingSource.LINKEDIN_ADS: LinkedinAdsTableKeywords,
- NativeMarketingSource.META_ADS: MetaAdsTableKeywords,
- NativeMarketingSource.TIK_TOK_ADS: TikTokAdsTableKeywords,
- NativeMarketingSource.REDDIT_ADS: RedditAdsTableKeywords,
- NativeMarketingSource.BING_ADS: BingAdsTableKeywords,
- NativeMarketingSource.SNAPCHAT_ADS: SnapchatAdsTableKeywords,
- NativeMarketingSource.PINTEREST_ADS: PinterestAdsTableKeywords,
-}
-
-_TABLE_EXCLUSIONS_ENUMS = {
- NativeMarketingSource.GOOGLE_ADS: GoogleAdsTableExclusions,
- NativeMarketingSource.LINKEDIN_ADS: LinkedinAdsTableExclusions,
- NativeMarketingSource.META_ADS: MetaAdsTableExclusions,
- NativeMarketingSource.TIK_TOK_ADS: TikTokAdsTableExclusions,
- NativeMarketingSource.REDDIT_ADS: RedditAdsTableExclusions,
- NativeMarketingSource.BING_ADS: BingAdsTableExclusions,
- NativeMarketingSource.SNAPCHAT_ADS: SnapchatAdsTableExclusions,
- NativeMarketingSource.PINTEREST_ADS: PinterestAdsTableExclusions,
-}
-
# Derived constants from generated types
NEEDED_FIELDS_FOR_NATIVE_MARKETING_ANALYTICS = {
source: [
@@ -572,9 +534,8 @@ NEEDED_FIELDS_FOR_NATIVE_MARKETING_ANALYTICS = {
TABLE_PATTERNS = {
source: {
- "campaign_table_keywords": _get_enum_values(_TABLE_KEYWORDS_ENUMS[source]),
- "campaign_table_exclusions": _get_enum_values(_TABLE_EXCLUSIONS_ENUMS[source]),
"stats_table_keywords": [_get_field_default(config, "statsTableName")],
+ "campaign_table_name": _get_field_default(config, "campaignTableName"),
}
for source, config in _CONFIG_MODELS.items()
}
diff --git a/products/marketing_analytics/backend/hogql_queries/test_constants.py b/products/marketing_analytics/backend/hogql_queries/test_constants.py
index fe9ddd6a5cb1..24ee3c1ac9d5 100644
--- a/products/marketing_analytics/backend/hogql_queries/test_constants.py
+++ b/products/marketing_analytics/backend/hogql_queries/test_constants.py
@@ -5,8 +5,6 @@ from posthog.schema import NativeMarketingSource
from .constants import (
_CONFIG_MODELS,
_DEFAULT_SOURCES_ENUMS,
- _TABLE_EXCLUSIONS_ENUMS,
- _TABLE_KEYWORDS_ENUMS,
INTEGRATION_DEFAULT_SOURCES,
INTEGRATION_FIELD_NAMES,
INTEGRATION_PRIMARY_SOURCE,
@@ -28,18 +26,6 @@ class TestMarketingAnalyticsConstantsCoverage:
missing = all_sources - covered_sources
assert covered_sources == all_sources, f"Missing sources in _DEFAULT_SOURCES_ENUMS: {missing}"
- def test_table_keywords_enums_covers_all_sources(self):
- all_sources = set(NativeMarketingSource)
- covered_sources = set(_TABLE_KEYWORDS_ENUMS.keys())
- missing = all_sources - covered_sources
- assert covered_sources == all_sources, f"Missing sources in _TABLE_KEYWORDS_ENUMS: {missing}"
-
- def test_table_exclusions_enums_covers_all_sources(self):
- all_sources = set(NativeMarketingSource)
- covered_sources = set(_TABLE_EXCLUSIONS_ENUMS.keys())
- missing = all_sources - covered_sources
- assert covered_sources == all_sources, f"Missing sources in _TABLE_EXCLUSIONS_ENUMS: {missing}"
-
def test_integration_default_sources_covers_all_sources(self):
all_sources = set(NativeMarketingSource)
covered_sources = set(INTEGRATION_DEFAULT_SOURCES.keys())
@@ -109,11 +95,13 @@ class TestMarketingAnalyticsConstantsStructure:
@parameterized.expand([(source,) for source in NativeMarketingSource])
def test_table_patterns_has_required_keys(self, source):
patterns = TABLE_PATTERNS[source]
- required_keys = ["campaign_table_keywords", "campaign_table_exclusions", "stats_table_keywords"]
- for key in required_keys:
- assert key in patterns, f"{source}: missing '{key}'"
- assert isinstance(patterns[key], list), f"{source}: '{key}' should be a list"
- assert len(patterns[key]) > 0, f"{source}: '{key}' is empty"
+ stats_keywords = patterns["stats_table_keywords"]
+ assert isinstance(stats_keywords, list), f"{source}: 'stats_table_keywords' should be a list"
+ assert len(stats_keywords) > 0, f"{source}: 'stats_table_keywords' is empty"
+
+ campaign_table_name = patterns["campaign_table_name"]
+ assert isinstance(campaign_table_name, str), f"{source}: 'campaign_table_name' should be a string"
+ assert campaign_table_name, f"{source}: 'campaign_table_name' is empty"
class TestMarketingAnalyticsConstantsConsistency: