Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement outgoing link URL replacements.#5628

Merged
cramforce merged 2 commits into
ampproject:masterfrom
cramforce:link-url-replacements
Oct 17, 2016
Merged

Implement outgoing link URL replacements.#5628
cramforce merged 2 commits into
ampproject:masterfrom
cramforce:link-url-replacements

Conversation

@cramforce

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

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

@zhouyx

zhouyx commented Oct 17, 2016

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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

zhouyx commented Oct 17, 2016

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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.

' source or canonical origin.');
return;
}
if (element[ORIGINAL_HREF_PROPERTY] == null) {

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.

where is this used?

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.

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
@cramforce cramforce force-pushed the link-url-replacements branch from eb9bc6f to 7a674bf Compare October 17, 2016 20:09
@zhouyx

zhouyx commented Oct 17, 2016

Copy link
Copy Markdown
Contributor

lgtm

createCookieIfNotPresent: true,
}, consent);
}).then(cid => {
if (!clientIds) {

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.

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

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.

Please let me have my premature optimizations :)

const supportedReplacements = {
'CLIENT_ID': true,
'QUERY_PARAM': 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.

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

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, 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
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.

3 participants