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

✨ Add requestOrigin field in analytics config #22454

Merged
merged 20 commits into from Jun 21, 2019

Conversation

jonathantyng-amp
Copy link
Contributor

Add a new requestOrigin field to the top level analytics config. The requestOrigin part will not be encoded and all outgoing URLs will be prepended with it.

See #19759 for more details

@zhouyx zhouyx self-requested a review May 23, 2019 00:23
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/amp-analytics.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Show resolved Hide resolved
extensions/amp-analytics/0.1/variables.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
@jonathantyng-amp
Copy link
Contributor Author

Discussed offline. IE11 does not support URL constructor and its behaviour is not exactly what we want. Will need to use custom URL constructor.

@jonathantyng-amp
Copy link
Contributor Author

cc @zhouyx ready for review!

extensions/amp-analytics/0.1/variables.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/config.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Show resolved Hide resolved
src/url.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
@jonathantyng-amp
Copy link
Contributor Author

jonathantyng-amp commented Jun 5, 2019

Discussed offline.

requestOrigin will only accept absolute URLs and will extract the origin. We will also not accept empty strings in requestOrigin for now.

E.g. "https://example.com/test1/test2" -> "https://example.com"

If requestOrigin is defined, every outgoing request will be appended to the origin that is extracted from requestOrigin.

An origin field will also be allowed in each request object that will override the top level requestOrigin

@jonathantyng-amp
Copy link
Contributor Author

cc @zhouyx ready for review!

extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
src/url.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/config.js Show resolved Hide resolved
@zhouyx zhouyx requested a review from torch2424 June 6, 2019 19:24
Copy link
Contributor

@torch2424 torch2424 left a comment

Choose a reason for hiding this comment

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

Great work! Thank you! 😄 🎉

Just some questions about the URL Parsing.

src/url.js Outdated Show resolved Hide resolved
test/unit/test-url.js Outdated Show resolved Hide resolved
src/url.js Outdated Show resolved Hide resolved
extensions/amp-analytics/0.1/config.js Show resolved Hide resolved
src/url.js Outdated Show resolved Hide resolved
src/url.js Outdated Show resolved Hide resolved
@jonathantyng-amp
Copy link
Contributor Author

jonathantyng-amp commented Jun 11, 2019

Ended up using parse helper function in UrlService to parse requestOrigin instead of regex! Added additional test coverage as well.

cc @zhouyx @choumx for review :)

Copy link
Contributor

@zhouyx zhouyx left a comment

Choose a reason for hiding this comment

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

Yay, LGTM with a few minor requests 🎉

extensions/amp-analytics/0.1/requests.js Show resolved Hide resolved
extensions/amp-analytics/0.1/requests.js Outdated Show resolved Hide resolved
yield macroTask();
expect(spy).to.be.calledWith('http://example.com/r3');
});
});
Copy link
Contributor

Choose a reason for hiding this comment

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

We talked about this, but I still think it's worth adding the requestOrigin being relative url test. Tests are mostly for developers, and it helps them to understand the desired behavior much better. With that test, we could save a lot of explanation on how we want to handle the special case where requestOrigin is not absolute. WDYT?

Copy link
Contributor

@torch2424 torch2424 left a comment

Choose a reason for hiding this comment

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

Thank you for addressing my comments 😄 LGTM!

@zhouyx
Copy link
Contributor

zhouyx commented Jun 18, 2019

Ping @jonathantyng-amp let me know once you think the PR is ready : ) Thank you

@jonathantyng-amp
Copy link
Contributor Author

cc @zhouyx ready for review!

@zhouyx zhouyx merged commit 2888ba7 into ampproject:master Jun 21, 2019
@zhouyx
Copy link
Contributor

zhouyx commented Jun 21, 2019

@jonathantyng-amp got green build! Merged! 🎉 🎉 🎉

thekorn pushed a commit to edelight/amphtml that referenced this pull request Sep 11, 2019
* add request origin

* expansionOptions fix

* Add changes from comments

* fix tests

* typo

* use URL constructor and move requestOrigin propagation to config.js

* catch URL construct error

* add custom url constructor

* cleanup unused code

* changes from comments

* Don't extract relative path from request and support origin field in request object

* remove unused tests

* add new tests and use URL constructor

* use UrlService

* add comments and tests

* lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants