Rewrite served markup with Content replacement
Per-placement find-and-replace pairs applied to every ad markup the placement serves — swap a domain, inject a publisher token, strip a fragment or remove a macro from third-party creatives on one slot — step by step, with exactly how serving applies the rules, the caveats, a fix-it checklist and the REST calls.
What it is and why
Content replacement is a per-placement find-and-replace: you define pairs of target → replacement strings, and the ad server rewrites every occurrence of each target in the ad markup it returns for this placement, whatever creative wins. Use it to patch third-party creative code for one specific slot — swap a domain, inject a publisher-specific token, or strip a fragment you do not want on that page — without touching the creatives themselves.
Example. A publisher’s Sports Daily site serves its pages over cdn.sportsdaily.example
and an agency’s creatives hard-code http://static.agency.example in their image URLs, which
the page’s HTTPS policy blocks. One rule on the placement — target
http://static.agency.example, replacement https://static.agency.example — fixes every
creative served there, and the agency’s code stays as delivered.
Typical scenarios
| You want | Target | Replacement |
|---|---|---|
| Upgrade an HTTP asset host every creative from one agency uses | http://static.agency.example | https://static.agency.example |
| Stamp the publisher’s own tracking token into a tag’s query string | pubid=PLACEHOLDER | pubid=sd-4471 |
| Remove a tracking pixel a publisher does not allow on its pages | the pixel’s <img …> tag, copied verbatim from the served markup | (blank — the target is deleted) |
| Stop a macro from resolving in creatives served on this slot | $$SOMETHING$$ | (blank) |
| Put a per-request value into the markup that the creative has no macro for | data-txid="" | data-txid="$$TRANSACTION_ID$$" — macros in a replacement resolve afterwards |
Step by step
-
Open the placement (Account → Publishers → site → zone → placement) and scroll to the Content replacement card (it is also listed in the feature rail). The card appears only after the placement’s first save, on every placement type.
-
Turn the card’s switch on. Rules are applied to live traffic only while the switch is on; rows you add stay saved either way.
-
In the add bar, enter the Target (the exact string to find — required) and the Replacement (what to put in its place — may be left blank), then click Add.

