Skip to content

Allow for white listed replacement of URL placements and use it in A4A.#5275

Merged
cramforce merged 4 commits intoampproject:masterfrom
cramforce:a4a-url-replace
Oct 11, 2016
Merged

Allow for white listed replacement of URL placements and use it in A4A.#5275
cramforce merged 4 commits intoampproject:masterfrom
cramforce:a4a-url-replace

Conversation

@cramforce
Copy link
Copy Markdown
Member

A more limited (to A4A) exposure of the work in #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 #5205 and #4078. Related to #4891.

// based rendering, in which case the document relative positions are
// really ad-relative.
'CLICK_X': () => {
return e.pageX;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer to wait

hrefToExpand, vars, undefined, /* opt_whitelist */ {
// For now we only allow to replace the click location vars
// and nothing else.
'CLICK_X': true,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There would never be a reason to pass false here, right? You really want a set so you used Object? Just confirming...

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

}
target.setAttribute('href', newHref);
}
return newHref;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to return href right? Signature does not reflect this

@avimehta
Copy link
Copy Markdown
Contributor

/cc I am interested in how amp-analytics will work in this as well.

@cramforce
Copy link
Copy Markdown
Member Author

@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.
@cramforce
Copy link
Copy Markdown
Member Author

PTAL

Added @zhouyx since she just wrote similar code.

@keithwrightbos
Copy link
Copy Markdown
Contributor

OOTO until Tuesday. If this cannot wait, please ask tdrl@ to review.
Thank you

On Oct 7, 2016 6:29 PM, "Malte Ubl" notifications@github.com wrote:

PTAL

Added @zhouyx https://github.com/zhouyx since she just wrote similar
code.


You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
#5275 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABr0L8_qqA4oLF5ZvqtVdZdilnOtD4JYks5qxse5gaJpZM4KIUYZ
.

* @param {!Window} iframeWin
*/
registerExpandUrlParams_(iframeWin) {
iframeWin.document.documentElement.addEventListener('click',
Copy link
Copy Markdown
Contributor

@zhouyx zhouyx Oct 8, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

},
};
const newHref = urlReplacementsForDoc(this.getAmpDoc()).expandSync(
hrefToExpand, vars, undefined, /* opt_whitelist */ {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we keep a default whitelist separately?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we will use this whitelist elsewhere and I like this inline for readability.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sg

* @private
*/
expand_(url, opt_bindings, opt_collectVars, opt_sync) {
expand_(url, opt_bindings, opt_collectVars, opt_sync, opt_whiteList) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Our current plans wouldn't go much further than this.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about performance metrics? It seems very likely we'd completely override their meaning for ads. No?

@cramforce
Copy link
Copy Markdown
Member Author

Friendly ping :)

@keithwrightbos
Copy link
Copy Markdown
Contributor

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.

@zhouyx
Copy link
Copy Markdown
Contributor

zhouyx commented Oct 11, 2016

LGTM

@cramforce cramforce merged commit bc5ac0d into ampproject:master Oct 11, 2016
@cramforce cramforce deleted the a4a-url-replace branch October 11, 2016 18:10
dreamofabear pushed a commit to dreamofabear/amphtml that referenced this pull request Oct 12, 2016
…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`).
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
…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`).
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
…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`).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants