Variable substitution in iframes - request to revisit #4573
in #4573 @cramforce wrote and the issue was closed.
We do not want to make variable substitution available to amp-iframe, because that opens up usage of it for undesired purposes such as ad serving and analytics.
I'd like to request we revisit this issue. The specific use case is video players in amp-iframes. None of our customers are currently using amp-video or amp-specific version of players in production due to the need for pre-roll ads and the presence of significant existing legacy video infrastructure.
While we can make the players work in an amp-iframe with some https juggling we can't correlate ads between the video and the page. We'd like to be able to pass to the iframe standard variable substitutions. Some we can do at page build time (static things like page urls) but the CID, timestamp, page view id etc. can't be done statically.
Yes this would allow ads and analytics in iframes. That's what we need to make video monetize at it's full potential.
/to @cramforce
nudge
I think the right solution here is to allow iframes to pass analytics events to the main page and have tracking happen there.
Could be as simple as (in the iframe)
parent.postMessage({
type: 'amp-analytics-trigger',
trigger: 'video-ad-view',
data: data,
}, $parentOrigin);
In AMP analytics the trigger names would need to be auto prefixed to not conflict with (future) builtin, like user-trigger-video-ad-view.
I like that. Would data be a JSON object that gets merged into the amp-analytics vars object?
That is not what I thought about, but seems reasonable.
I was thinking of an a custom trigger as opposed to custom analytics config. Both make sense. Definitely something the page would need to give as a permission to an iframe, of course.
On Wed, Dec 7, 2016 at 2:34 PM, John Pettitt [email protected] wrote:
I like that. Would data be a JSON object that gets merged into the amp-analytics vars object?
— You are receiving this because you were assigned. Reply to this email directly, view it on GitHub https://github.com/ampproject/amphtml/issues/6234#issuecomment-265595372, or mute the thread https://github.com/notifications/unsubscribe-auth/AAFeT6_WTJzs6mH4k-NitqAnFSzv91x8ks5rFzSQgaJpZM4K1wUZ .
@jpettitt Would you or someone in your company be interested in implementing this?
@cramforce - let me look at the schedule. We're slammed with customer work right now.
Edit: Would you want to do this only for amp-iframe or allow other trame generating code (ads, video players, embeds) to use it.
@jspettitt @cramforce Are you still considering to implement this? Maintain same client id for content inside an IFRAME is something we also need, and we can contribute if necessary.
Would it be as easy as receiving the post message from AMP-IFRAME (only in white-listed IFRAMEs) , and create an AMP-ANALYTICS component on the fly with the JSON received?
I think there would need to be a stub analytics component to catch the message, if only to include the CID and do var substitution. My take was trigger a regular amp-analytics event with a set of vars merged in from the json payload. That way all the AMP substitutions would work.
Fortunately for the company but unfortunately for this we've picked up even more work so I don't see having time to contribute to this before Feb at the earliest.
@cramforce what do you think which approach work best? I think we can work on this
@oliverfernandez I think the configuration of analytics events should be on the main page. iframes should only send events.
@cramforce are you saying that no data can be passed or that the main analytics event is defined in the parent but the variables used by that event can be passed up from the iframe? We'd like to be able to pass variables out of the frame - eg play length for videos.
@jpettitt The latter. The parent should not send analytics hit requests that it did not expect, but iframes can parametrize those it does.
@jpettitt Any chance you'd like to take a shot at implementing this?
@cramforce even more slammed that last time you asked. :-(
We also have an on-going issue with tracking events from a proprietary video player in an <amp-iframe>. There seems to be two possible approaches:
- Allow variable substitution into
<amp-iframe>, including key values like DOCUMENT_REFERER, CANONICAL_URL and CLIENT_ID (since without them it's near impossible to relate the video in the iframe to it's container) - Allow the creation of customer analytics events within the private IFRAME via window.postMessage() and get
<amp-analytics>to send the events on behalf of the iframe.
The general gist seems to be that the contents of IFRAMEs are isolated from AMP, which would suggest option (2) is more AMP-friendly, in that events are managed (filtered, substituted, secured) by AMP.
Are either of these solutions part of planned update? If not, who/how is the case made?
I suggest we do this regardless of amp-video-iframe work. Doing https://github.com/ampproject/amphtml/issues/6234#issuecomment-296156703 for both amp-iframe and amp-video-iframe (same underlying code) makes more sense to me than just doing it for amp-video-iframe as it enables analytics for other types of embeds (e.g. an interactive data visualization iframe that similar to a video player, may want to send analytics values).
My idea of AMP video analytics is a common set of variables (e.g. play, seek, fullscreen, etc..) that can come from any video player (amp-video, amp-youtube, amp-video-iframe) but this set is limited and only for events that are common across all video players, we would still need a way to have custom variables that only make sense for certain players to make it to analytics hence my suggestion.
@lannka Suggested we use amp context from now on to create 3p APIs in JS instead of relying on documented postMessage structures which I totally agree with.
@rudygalfi looks like both DailyMail and RelayMedia can benefit from this. Let's see where it fits in our priorities. @matAtWork PRs welcomed for this as well if this is something you are interested in contributing.
Apologies for the silence - been inundated with (unrelated) tasks, but I'll try to focus on it next week
@matAtWork any updates here? Thanks.