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

Normalize Referrer classes across devices #1270

Merged
merged 1 commit into from
Jan 13, 2016

Conversation

jridgewell
Copy link
Contributor

For now, these include Facebook, Twitter, and Pinterest with amp-ua-${SERVICE}.

Fixes #1263.

describe('dynamic classes are inserted at runtime', () => {
let documentElement, win;
beforeEach(() => {
describe.only('dynamic classes are inserted at runtime', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

remove the only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@jridgewell
Copy link
Contributor Author

Assigning to @cramforce, need to know what other apps we want to support.

@jridgewell jridgewell assigned cramforce and unassigned camelburrito Dec 30, 2015

**amp-ua-***

A User Agent class will be added when we detect that the document is
Copy link
Contributor

Choose a reason for hiding this comment

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

document where the class would be added. (body/documentElement? )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@camelburrito
Copy link
Contributor

LGTM

@dvoytenko
Copy link
Contributor

My main question is whether the distinction between referrer and UA is apparent enough. A lot of times, I assume, these could mean the same thing, especially when the document is shown in the iframe. I think it's critical we clarify the distinction between the two or remove it entirely.

@@ -27,8 +27,8 @@ export class Platform {
* @param {!Window} win
*/
constructor(win) {
/** @const {!Window} */
this.win = win;
/** @const {string} */
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not a string, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, fixed.

@jridgewell jridgewell force-pushed the dynamic-user-agent-classes branch 2 times, most recently from 5ea0456 to a9ddbc6 Compare December 30, 2015 19:50

function addUserAgentClasses(win) {
const classes = ['Facebook', 'Twitter', 'Pinterest'].filter(service => {
return platform[`is${service}`]();
Copy link
Member

Choose a reason for hiding this comment

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

This pattern does not work with closure compiler advanced optimizations.

@jridgewell
Copy link
Contributor Author

Updated code, please take another look. Will update the docs tomorrow.

@jridgewell jridgewell changed the title Include Service identifier dynamic classes Normalize Referrer classes across devices Jan 12, 2016
@cramforce
Copy link
Member

Code looks good.


// Normalize t.co names to twitter.com
if (referrer === 't.co') {
referrers = referrers.concat(referrers_('twitter.com'));
Copy link
Contributor

Choose a reason for hiding this comment

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

So, we will have both, "t-co" and "twitter-com"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, this will include the both of them. Per my talk with @cramforce yesterday:

Should we normalize t.co links to twitter.com?

That would be cool, yeah
Because I want them to get rid of t.co
And if they did we likely would put the opposite hack on our side

So it seems to me we should allow people to use t.co if they're aware of twitter's short links, or twitter.com if they're not.

Copy link
Member

Choose a reason for hiding this comment

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

I'd actually prefer to use twitter.com exclusively.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't you think that'll be confusing for the people who are expecting t.co links?

Copy link
Member

Choose a reason for hiding this comment

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

They can always just see which classes are present in the cases they are testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@jridgewell jridgewell force-pushed the dynamic-user-agent-classes branch 3 times, most recently from 5f5245c to 9bb543a Compare January 13, 2016 19:46
it('should normalize twitter shortlinks to twitter', () => {
return setup(true, '', tcoReferrer).then(() => {
expect(documentElement).to.have.class('amp-referrer-co');
expect(documentElement).to.have.class('amp-referrer-t-co');
Copy link
Member

Choose a reason for hiding this comment

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

Why is this still being added?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Forgot to remove it, sorry.

@cramforce
Copy link
Member

Do you still have it on your radar to make this extension block the page from unhiding the body before it ran?

@cramforce
Copy link
Member

LGTM

@jridgewell
Copy link
Contributor Author

Added #1415 to track the FOUC issue.

- We normalize `t.co` referrers to `twitter.com`
- We add a `www.pinterest.com` referrer when inside the Android
  Pinterest app.
jridgewell added a commit that referenced this pull request Jan 13, 2016
Normalize Referrer classes across devices
@jridgewell jridgewell merged commit 3f6282a into ampproject:master Jan 13, 2016
@jridgewell jridgewell deleted the dynamic-user-agent-classes branch January 13, 2016 22:16
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.

4 participants