Support per-section GAM ad unit paths via gam_unit_path templates#957
Open
prk-Jr wants to merge 8 commits into
Open
Support per-section GAM ad unit paths via gam_unit_path templates#957prk-Jr wants to merge 8 commits into
prk-Jr wants to merge 8 commits into
Conversation
prk-Jr
requested review from
ChristianPavilonis and
aram356
and removed request for
aram356
July 23, 2026 16:25
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.
Summary
creative_opportunities.slot.gam_unit_pathis now a template with{network_id},{section}, and{slot_id}placeholders, so a publisher whose GAM ad unit varies by site section expresses that in one slot rule instead of one rule per (slot × section).{section}is derived from the request path (first segment, sanitized), with a requiredsection_rootfor/— the URL→section convention lives in config, not core.gam_unit_pathreachesgoogletag.defineSlotclient-side but is not in the OpenRTB request, so the wire shape is unchanged and there is no JS change.Changes
crates/trusted-server-core/src/creative_opportunities.rsUnitTemplatePart,parse_unit_template,sanitize_section,derive_section; slotcompiled_unitcache +compile_unit_template/render_gam_unit_path/template_uses_section; configsection_root+compile_unit_templates;validate_runtimenow enforcessection_rootwhen{section}is used and drops the render-time emptiness checkcrates/trusted-server-core/src/publisher.rsbuild_slot_json/build_ad_slots_scripttakerequest_path; render the template on both the initial-render andhandle_page_bids(SPA) pathscrates/trusted-server-core/src/settings.rsprepare_runtimeparses templates viacompile_unit_templatesbefore validation, surfacing parse errors asConfigurationerrorsdocs/guide/configuration.md{section}derivation, the no-decode rule, and unmatched-route behaviortrusted-server.example.tomlsection_rootand a templated-slot exampledocs/superpowers/specs/,docs/superpowers/plans/Closes
Closes #954
Test plan
cargo test-fastly && cargo test-axum(alsotest-cloudflare,test-spin— all pass)cargo fmt --all -- --checkcargo clippy-fastly(remaining clippy targets left to CI)cd docs && npm run formatclippy-axum/clippy-cloudflare*/clippy-spin*— left to CINew tests: template parsing (unknown placeholder, unmatched/nested brace, empty), section derivation (
/, single/multi-segment, unsafe/undecoded segmentnew%20s→new_20s),render_gam_unit_path(template, default, verbatim), startup validation (missing/invalidsection_root, parse error), and initial-render/SPA equivalence for the same path.Hardening note
Template parsing and
section_rootvalidation are config-derived and run at startup inSettings::prepare_runtime. Invalid enabled config fails startup viaReport<TrustedServerError::Configuration>— nopanic!,unwrap(), orexpect()on the config path.compile_unit_templatesrejects malformed templates (unknown placeholder, unmatched/nested brace, empty);validate_runtimerejects a{section}template with a missing or non-[A-Za-z0-9_-]section_root. Regression coverage:compile_unit_templates_surfaces_parse_error,validate_runtime_requires_section_root_when_template_uses_section,validate_runtime_rejects_invalid_section_root, andsettings_rejects_creative_opportunity_slot_with_empty_gam_unit_path. Existing staticgam_unit_pathconfigs are unaffected (verbatim when no placeholders;/{network_id}/{slot_id}when absent).Checklist
unwrap()in production code — useexpect("should ...")logmacros (notprintln!)