amphtml icon indicating copy to clipboard operation
amphtml copied to clipboard

Intent to implement: Dynamic CSS classes based on referrer, viewer, other factors

Open cramforce opened this issue 11 years ago • 5 comments

We want to allow tailoring content and interaction elements to the environment using css.

We'll interpret certain signals and if present add classes to the document element, so that pages can show, hide or change emphasize based on these classes.

Example:

<html class="amp-referrer-twitter amp-viewer amp-viewer-google">

In particular, we'll take the domain of the referrer and add each sub-domain as one class. E.g. www.twitter.com becomes amp-referrer-www amp-referrer-twitter amp-referrer-com` (Maybe the algorithm can be made slightly smarter).

Another case is that we'd add the class amp-viewer if a viewer is present.

In the future a-b testing can be implemented this way as well, where we define a way to express rules for how to add such classes and publishers can say e.g. "add test-grou-a for 10% of users" or a similar expression.

CC @rudygalfi

cramforce avatar Nov 17 '15 01:11 cramforce

@ryanlombardo Do you think this would cover some of the use cases you mentioned in #871 where you vary content by referrer or user agent?

@cramforce Can user agent be one of the factors looked at here?

rudygalfi avatar Nov 19 '15 20:11 rudygalfi

We could do classification of "special" UAs. Generally UAs have a bit too much entropy to put them into CSS classes without processing. I'd also avoid making Chrome/Safari/Firefox differentiation, but ua-twitter and ua-facebook would be fine.

cramforce avatar Nov 19 '15 20:11 cramforce

@rudygalfi To confirm, yes, this is more-or-less exactly what we already do on mobile-web.

ryanlombardo avatar Dec 07 '15 22:12 ryanlombardo

@jridgewell want to give this a go?

cramforce avatar Dec 20 '15 22:12 cramforce

Certainly.

jridgewell avatar Dec 21 '15 16:12 jridgewell