I2I: Accept Experiment ID's from Player
Summary
The document should accept a list of experiment ID's from the player that's containing it. We'll implement this using PostMessage.
Design document: AMP-Player Experiment Coordination
Objective
Allow Story Players to pass experiment context to the AMP format to allow for experiment coordination and cohesive logging for player experiments.
Background
Google's Story Player uses an internal system for setting up and enabling experiments. The AMP format uses its own separate system for experimentation. We intend to run an experiment in which the viewer enables a default auto-advancing behavior and it will be important for the AMP format to log monetization data associated with each arm. There is currently no way to pass experiment context to the AMP doc.
Overview
Player
The STAMP Viewer will need to get a set of experiment ID’s which it will send to the format. The ID’s will be sent via PostMessage once the format indicates its ready (players often queue messages while the doc is loading).
Format
The format will accept a message which will include a list of experiment ID’s which may be accessed and used, for example to log Ads metrics for AutoAdvance .
Design
Communicating Between the AMP Doc and Player
The ID’s will be sent via PostMessage once the document is loaded and ready to receive messages. See integrating-viewer-with-amp-doc-guide.
The advantage of using PostMessage for communicating (over alternatives like an encoded/unencoded list of experiments in a URL param) is that it prevents experiment ID’s from being revealed to the entire AMP doc as a param, and it will better allow for scaling if the feature is used more widely in the future.
Request (with no response) from player to AMP doc
{
"type": "playerExperiments",
"payload":
{
"ids": [1234, "…", 5678]
}
}
Motivation
For both logging and experiment coordination (i.e. triggering an AMP-specific experiment only if a player-specific experiment is active for a user), it is helpful to know which experiments the player is in. There have been Google AMP experiments in the past which relied on one-off hacks to accomplish this and we need to use this for Ads logging now, so it's worth creating a robust solution.
Launch tracker
TODO
/cc @ampproject/wg-approvers @gmajoulet @kristoferbaxter @calebcordry
Can you justify your choice of requesting the experiment IDs using postMessage, vs providing them as a query parameter in the URL of the document? Some logs or analytics could potentially be sent before the viewer answers this postMessage. Having the data in the URL would avoid all possible race conditions, and ensure that all logs/analytics call have the information available.
We thought using PostMessage would be the right choice for
- Privacy, to restrict access to the experiment ID's, and
- Scalability, so that if this feature is used for a huge set of ID's in the future it doesn't risk overloading the URL
The race condition is a good point though, I hadn't considered that. I'll make a public design doc and attach it soon so we can compare options and benefits there. I'm also aiming to join for Wednesday's Design Review where we can discuss synchronously.
I think IDs in URL is more reliable & flexible. Reliable: no async problem that @gmajoulet pointed out, which might cause unnecessary code complexity or future bugs. Flexible: it leaves opportunity for server side rendering.
Meantime I do think the Player is responsible to extract a subset of IDs that are sharable to AMP doc to not overload the URL.