Add geo and publisher breakdown reports to the advertiser API - #1237
Draft
ericholscher wants to merge 6 commits into
Draft
Add geo and publisher breakdown reports to the advertiser API#1237ericholscher wants to merge 6 commits into
ericholscher wants to merge 6 commits into
Conversation
Add geo, publisher, and keyword breakdown report endpoints to the
advertiser API to match the granular reports already available to
advertisers in the dashboard.
New endpoints on the advertiser API:
* /api/v1/advertisers/{slug}/geo_report/ - performance by country
* /api/v1/advertisers/{slug}/publisher_report/ - performance by publisher
* /api/v1/advertisers/{slug}/keyword_report/ - performance by keyword
These reuse the existing AdvertiserGeoReport and AdvertiserPublisherReport
classes and add a new AdvertiserKeywordReport. All endpoints honor the same
advertiser access scoping and start_date/end_date filtering as the existing
report endpoint.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01A75FWNN8ep1FfSP76811cS
Drop the new AdvertiserKeywordReport class and the keyword_report endpoint so the breakdown API only relies on existing report infrastructure. The geo and publisher endpoints reuse the existing AdvertiserGeoReport and AdvertiserPublisherReport classes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A75FWNN8ep1FfSP76811cS
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A75FWNN8ep1FfSP76811cS
Mirror the BaseReportView.fieldnames convention used by the dashboard CSV exports instead of hand-rolling per-dimension serialization. Breakdown rows are now projected through a shared report_fields list and labeled by the generic "index" field, dropping the Publisher special-case. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A75FWNN8ep1FfSP76811cS
Add BaseReport.serialize(fields) which projects results/total onto a column list as JSON-serializable rows. Both the advertiser breakdown API and the dashboard CSV exports now use it, removing the duplicated projection logic and the API-specific row serializer. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A75FWNN8ep1FfSP76811cS
Collaborator
|
This looks pretty good. Happy these are relatively easy to add! |
This reverts commit b46a638.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
HS: Had an advertiser ask for MCP access on a call, and I mentioned we could give reports via the API. I looked into the API reporting, and it's pretty minimal, so had the AI throw together a quick port of the existing easy reports to port over.
Summary
Advertisers can already see geo and publisher breakdowns of their ad performance in the dashboard, but the API only exposed the daily/flight/ad report. This adds two new read-only endpoints to the advertiser API so advertisers can pull that same granular data programmatically.
New endpoints on
AdvertiserViewSet:GET /api/v1/advertisers/{slug}/geo_report/AdvertiserGeoReportGET /api/v1/advertisers/{slug}/publisher_report/AdvertiserPublisherReportEach returns
{ "total": {...}, "results": [...] }withviews,clicks,cost,ctr, andecpmper row. The publisher report emits a machine-readablepublisherslug plus apublisher_name.Implementation notes
AdvertiserGeoReportandAdvertiserPublisherReport._breakdown_reporthelper that builds the advertiser-scoped queryset, runs the report, and serializes rows into JSON-safe dicts (the report's internal index can be aPublishermodel instance, which isn't directly serializable).start_date/end_dateparsing out of the existingreportaction into a_date_rangehelper, now shared by all three report actions.start_date/end_datefiltering as the existingreportendpoint.AdvertiserViewSetdocstring (autoclass), so the new endpoints are documented there.Not included
Keyword, topic, and domain breakdowns are rendered from Metabase in the dashboard rather than from these report classes, so they're out of scope here. Keyword in particular has no advertiser-appropriate report class to reuse (the existing
PublisherKeywordReportcomputes publisher revenue, not advertiser cost), so it would require new code.Testing
test_advertiser_geo_report,test_advertiser_publisher_report, plus access-control coverage for both endpoints.adserver.tests.test_apiandadserver.tests.test_reportssuites pass;ruff check/ruff formatclean.🤖 Generated with Claude Code
https://claude.ai/code/session_01A75FWNN8ep1FfSP76811cS
Generated by Claude Code