Skip to content

Add complete OpenRTB 2.6 data model crate#390

Draft
ChristianPavilonis wants to merge 5 commits intomainfrom
feature/openrtb-full-implementation
Draft

Add complete OpenRTB 2.6 data model crate#390
ChristianPavilonis wants to merge 5 commits intomainfrom
feature/openrtb-full-implementation

Conversation

@ChristianPavilonis
Copy link
Collaborator

@ChristianPavilonis ChristianPavilonis commented Mar 2, 2026

Summary

  • Introduces a new trusted-server-openrtb crate containing a complete OpenRTB 2.6 data model (all request/response objects with every field from the spec) to replace the minimal hand-rolled structs in crates/common/src/openrtb.rs.
  • Refactors crates/common to use the new crate's types via builder functions, keeping call sites clean while gaining full spec coverage (video, audio, native, DOOH, supply chain, EIDs, pod bidding, etc.).
  • Populates previously-unmapped OpenRTB fields from data already available in the auction request/context, improving bid quality and compliance.
  • Adds an openrtb.md reference document covering the full OpenRTB 2.6 schema for contributor use.

OpenRTB Field Enrichment

The Prebid integration now maps the following fields that were previously left empty despite data being available:

OpenRTB Field Source Impact
Imp.bidfloor / bidfloorcur AdSlot.floor_price Floor-price-aware bidders can now respect publisher floors
Imp.secure Hardcoded 1 Ensures HTTPS-only creatives
Imp.tagid slot.id Gives bidders a stable slot identifier
Geo.lat / lon GeoInfo.latitude / longitude Improves geo-targeted demand
Geo.metro GeoInfo.metro_code (DMA) Critical for US-targeted campaigns
User.consent UserInfo.consent (TCF string) GDPR compliance — consent string now forwarded
Regs.gdpr Set to 1 when consent present GDPR compliance flag
Regs.us_privacy Sec-GPC header → "1YYN" Promoted from ext to first-class field
Device.dnt DNT: 1 header Do Not Track signal forwarded to bidders
Device.language Accept-Language header Language targeting for bidders
Site.ref Referer header Referrer URL in OpenRTB (not just HTTP header)
Site.publisher Publisher domain Canonical publisher object for bidders
BidRequest.tmax config.timeout_ms PBS can manage internal auction deadlines
BidRequest.cur ["USD"] Explicit currency preference

Changes

File Change
crates/openrtb/Cargo.toml New crate manifest for trusted-server-openrtb with serde + serde_json deps
crates/openrtb/src/lib.rs Complete OpenRTB 2.6 data model: BidRequest, BidResponse, Imp, Banner, Video, Audio, Native, Site, App, Dooh, Device, User, Geo, Regs, SeatBid, Bid, Source, SupplyChain, Pmp, Deal, Publisher, Content, Producer, Network, Channel, EID, UserAgent, Qty, Refresh, DurFloors, and more
Cargo.toml Add crates/openrtb to workspace members
crates/common/Cargo.toml Add trusted-server-openrtb dependency
crates/common/src/openrtb.rs Replace hand-rolled structs with type aliases to new crate. Builder functions enhanced with new params (OpenRtbRequestParams struct, build_publisher, lat/lon/metro on geo, bidfloor/secure/tagid on imp, consent on user, gdpr/us_privacy on regs, dnt/language on device, ref/publisher on site, tmax/cur on request)
crates/common/src/auction/formats.rs Update bid/response construction to use new builder functions
crates/common/src/integrations/prebid.rs Map all new OpenRTB fields from available auction data. Extract DNT, Accept-Language, Referer headers. Forward GDPR consent and floor prices. Fix pre-existing test compilation errors for ext field access
openrtb.md New reference doc: complete OpenRTB 2.6 schema cheat-sheet

Closes

Closes #386

Test plan

  • cargo test --workspace (467 tests pass)
  • cargo clippy --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check
  • JS tests: cd crates/js/lib && npx vitest run
  • JS format: cd crates/js/lib && npm run format
  • Docs format: cd docs && npm run format
  • WASM build: cargo build --bin trusted-server-fastly --release --target wasm32-wasip1
  • Manual testing via fastly compute serve

Checklist

  • Changes follow CLAUDE.md conventions
  • No unwrap() in production code — uses expect("should ...") where needed
  • Uses tracing macros (not println!)
  • New code has tests
  • No secrets or credentials committed

@ChristianPavilonis ChristianPavilonis linked an issue Mar 2, 2026 that may be closed by this pull request
@ChristianPavilonis ChristianPavilonis changed the title DRAFT: OpenRTB full implementation Add complete OpenRTB 2.6 data model crate Mar 3, 2026
@ChristianPavilonis ChristianPavilonis force-pushed the feature/openrtb-full-implementation branch from f2eee35 to 0c0e4fa Compare March 3, 2026 16:01
Enrich outgoing Prebid Server requests with fields that were already
available in the AuctionRequest/context but not being mapped:

- Imp: bidfloor/bidfloorcur (from AdSlot.floor_price), secure (1),
  tagid (slot id)
- Geo: lat/lon (from GeoInfo), metro (DMA code)
- User: consent (TCF consent string from UserInfo)
- Regs: gdpr flag (when consent present), us_privacy promoted to
  first-class field
- Device: dnt (from DNT header), language (from Accept-Language)
- Site: ref (from Referer header), publisher object with domain
- BidRequest: tmax (from config timeout_ms), cur (["USD"])

Also refactor build_openrtb_request to use a params struct to satisfy
clippy argument limits, and fix pre-existing test compilation errors
where ext fields were accessed with struct syntax instead of Map::get.
- Validate Sec-GPC header value is '1' (not just presence)
- Add comment documenting GDPR flag trade-off (conservative approach)
- Add comment about hardcoded USD currency
- Remove dead RegsExt struct (us_privacy promoted to first-class field)
- Remove unnecessary language.clone()
- Add 13 tests covering all new OpenRTB field mappings: bidfloor,
  secure, tagid, consent/gdpr, Sec-GPC, DNT, language, geo lat/lon/
  metro, tmax, cur, site.ref, site.publisher
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Complete OpenRTB implementation

1 participant