:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(marketing): add bing ads landing page metrics (#112780)
Javier Bahamondes9b69890efc7c
diff --git a/docs/internal/marketing-source-suggestions.md b/docs/internal/marketing-source-suggestions.mdindex fc19c730f7eb..5f65fb7f35b6 100644--- a/docs/internal/marketing-source-suggestions.md+++ b/docs/internal/marketing-source-suggestions.md@@ -36,3 +36,11 @@ Clicks include the engagement clicks reported by X, not only outbound link clickThe current import provides spend, clicks, and impressions; platform-reported conversions and revenue are not imported.PostHog conversion goals still work through campaign attribution.Ad-level reporting is unavailable because the connector does not import promoted-post statistics.++## Bing Ads landing pages++Search performance includes Bing Ads in the Landing pages view.+Enable `destination_url_performance_report` in the Bing Ads source settings and wait for its first successful sync.+The view groups search distribution metrics by destination URL and currency, with clicks, impressions, spend, and platform-attributed conversions.+The connector uses `ConversionsQualified` because Microsoft deprecated `Conversions` for this report.+Keyword reporting continues to use `keyword_performance_report`.diff --git a/frontend/snapshots.yml b/frontend/snapshots.ymlindex fc8734f19b44..251432b8ff55 100644--- a/frontend/snapshots.yml+++ b/frontend/snapshots.yml@@ -11967,9 +11967,9 @@ snapshots:scenes-app-marketing-analytics-search-performance--flag-off--light:hash: v1.k794b7964.9336af8fdbf0c10e0dadbdc398517b3856ad19eae7ff0f580ddd507e4202b57b.92lmvS4XqmLPpRq2h7e7R_7p8x2ZpdvIaIAKZRL4lQUscenes-app-marketing-analytics-search-performance--landing-pages--dark:- hash: v1.k794b7964.62ba6335df58e3073ae81e43aacbbd8fa1c77f7265c489e863f5e622358af4ea.FmrnlcNqxK5iLB3-xr613EDWIG4BcMBYFKUr98gTVvo+ hash: v1.k794b7964.74656d8364625a9f6b442baa2ad5507a244323919fb63d37dc2342a5a1bfdab5.wauw1gWSMZQPmDxATPiyd5Kw-cqdLg89C0CDPzEW9GAscenes-app-marketing-analytics-search-performance--landing-pages--light:- hash: v1.k794b7964.4deaf12c332971e15f972d0dec3fbd0c3e3343325a536e50dee92934d14f82ff.nigxzpdupH3jx2rXs9f2DD35x1rF8S_8f74GpuxF9Lg+ hash: v1.k794b7964.bc30f3c78c9a225f143ba3378e886536265d6c9c8916944b3f33de3a4482de73.PIXCck6pjUZmQlVCqW1WIErlkXU7E3W_JTl2IZnlnYcscenes-app-marketing-analytics-search-performance--legacy-scene--dark:hash: v1.k794b7964.bb37add7475d921f29b8d578a8a879f61054e69cac604bf6039c2a267ade6683.ng8ac4fpTBVCX8us-xZvC9a2gWYq61EblkjLr0Ov9yIscenes-app-marketing-analytics-search-performance--legacy-scene--light:diff --git a/products/marketing_analytics/backend/hogql_queries/marketing_search_query_runner.py b/products/marketing_analytics/backend/hogql_queries/marketing_search_query_runner.pyindex bcc124230507..b4560c3f39b3 100644--- a/products/marketing_analytics/backend/hogql_queries/marketing_search_query_runner.py+++ b/products/marketing_analytics/backend/hogql_queries/marketing_search_query_runner.py@@ -99,6 +99,22 @@ class MarketingAnalyticsSearchQueryRunner(AnalyticsQueryRunner[MarketingAnalytic""",placeholders=placeholders,)+ if self.query.breakdown == "page" and source.sourceType == "BingAds":+ return parse_select(+ """+ SELECT {period} AS period, NULL AS keyword, nullIf(destination_url, '') AS page,+ 'BingAds' AS platform, NULL AS matchType,+ nullIf(upper(currency_code), '') AS currency,+ sum(toFloat(clicks)) AS click_count, sum(toFloat(impressions)) AS impression_count,+ sum(toFloat(spend)) AS total_cost,+ sum(toFloat(conversions_qualified)) AS conversion_count, 0 AS position_total+ FROM {stats}+ WHERE toDate(time_period) >= toDate({date_from}) AND toDate(time_period) <= toDate({date_to})+ AND ad_distribution = 'Search'+ GROUP BY page, currency+ """,+ placeholders=placeholders,+ )if self.query.breakdown == "page":if source.sourceType != "GoogleAds":raise ValueError("Landing pages are supported by Google Ads and Google Search Console")diff --git a/products/marketing_analytics/backend/hogql_queries/test_marketing_search_query_runner.py b/products/marketing_analytics/backend/hogql_queries/test_marketing_search_query_runner.pyindex f419be22dd56..23da4a323910 100644--- a/products/marketing_analytics/backend/hogql_queries/test_marketing_search_query_runner.py+++ b/products/marketing_analytics/backend/hogql_queries/test_marketing_search_query_runner.py@@ -171,28 +171,50 @@ class TestMarketingAnalyticsSearchQueryRunner(ClickhouseTestMixin, BaseTest):assert previous_year.previous is not None and previous_year.previous.clicks == 8assert not any(row.keyword == "previous only" for row in year_compared)- def test_google_landing_pages_exclude_non_search_traffic_and_keep_currencies(self) -> None:- table = self._table(- "paid_landing_pages",- {- "segments_date": "Date",- "landing_page_view_unexpanded_final_url": "String",- "segments_ad_network_type": "String",- "customer_currency_code": "String",- "metrics_clicks": "Float64",- "metrics_impressions": "Float64",- "metrics_cost_micros": "Float64",- "metrics_conversions": "Float64",- },- "segments_date,landing_page_view_unexpanded_final_url,segments_ad_network_type,customer_currency_code,metrics_clicks,metrics_impressions,metrics_cost_micros,metrics_conversions\n"- "2023-01-10,https://example.com/a,SEARCH,USD,10,100,20000000,2\n"- "2023-01-11,https://example.com/a,SEARCH_PARTNERS,USD,5,50,10000000,0.5\n"- "2023-01-10,https://example.com/a,SEARCH,EUR,3,30,6000000,1\n"- "2023-01-10,https://example.com/a,CONTENT,USD,900,9000,90000000,90\n",- )+ @parameterized.expand([("GoogleAds",), ("BingAds",)])+ def test_landing_pages_exclude_non_search_traffic_and_keep_currencies(self, platform: str) -> None:+ if platform == "GoogleAds":+ table = self._table(+ "paid_landing_pages",+ {+ "segments_date": "Date",+ "landing_page_view_unexpanded_final_url": "String",+ "segments_ad_network_type": "String",+ "customer_currency_code": "String",+ "metrics_clicks": "Float64",+ "metrics_impressions": "Float64",+ "metrics_cost_micros": "Float64",+ "metrics_conversions": "Float64",+ },+ "segments_date,landing_page_view_unexpanded_final_url,segments_ad_network_type,customer_currency_code,metrics_clicks,metrics_impressions,metrics_cost_micros,metrics_conversions\n"+ "2023-01-10,https://example.com/a,SEARCH,USD,10,100,20000000,2\n"+ "2023-01-11,https://example.com/a,SEARCH_PARTNERS,USD,5,50,10000000,0.5\n"+ "2023-01-10,https://example.com/a,SEARCH,EUR,3,30,6000000,1\n"+ "2023-01-10,https://example.com/a,CONTENT,USD,900,9000,90000000,90\n",+ )+ else:+ table = self._table(+ "bing_landing_pages",+ {+ "time_period": "Date",+ "destination_url": "String",+ "ad_distribution": "String",+ "currency_code": "String",+ "clicks": "Float64",+ "impressions": "Float64",+ "spend": "Float64",+ "conversions_qualified": "Float64",+ },+ "time_period,destination_url,ad_distribution,currency_code,clicks,impressions,spend,conversions_qualified\n"+ "2023-01-10,https://example.com/a,Search,USD,10,100,20,2\n"+ "2023-01-11,https://example.com/a,Search,USD,5,50,10,0.5\n"+ "2023-01-10,https://example.com/a,Search,EUR,3,30,6,1\n"+ "2023-01-10,https://example.com/a,Audience,USD,900,9000,90,90\n"+ "2022-01-10,https://example.com/a,Search,USD,900,9000,90,90\n",+ )query = MarketingAnalyticsSearchQuery(breakdown="page",- sources=[MarketingAnalyticsSearchSource(sourceType="GoogleAds", statsTable=table)],+ sources=[MarketingAnalyticsSearchSource(sourceType=platform, statsTable=table)],dateRange=DateRange(date_from="2023-01-01", date_to="2023-01-31"),)rows = MarketingAnalyticsSearchQueryRunner(query=query, team=self.team, user=self.user).calculate().resultsdiff --git a/products/marketing_analytics/frontend/search/SearchPerformanceTab.stories.tsx b/products/marketing_analytics/frontend/search/SearchPerformanceTab.stories.tsxindex eb95ef182eeb..988960796386 100644--- a/products/marketing_analytics/frontend/search/SearchPerformanceTab.stories.tsx+++ b/products/marketing_analytics/frontend/search/SearchPerformanceTab.stories.tsx@@ -46,7 +46,12 @@ const SOURCES = [description: 'Example Bing Ads',prefix: 'example',status: 'Completed',- schemas: ['campaigns', 'campaign_performance_report', 'keyword_performance_report'].map((name) => ({+ schemas: [+ 'campaigns',+ 'campaign_performance_report',+ 'keyword_performance_report',+ 'destination_url_performance_report',+ ].map((name) => ({id: `example-bing-${name}`,name,should_sync: true,@@ -184,7 +189,7 @@ const MOCKS: Mocks = {200,{results: (query.breakdown === 'page'- ? ROWS.filter((row) => row.platform !== 'BingAds' && row.clicks > 0).map((row) => ({+ ? ROWS.filter((row) => row.clicks > 0).map((row) => ({...row,page: `https://example.com/${row.keyword?.replaceAll(' ', '-')}`,keyword: null,diff --git a/products/marketing_analytics/frontend/search/SearchPerformanceTab.tsx b/products/marketing_analytics/frontend/search/SearchPerformanceTab.tsxindex 223f20ff6a13..049a26071aea 100644--- a/products/marketing_analytics/frontend/search/SearchPerformanceTab.tsx+++ b/products/marketing_analytics/frontend/search/SearchPerformanceTab.tsx@@ -36,7 +36,6 @@ export function SearchPerformanceTab(): JSX.Element {breakdown,channel,hasActiveFilters,- hasSelectedBingSource,} = useValues(searchPerformanceLogic)const { loadSources, setMetrics, setSearch, setBreakdown, setChannel, selectRow, setShowPosition, clearFilters } =useActions(searchPerformanceLogic)@@ -80,12 +79,6 @@ export function SearchPerformanceTab(): JSX.Element {) : (<>{!hasActiveFilters && <SearchSourceSuggestions />}- {breakdown === 'page' && channel !== 'organic' && hasSelectedBingSource && (- <LemonBanner type="info">- Bing Ads landing page metrics are not available in this view. Its keyword metrics are- available under Keywords and queries.- </LemonBanner>- )}{sourceNotices.map(({ sourceId, message }) => (<LemonBannerkey={sourceId}diff --git a/products/marketing_analytics/frontend/search/searchPerformance.test.ts b/products/marketing_analytics/frontend/search/searchPerformance.test.tsindex ac0d8346b15b..45b04e42c120 100644--- a/products/marketing_analytics/frontend/search/searchPerformance.test.ts+++ b/products/marketing_analytics/frontend/search/searchPerformance.test.ts@@ -57,6 +57,13 @@ describe('search performance sources', () => {it.each([['GoogleAds', ['landing_page_stats'], 'page', false, 'example.landing_page_stats'],['BingAds', ['keyword_performance_report'], 'page', false, undefined],+ [+ 'BingAds',+ ['destination_url_performance_report'],+ 'page',+ false,+ 'example.destination_url_performance_report',+ ],['GoogleSearchConsole',['search_analytics_by_page', 'search_analytics_by_query_page'],diff --git a/products/marketing_analytics/frontend/search/searchPerformance.ts b/products/marketing_analytics/frontend/search/searchPerformance.tsindex 2ca7525a2b79..fc4a7f2f9cba 100644--- a/products/marketing_analytics/frontend/search/searchPerformance.ts+++ b/products/marketing_analytics/frontend/search/searchPerformance.ts@@ -58,7 +58,9 @@ function searchTableNames(source: ExternalDataSource, breakdown: SearchBreakdownif (source.source_type === 'GoogleAds') {return breakdown === 'page' ? ['landing_page_stats'] : ['keyword', 'keyword_stats']}- return source.source_type === 'BingAds' && breakdown === 'keyword' ? ['keyword_performance_report'] : []+ return source.source_type === 'BingAds'+ ? [breakdown === 'page' ? 'destination_url_performance_report' : 'keyword_performance_report']+ : []}export function searchPerformanceSource(diff --git a/products/marketing_analytics/frontend/search/searchPerformanceLogic.ts b/products/marketing_analytics/frontend/search/searchPerformanceLogic.tsindex 29ecb2b2686a..2aaa02137259 100644--- a/products/marketing_analytics/frontend/search/searchPerformanceLogic.ts+++ b/products/marketing_analytics/frontend/search/searchPerformanceLogic.ts@@ -41,7 +41,6 @@ export interface searchPerformanceLogicValues extends Pick<missingSources: SearchPlatform[]hasActiveFilters: booleanhasSearchConsole: boolean- hasSelectedBingSource: booleansearch: stringquerySearch: stringsourcesError: boolean@@ -138,23 +137,13 @@ export const searchPerformanceLogic = kea<searchPerformanceLogicType>([(sources: ExternalDataSource[]): boolean =>sources.some((source) => source.source_type === 'GoogleSearchConsole'),],- hasSelectedBingSource: [- (s) => [s.allSearchSources, s.integrationFilter],- (sources: ExternalDataSource[], integrationFilter): boolean =>- selectedSearchSources(sources, integrationFilter.integrationSourceIds ?? []).some(- (source) => source.source_type === 'BingAds'- ),- ],sources: [- (s) => [s.allSearchSources, s.integrationFilter, s.channel, s.breakdown],- (allSources, integrationFilter, channel, breakdown): ExternalDataSource[] =>+ (s) => [s.allSearchSources, s.integrationFilter, s.channel],+ (allSources, integrationFilter, channel): ExternalDataSource[] =>selectedSearchSources(allSources, integrationFilter.integrationSourceIds ?? []).filter((source) =>- (channel === 'all' ||- (source.source_type === 'GoogleSearchConsole'- ? channel === 'organic'- : channel === 'paid')) &&- (breakdown !== 'page' || source.source_type !== 'BingAds')+ channel === 'all' ||+ (source.source_type === 'GoogleSearchConsole' ? channel === 'organic' : channel === 'paid')),],sourceNotices: [diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/canonical_descriptions.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/canonical_descriptions.pyindex 8ccc6a6556b4..cea24158e37a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/canonical_descriptions.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/canonical_descriptions.py@@ -34,6 +34,22 @@ _REPORT_METRICS = {CANONICAL_DESCRIPTIONS: CanonicalDescriptions = {+ "destination_url_performance_report": {+ "description": "Daily landing page performance by destination URL and ad.",+ "docs_url": "https://learn.microsoft.com/en-us/advertising/reporting-service/destinationurlperformancereportrequest",+ "columns": {+ **{+ key: value+ for key, value in _REPORT_METRICS.items()+ if key in {"time_period", "currency_code", "clicks", "impressions", "spend"}+ },+ "account_id": "Identifier of the Microsoft Advertising account.",+ "ad_id": "Identifier of the ad.",+ "destination_url": "Destination URL after dynamic text substitution.",+ "ad_distribution": "Distribution channel for the ad, such as Search or Audience.",+ "conversions_qualified": "Conversions attributed to the ad, including fractional conversions.",+ },+ },"campaigns": {"description": "A Microsoft Advertising campaign — a container for ad groups, budget, and targeting settings.","docs_url": "https://learn.microsoft.com/en-us/advertising/campaign-management-service/campaign",diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/schemas.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/schemas.pyindex 712817c85c4a..7e03ca13ac0a 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/schemas.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/schemas.py@@ -8,10 +8,18 @@ class BingAdsResource(str, Enum):CAMPAIGN_PERFORMANCE_REPORT = "campaign_performance_report"AD_GROUP_PERFORMANCE_REPORT = "ad_group_performance_report"AD_PERFORMANCE_REPORT = "ad_performance_report"+ DESTINATION_URL_PERFORMANCE_REPORT = "destination_url_performance_report"KEYWORD_PERFORMANCE_REPORT = "keyword_performance_report"REPORT_CONFIG: dict[BingAdsResource, dict] = {+ BingAdsResource.DESTINATION_URL_PERFORMANCE_REPORT: {+ "report_type": "DestinationUrlPerformanceReportRequest",+ "column_array_type": "ArrayOfDestinationUrlPerformanceReportColumn",+ "column_field": "DestinationUrlPerformanceReportColumn",+ "scope_type": "AccountThroughAdGroupReportScope",+ "report_name": "Destination URL Performance Report",+ },BingAdsResource.CAMPAIGN_PERFORMANCE_REPORT: {"report_type": "CampaignPerformanceReportRequest","column_array_type": "ArrayOfCampaignPerformanceReportColumn",@@ -44,6 +52,28 @@ REPORT_CONFIG: dict[BingAdsResource, dict] = {RESOURCE_SCHEMAS: dict[BingAdsResource, dict] = {+ BingAdsResource.DESTINATION_URL_PERFORMANCE_REPORT: {+ "resource_name": "destination_url_performance_report",+ "primary_key": ["AccountId", "AdId", "DestinationUrl", "CurrencyCode", "AdDistribution", "TimePeriod"],+ "field_names": [+ "AccountId",+ "AdId",+ "DestinationUrl",+ "CurrencyCode",+ "AdDistribution",+ "TimePeriod",+ "Clicks",+ "Impressions",+ "Spend",+ "ConversionsQualified",+ ],+ "partition_keys": ["TimePeriod"],+ "partition_mode": "datetime",+ "partition_format": "month",+ "is_stats": True,+ "partition_size": 1,+ "filter_field_names": [("TimePeriod", IncrementalFieldType.Date)],+ },BingAdsResource.CAMPAIGNS: {"resource_name": "campaigns","primary_key": ["Id"],diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.pyindex ae3c780dcdfe..f01df8e77ac1 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/source.py@@ -35,8 +35,19 @@ from products.warehouse_sources.backend.types import ExternalDataSourceTypefrom .bing_ads import bing_ads_source, get_incremental_fields, get_schemasfrom .client import BingAdsClient+from .schemas import BingAdsResourcefrom .utils import BingAdsResumeConfig+# Default incremental overlap re-read windows, keyed by schema name. The report request sets+# ReturnOnlyCompleteData = False, so the newest days arrive before Microsoft finishes processing them,+# and Microsoft attributes later conversions to the date of the click. An incremental sync that starts+# at the newest imported day freezes each earlier day at its first-imported value. Re-reading a trailing+# window lets those days catch up, and merge-by-primary-key makes the overlap idempotent. The window+# matches the Google Ads stats tables, and users can change it per schema.+BING_ADS_INCREMENTAL_LOOKBACK_SECONDS: dict[str, int] = {+ BingAdsResource.DESTINATION_URL_PERFORMANCE_REPORT.value: 15 * 24 * 60 * 60,+}+@SourceRegistry.registerclass BingAdsSource(ResumableSource[BingAdsSourceConfig, BingAdsResumeConfig], OAuthMixin):@@ -312,6 +323,7 @@ class BingAdsSource(ResumableSource[BingAdsSourceConfig, BingAdsResumeConfig], O{"label": column_name, "type": column_type, "field": column_name, "field_type": column_type}for column_name, column_type in ads_incremental_fields.get(endpoint, [])],+ default_incremental_lookback_seconds=BING_ADS_INCREMENTAL_LOOKBACK_SECONDS.get(endpoint),)for endpoint in bing_ads_schemas.keys()]diff --git a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.pyindex e92529e8a299..10a61f629903 100644--- a/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py+++ b/products/warehouse_sources/backend/temporal/data_imports/sources/bing_ads/tests/test_bing_ads_source.py@@ -101,6 +101,9 @@ class TestBingAdsSource:assert report_schema.incremental_fields[0]["field"] == "TimePeriod"assert report_schema.incremental_fields[0]["field_type"] == IncrementalFieldType.Date+ destination_url_schema = next(s for s in schemas if s.name == "destination_url_performance_report")+ assert destination_url_schema.default_incremental_lookback_seconds == 15 * 24 * 60 * 60+@mock.patch("products.warehouse_sources.backend.temporal.data_imports.sources.bing_ads.source.bing_ads_source")@mock.patch.object(BingAdsSource, "get_oauth_integration")def test_source_for_pipeline_campaigns(self, mock_get_oauth, mock_bing_ads_source):