-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Publisher pages hosted by the CDN do not allow the publisher to specify different amp-ad implementations by user, device, etc. For amp-ad elements, remote HTML addresses this deficiency by allowing publishers to specify the frame in which Delayed Fetch executes, in which custom JavaScript dynamically modifies inputs to the ad tag. The primary use case is access to publisher party cookies to allow user-specific targeting. However, Fast Fetch does not allow custom JavaScript execution and thus is not executed (falls back to Delayed Fetch) when remote HTML meta tag is present. Solution proposed is for the publisher to set a new meta tag whose value is a URL (known henceforth as real-time config request) to be executed via GET XHR CORS. This not only ensures Fast Fetch supports real-time configuration, but will also allow for the request to be made earlier in the Delayed Fetch flow, as currently the 3p frame is attached as part of layoutCallback and therefore subjected to the 3 viewport (by default) and other throttling limitations.
Proposed meta tag with example URL:
<meta name="amp-ad-remote-config-url" content="https://foo.your-domain.com/realtimeconfig.get?a=b&c=ATTR(data-slot)&url=CANONICAL_URL">
The real-time config url will include cookies (so long as the CORS response headers indicate they are allowed via Access-Control-Allow-Credentials=true) and will be expanded via url replacement service for the following items (this may be extended as needed). Note that the length of the url will be capped at 4k characters via explicit truncation (allowing for the last parameter to be incomplete).
- ATTR(/name/) allowing for inclusion of attribute values from the amp-ad element
- RANDOM
- CANONICAL_URL the URL of the page as served from the publisher page
- SLOT_WIDTH & SLOT_HEIGHT which are the calculated height/width of the slot to be used for responsive layouts
For Delayed Fetch, the request will be made as soon as onLayoutMeasure executes, the slot is not in a prerender state, and prior to default 3p frame attachment. For Fast Fetch, the request will be made prior to building the ad URL (part of onLayoutMeasure, when slot is not in prerender state).
The AMP XHR service will include on the XHR request a __amp_source_origin parameter with value equal to domain of publisher page. This is because the standard XHR CORS Origin header value will be the CDN (still expects standard Access-Control-Allow-Origin response header whose value is the Origin request header). If access is allowed, the AMP runtime expects the response to include a header named AMP-Access-Control-Allow-Source-Origin whose value is equal to the __amp_source_origin value given in the request. Because this is a non-standard header, the response will also need to include the Access-Control-Expose-Headers header which is a comma separated list of custom header names and should therefore include AMP-Access-Control-Allow-Source-Origin.
The response must be JSON (expects Content-Type header equal to 'application/json') whose keys match attributes to be set on the amp-ad element and whose values are the attribute values to be set. These will then be used by the Fast Fetch implementations to build the ad request and other behavior. The following attributes are not allowed to be modified, and if provided in the response, will be ignored:
- Attribute keys that start with “on” to ensure no JavaScript execution
- style, class, height, width, type, layout
A timeout TBD will be imposed on the real-time config request such that if exceeded (or XHR returns non-200 or otherwise invalid response), the existing amp-ad configuration will be used. This could be configurable by the publisher such that timeout/error could allow for no ad request and collapse, but this configurability will not be included in the first version. Where possible, it is recommended that the response be cacheable by user in order to reduce network fetch delay. Client-side redirects will not be allowed.
Migration Plan
Initially, the remote HTML meta tag will still be honored as publishers move to the new implementation. If both are specified, real-time config will be used and Fast Fetch employed where supported. In the near future, remote HTML support will no longer be honored such that if present, no real time targeting will be made (Delayed Fetch will not use remote HTML path specified) and Fast Fetch will be executed where possible.
Example
<meta name="amp-ad-remote-config-url" content="https://foo.your-domain.com/realtimeconfig.get?a=b&c=ATTR(data-slot)&url=CANONICAL_URL">
Which has amp-ad element:
<amp-ad height=100 width=320 type="doubleclick" data-slot="/1234/a/b/c" data-some-attr="bar"></amp-ad>
Resulting real-time config url (assuming pub page is foo.your-domain.com/blah?foo=bar):
Publisher server makes any potential call-outs to 3rd party vendors to build audience or other targeting to be set and are included in the response.
Example response (note inclusion of invalid attribute names):
{ “json”: {“a”:”b”, “c:123”, e:[1,2,3,4], “data-multi-size-validation”: “123x456,789x123”, “type”: “adsense”, “data-some-attr”: “hello” }
Resulting amp-ad element:
<amp-ad height=100 width=320 type="doubleclick" data-slot="/1234/a/b/c" data-multi-size-validation="123x456,789x123" data-some-attr="hello"></amp-ad>