AMP has a useful built-in component, amp-user-notification
, for displaying pop-up, dismissable notifications. A common use for this component is to display a cookie warning (a requirement for sites that use cookies in the EU). By default, the notification is displayed at the bottom of the screen. It's not limited to displaying cookie warnings of course; it could show a notification about new content, a special offer, a newsletter sign-up, or number of credits or unread articles, to name just a few. Let's see how it works.
The first thing to note is that we need two scripts to use amp-user-notification
:
amp-user-notification
:
<script async custom-element="amp-user-notification" src="https://cdn.ampproject.org/v0/amp-user-notification-0.1.js"></script>
amp-analytics
:
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
We could display a simple cookie notice like this:
<amp-user-notification...