-
Repeat for each pair. Existing rows are edited inline — click a cell, change the text and commit; each edit saves immediately.
-
To remove rules, tick their rows and click Delete (asks for confirmation).
There is no page-level Save for this card — add, inline edit, delete and the on/off switch each persist on the spot. The ad server picks the change up on its next cache reload, not on the next request: allow a couple of minutes before judging a rule.
Caveats and exceptions
Who can do this. Publishers and network managers who need to post-process creatives on a specific placement. The card is not part of either stock role: it appears once your network administrator switches Placement Content Replacement on for the role, and then behaves the same for both. Changing anything also needs update rights on the parent site, as its owner or through an editable share. A Can View or masked share sees the rules but the switch is locked and there is no add bar or delete. Exact grants: User roles.
How serving applies the rules. Rules run on every ad response of this placement,
whatever creative wins, as part of the markup-processing pipeline. Matching is literal and
case-sensitive — no wildcards, no regex: Example.com does not match example.com. All
occurrences of a target are replaced, not just the first. A replacement that happens to
contain its own target again is not re-processed — the scanner moves past inserted text, so
rules cannot loop.
Rules run before macros are expanded. Two practical consequences: a replacement value may
contain macros ($$RANDOM$$, $$TRANSACTION_ID$$, …) — they
resolve normally afterwards; and a target may be a macro token: replacing $$SOMETHING$$ with
an empty string removes that macro from the creative before it ever resolves.
Changes are not instant on live traffic. The ad server works from an in-memory snapshot that is reloaded periodically, so a new rule (or the switch flip) takes effect on the next cache reload. The switch’s off state unloads the rules entirely — the ad server does not even load rows of a disabled card; toggling back on restores them on the following cache reload.
The target is exact, and it is not trimmed. If your target contains quotes or whitespace, copy it verbatim from the served markup (view the tag’s response source), not from a prettified view — one changed quote character and nothing matches, with no error anywhere. The Replacement value, on the other hand, is trimmed when the ad server loads it — leading and trailing whitespace you typed is gone from what gets served — while a Target with a trailing space matches only markup that has one.
One target per placement, checked without regard to case. To change what an existing target
produces, edit its Replacement cell inline instead of adding a second row with the same target —
the add is rejected with a Wrong values error. The uniqueness check is case-insensitive
even though matching is case-sensitive: Example.com and example.com cannot both be targets of
one placement, although serving would treat them as different strings.
Not working?
A rule is in the grid and the served markup is unchanged. Check in this order:
- The switch is off. Where: the card header — with it off the ad server does not load the rows at all.
- The cache has not reloaded yet. Where: the clock — allow a couple of minutes after any add, edit, delete or switch flip.
- The target has a stray space. Where: the Target cell — targets are not trimmed, so a trailing space matches only markup that has one. (The Replacement is trimmed.)
- The case or a quote differs. Where: the served markup’s source (the tag’s response), not a prettified view — matching is literal and case-sensitive.
- The text you expect is produced by a macro. Where: the creative’s markup — rules run before
macros expand, so a target must match the macro token (
$$NAME$$), not its resolved value. - You are looking at another placement. Where: the placement that served the impression — rules are per placement, not per site or zone.
Other symptoms:
- Add is refused with “Wrong values”. Where: the Target — blank, over 255 characters, or already a target of this placement (compared without regard to case). Edit the existing row’s Replacement instead.
- The card is missing. Where: your role — Placement Content Replacement is off on both stock roles until an administrator grants it — and the placement: it must have been saved once.
- The switch is locked and there is no add bar. Where: your share on the parent site — a Can View or masked share is read-only; editing needs the owner or an editable share.
- Leading spaces in the replacement are missing. Where: the ad server trims the Replacement when it loads it; a replacement cannot start or end with whitespace.
Reference
| Field | What it does | Notes |
|---|---|---|
| Switch (card header) | Turns applying the rules on/off for serving | Off = rows kept but ignored by the ad server |
| Target | The exact string to find in the served markup | Required; up to 255 characters; must be unique within the placement (case-insensitive) — adding a duplicate target is rejected |
| Replacement | The string every occurrence of the target becomes | May be blank — a blank replacement deletes the target from the markup. Leading and trailing spaces are stripped before serving. Up to 65,535 bytes |
Through the API or an AI assistant
The rules can be managed over the REST API, with the same permission and site rights as the card:
| Method | Path | Does |
|---|---|---|
| GET | /rest-api/placements/{placementId}/content-replacement.do | Every rule (id, target, replacement), their number (total) and whether the card’s switch is on (contentReplacementEnabled) |
| POST | /rest-api/placements/{placementId}/content-replacement/create.do | Add a rule: target (required, up to 255 characters), replacement (optional) |
| POST | /rest-api/placements/{placementId}/content-replacement/{ruleId}/update.do | Change a rule’s target and/or replacement; what you do not send stays |
| POST | /rest-api/placements/{placementId}/content-replacement/{ruleId}/delete.do | Remove a rule |
The switch itself is the contentReplacementEnabled parameter of the placement’s
update/* operation. A duplicate, blank or over-long target, or a replacement over 65,535
bytes, is refused with a 400 naming the field; a rule id of another placement is a 404.
An AI assistant connected through MCP shows the rules in
placement_overview, and whoami says whether your role may manage them
(contentReplacement).
Per-role notes
- Publisher and network manager — the card appears once your network administrator switches Placement Content Replacement on for the role, and then behaves the same for both.
- Can View share — the rules are visible, but the switch is locked and there is no add bar or delete.
- Masked share — the same as Can View; masking does not change the card.
Exact grants: see User roles.
Related pages: