Search code examples
phpamp-html

Render different content on AMP depending on device (iPhone or Android)


I want to create dynamic content depending on the device of the user.

For example, if the user is browsing the AMP version on my website using an iPhone, my app download link should render as: Download for iPhone (href = app store link)

However, if the user is browsing using an Android device, I would like to render the download app link as: Download for Android (href = google play link)

The problem is that AMP pages are cached and I do not know how to render the content dynamically depending on device type.


Solution

  • IMHO you can achieve this by using amp-access. If you could identify the device from user-agent in the authorization request from amp-access and set a flag in your amp-access response AUTHDATA, then you can conditionally render the button.