Intent to implement: Dynamic CSS classes based on referrer, viewer, other factors
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
@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?
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.
@rudygalfi To confirm, yes, this is more-or-less exactly what we already do on mobile-web.
@jridgewell want to give this a go?
Certainly.