Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement outgoing link URL replacements. #5628

Merged
merged 2 commits into from Oct 17, 2016

Conversation

cramforce
Copy link
Member

  • Only exposes QUERY_PARAM and CLIENT_ID
  • Requires opt-in per <a> tag.
  • Only done for destinations going to the page's source or canonical origin.

Fixes #4078

@cramforce
Copy link
Member Author

@zhouyx please take a look
CC @rudygalfi I went ahead and implemented this :)

@zhouyx
Copy link
Contributor

zhouyx commented Oct 17, 2016

One thing I don't understand. We still do lazy initialization. What I see here is that this.setAsync_('CLIENT_ID... here is called no earlier than this.set_('CLIENT_ID.... Would this work as expected?

@cramforce
Copy link
Member Author

@zhouyx Could you rephrase your question? I'm not sure I understand.

This is intended to only provide a CLIENT_ID into a link if there was another mechanism that previously requested it.

@zhouyx
Copy link
Contributor

zhouyx commented Oct 17, 2016

I see, I thought we would need to wait and replace the URL in all cases.
So we are not replacing CLIENT_ID if we don't have it at that moment, would it be normal that url replacement will fail because we never wait for anything?

@cramforce
Copy link
Member Author

Replacement happens on click, while the other mechanisms (analytics) load on page view, so they will probably have run by the time of the click.

if (!clientIds) {
return null;
}
return clientIds[dev().assertString(scope)];
Copy link
Contributor

Choose a reason for hiding this comment

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

don't quite understand what's the scope here. Is it always the same as what we set clientIds[scope above?
Would it be possible to getclientIds[scope] = null here?

Copy link
Member Author

Choose a reason for hiding this comment

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

scope is the param passed of CLIENT_ID(someScope). If the scope is the same, the client ID is the same, which should be what is achieved here. The return value of this statement is undefined if no async request for the client id was made.

return;
}
if (element[ORIGINAL_HREF_PROPERTY] == null) {
element[ORIGINAL_HREF_PROPERTY] = href;
Copy link
Contributor

Choose a reason for hiding this comment

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

where is this used?

Copy link
Member Author

Choose a reason for hiding this comment

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

Line 647. I'll add a comment as to what this is for.

- Only exposes `QUERY_PARAM` and `CLIENT_ID`
- Requires opt-in per `<a>` tag.
- Only done for destinations going to the page's source or canonical origin.

Fixes ampproject#4078
@zhouyx
Copy link
Contributor

zhouyx commented Oct 17, 2016

lgtm

@@ -213,8 +221,22 @@ export class UrlReplacements {
scope: dev().assertString(scope),
createCookieIfNotPresent: true,
}, consent);
}).then(cid => {
if (!clientIds) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not just initialize it above? It's just one object.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please let me have my premature optimizations :)

'CLIENT_ID': true,
'QUERY_PARAM': true,
};
const requestedReplacements = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

We could reuse the same supportedReplacements by settings its values to false.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, it also isn't actually used like that, i think. I don't care about allocation on click :)

@cramforce cramforce merged commit 156c8ee into ampproject:master Oct 17, 2016
samiamorwas pushed a commit to samiamorwas/amphtml that referenced this pull request Oct 18, 2016
…mp_reddit_extension

* 'master' of https://github.com/ampproject/amphtml: (63 commits)
  Position:relative on body (ampproject#5665)
  Fix for ampproject#5663 (ampproject#5664)
  Nokta Ad Server is added as an ad type (ampproject#5550)
  RFC: Separate the load phase of AMP into multiple chunks. (ampproject#5536)
  Add OWNERS files for A4A. (ampproject#5651)
  Update DEVELOPING.md
  Call original event add/remove via interceptor (ampproject#5650)
  Fix wording on confusing steps to protect against CSRF. (ampproject#5646)
  Install runtime CSS for all amp tests (ampproject#5642)
  Implement outgoing link URL replacements. (ampproject#5628)
  Wait for window to load before installing ServiceWorker. (ampproject#5638)
  iOS wrapper viewport implementation (ampproject#5629)
  Do not use AMP Version as RTV Versions (ampproject#5474)
  Purch Ad Support for Amp-Ads (ampproject#5464)
  A11Y fix for sticky ad close button. (ampproject#5640)
  Propagate ARIA attributes to real-elements (ampproject#5590)
  Ibillboard integration (ampproject#5392)
  Add some keywords to the NPM description of the validator. (ampproject#5633)
  PWA: messaging and broadcast (ampproject#5588)
  Carousel swipe not working well on Android Firefox (ampproject#5626)
  ...
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
- Only exposes `QUERY_PARAM` and `CLIENT_ID`
- Requires opt-in per `<a>` tag.
- Only done for destinations going to the page's source or canonical origin.

Implements ampproject#4078
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
- Only exposes `QUERY_PARAM` and `CLIENT_ID`
- Requires opt-in per `<a>` tag.
- Only done for destinations going to the page's source or canonical origin.

Implements ampproject#4078
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants