AMP Access spec provides a way for to lock/unlock content.
At the core of the protocol are three concepts:
Metering implementation is specifically described in the Metering section of the AMP Access spec. It suggests that publishers store metering count on their backend system keyed by AMP Reader ID and/or any session information delivered via CORS protocol.
The goal of this ITI is to create a client-side solution that does not require CORS request (or doesn't always require it). This solution is based on 3p iframes.
Some important considerations when designing this solution:
The solution has several components:
This part is very straightforward. It roughly executed as following.
First, the new config extension is provided:
<script id="amp-access" type="application/json">
{
"type": "iframe",
"iframeSrc": "https://pub/iframe",
"iframeVars": [
"EXPRESSION1",
"EXPRESSION2",
...
],
"defaultResponse": {
...
},
// Additional properties.
}
</script>
The iframe is instantiated as following:
const iframeController = createIframe(config.src);
iframeController.connect(config).then(() => {
// Continue to authorization, etc.
});
AMP will define communication protocol to invoke iframe's methods, most notably authorize and pingback.
Most important, the iframe will establish connection with AMP Runtime via a basic handshake:
config object.To execute authorization, AMP Runtime will:
config.iframeVars.To execute pingback, AMP Runtime will:
config.pingbackVars.pingback message to the iframe that includes these variables.So far, this proposal is simple and similar to the AMP Access spec with CORS. However, this section will attempt to address performance issues. We'd like to use the previous response for the next page impression if possible. For the first visit, we also get some of the worst performance factors. So, we would rely on the defaultResponse to do the initial rendering when cache is not available, which will be assumed to be positive. However, we can speed up the follow up impression. The steps are:
defaultResponse.This requires us to define the notion of the positive response. It means that the authorization response grants read access. We will start by mandating a boolean granted field in the authorization response.
The cache can have an upper-bound expiration limit, e.g. the cached response is dropped after 7 days.
Thus, only the negative authorizations are render-blocking. Depending on metering quota, this could significantly reduce optimistic render blocks. It'd also normally result in no more than one extra view by the user.
In case of previous negative response, the authorization is render-blocking. We normally apply a strict time-out of 3 seconds to authorization requests and we鈥檇 like to do the same here.
However, we can do one improvement: even if we timeout the authorization, we can still allow the iframe authorization request to continue and update the cache ones it completes. Thus, the next impression should hopefully proceed faster.
Based on #2970.
I really like the compromise between developer flexibility and performance.
this is great. we currently use amp-iframe for some custom tracking of auth-ed users, but there has been no way yet for us to pass this data back to AMP. let me know if there's anything I can do to help this along ...
Checking in: is this work speculative at this point, or do we have a timeline in mind?
Implementation is started. Not all pieces are yet merged.
A few pointers:
The initial batch of PRs have made it in. The docs are in https://github.com/ampproject/amphtml/blob/master/extensions/amp-access/0.1/iframe-api/README.md
The #14254 adds configuration parameters, defines authorization response more clearly and adds more docs.
Just as clarification, the additional docs were appended to: https://github.com/ampproject/amphtml/blob/master/extensions/amp-access/0.1/iframe-api/README.md
How would one actually reference the sync script used in the iframe? That is, what will the absolute URL for that script (seen as the relative URL /dist.3p/current/amp-iframe-api-export.js in the article-access-iframe.provider.html example) be?
@czarnechmurki amp-iframe-api-export.js is just the concatenation of two files: messenger.js and iframe-api.js. The synchronous /dist.3p/current/amp-iframe-api-export.js is just an example. Concatenation can be done manually, using tools such as rollup, or just take amp-iframe-api-export.js file we provide and drop it in your project. You most likely will want to compile these two files into your own JS binary to avoid extra downloads and sync issues - the startup time for this iframe is pretty important so reducing number of binaries would help.
We will eventually deploy bundled messenger.js and iframe-api.js as an npm module for those who manage dependencies/compile via npm. Let us know if it'd help you.
The merged #14295 functionally completes the access-via-iframe integration. Remaining tasks are mostly administrative, such as exposing npm package, and fixing bugs. But otherwise we are starting tracking toward the launch.
I'm closing this issue and we'll proceed with separate issues for additional fixed and features.
Pls clean up the feature flag if this is fully launched.
@lannka cleaned up