AMP – or Accelerated Mobile Pages – is a project backed by Google that aims to make the loading of mobile web pages much faster.
According to Google, 40% of people abandon a website that takes more than 3 seconds to load. This demonstrates that users expect websites to load almost instantaneously.
Essentially, AMP pages work by using a lighter version of HTML that allows websites to load much faster than regular HTML.
As google give AMP pages more importance in search engines, you will get hell out of traffic. So it will be better idea to implement web push notifications on AMP pages and increase your subscribers.
How to implement Web Push Notification on AMP pages
There are 3 simple steps to implement Web Push Notifications:
1. Start with an empty html page with basic html structure. Add the script tag given below in your head section. This will load amp-web-push library provided by amp project.
2. Now create a widget to give user to subscribe to push notification. Make two buttons , one for subscribe and one for unsubscribe. You can remove unsubscribe button but it will recommended by google for better user experiences. Add this code in body part.
Note : Visibility tag is required here. Visibility will take three value namely subscribe , unsubscribe or blocked . Widget will show and hide on the basis of user’s subscription state .For ex. first time user will see widget with visibility unsubscribe and if user subscribe the push, he will see widget with visibility subscribe .
3 . Now it’s time to install service worker and other configuration. For this you have to integrate three files in your root folder of our web site and your site must be on https. This three files are as following:
You can download these files by clicking on them.
Add this amp-web-push tag in html page which loads the all three files.
Now question is for what purpose we are adding these three files
helper-iframe-url : This page works as a mediator between amp and service worker, to enable communication which subscribes and unsubscribes the user. Notification permission status is also determined by this page.
Permission-dialog-url : This page is for user interaction which open a page as a pop up and prompts for notification permissions.
Service-worker-url : As you know it will run in background which subscribe, unsubscribe the users or display notifications to them.
If you don’t know about Service Workers, you can use third party sites which provide complete solution for Web Push Notifications like NotifyVisitors
- Your AMP page must pass in validation.
- Your site must be on https.
- All three files mentioned above must be placed in root folder