Allow for white listed replacement of URL placements and use it in A4A.#5275
Allow for white listed replacement of URL placements and use it in A4A.#5275cramforce merged 4 commits intoampproject:masterfrom
Conversation
| // based rendering, in which case the document relative positions are | ||
| // really ad-relative. | ||
| 'CLICK_X': () => { | ||
| return e.pageX; |
There was a problem hiding this comment.
Given that we're not handling ad offset correctly here in the shadow DOM case, I'm concerned that we may inadvertently trip spam filters due to invalid click x/y values being sent. I propose we either wait for PR #5196 before submitting (will need to handle conflicts) or update the X/Y to use the shadow DOM offset as I had done previously and then I will remove as part of PR #5196
| hrefToExpand, vars, undefined, /* opt_whitelist */ { | ||
| // For now we only allow to replace the click location vars | ||
| // and nothing else. | ||
| 'CLICK_X': true, |
There was a problem hiding this comment.
There would never be a reason to pass false here, right? You really want a set so you used Object? Just confirming...
There was a problem hiding this comment.
Yeah, sigh. I was considering an array, since O(small N) is likely faster than more complicated O(1), but this is slightly more idiomatic.
extensions/amp-a4a/0.1/amp-a4a.js
Outdated
| } | ||
| target.setAttribute('href', newHref); | ||
| } | ||
| return newHref; |
There was a problem hiding this comment.
No need to return href right? Signature does not reflect this
|
/cc I am interested in how amp-analytics will work in this as well. |
|
@avimehta Currently no change, but we need to do something similar there for rolling out A4A to more ad sources. |
A more limited (to A4A) exposure of the work in ampproject#5053. - Implements ability to provide a white list of replacements for a given operation. - Moves the click handler from a global position to A4A specific code. - Switches to simpler click position implementation (just `pageX/Y`). This is currently incorrect, but will be correct after A4A moves to friendly iframes from ShadowDOM. Should help with ampproject#5205 and ampproject#4078. Related to ampproject#4891.
1159d3e to
19f3a1c
Compare
|
PTAL Added @zhouyx since she just wrote similar code. |
|
OOTO until Tuesday. If this cannot wait, please ask tdrl@ to review. On Oct 7, 2016 6:29 PM, "Malte Ubl" notifications@github.com wrote:
|
| * @param {!Window} iframeWin | ||
| */ | ||
| registerExpandUrlParams_(iframeWin) { | ||
| iframeWin.document.documentElement.addEventListener('click', |
There was a problem hiding this comment.
One thing I worry here is registerAlpHandler_ also listen to the same click event. Would it be the case that it redirect before expanding url params?
There was a problem hiding this comment.
I added some comments to this respect. We do need the 2 handlers for correctness, because one is a capture phase handler and thus reliably runs first.
| }, | ||
| }; | ||
| const newHref = urlReplacementsForDoc(this.getAmpDoc()).expandSync( | ||
| hrefToExpand, vars, undefined, /* opt_whitelist */ { |
There was a problem hiding this comment.
should we keep a default whitelist separately?
There was a problem hiding this comment.
I don't think we will use this whitelist elsewhere and I like this inline for readability.
| * @private | ||
| */ | ||
| expand_(url, opt_bindings, opt_collectVars, opt_sync) { | ||
| expand_(url, opt_bindings, opt_collectVars, opt_sync, opt_whiteList) { |
There was a problem hiding this comment.
This is probably ok as a first start, but I think the final API will be drastically different when we need to support the whole table of enabled/disabled/overriden vars. In the meantime, we could even simply call string.replace('CLIENT_X', value) to get us past this point and closer to correct implementation.
There was a problem hiding this comment.
Our current plans wouldn't go much further than this.
There was a problem hiding this comment.
@dvoytenko I think the overall design is moving towards not having any overridden variables. Variables will be either enabled or disabled for amp-analytics. This design works for that case(with the change to figure out how whitelist can be converted to blacklist.).
There was a problem hiding this comment.
What about performance metrics? It seems very likely we'd completely override their meaning for ads. No?
|
Friendly ping :) |
|
Apologies for the delay. LGTM. I am definitely interested in the long term design decision on how to allow greater expansion. The original i2i included the ability for a hidden iframe to send post message information to be included in the click url. We are hoping to add this functionality in Q1. |
|
LGTM |
…A. (ampproject#5275) A more limited (to A4A) exposure of the work in ampproject#5053. - Implements ability to provide a white list of replacements for a given operation. - Moves the click handler from a global position to A4A specific code. - Switches to simpler click position implementation (just `pageX/Y`).
…A. (ampproject#5275) A more limited (to A4A) exposure of the work in ampproject#5053. - Implements ability to provide a white list of replacements for a given operation. - Moves the click handler from a global position to A4A specific code. - Switches to simpler click position implementation (just `pageX/Y`).
…A. (ampproject#5275) A more limited (to A4A) exposure of the work in ampproject#5053. - Implements ability to provide a white list of replacements for a given operation. - Moves the click handler from a global position to A4A specific code. - Switches to simpler click position implementation (just `pageX/Y`).
A more limited (to A4A) exposure of the work in #5053.
pageX/Y). This is currently incorrect, but will be correct after A4A moves to friendly iframes from ShadowDOM.Should help with #5205 and #4078. Related to #4891.