PWA
Last updated
Last updated
PushExpress -- SDK PWA
You can use the data from a single Firebase application for multiple Push.Express applications. To do this, use the same firebaseConfig, Web Push certificate, and private-key.json for multiple Push.Express applications.
Go to Firebase Console and create a new project (or use existing one). You can use one project for all your apps.
Open Project Settings.
Go to General, copy firebaseConfig.
Go to Cloud Messaging, Web configuration, press Generate key pair and save key.
Go to Service accounts, press Generate new private key and save it to file private-key.json (you can use same key for all apps).
Create new application.
Choose type of application Web Push.
Fill in the required Application name field *
Paste private-key.json file to Firebase Admin SDK private key textbox.
After creating the application, push_express_app_id will be available.
Add firebaseConfig, vapidKey, push_express_app_id in your project (where to get this data can be viewed here).
The firebase Config is located in the firebase console of your application (look here).
The vapidKey is located in the firebase console of your application ( look here).
The push_express_app_id is located on the application page in the Push Express service (look here).
Here you can set the path to the service worker.
Send the unique installation id here.
The url for the redirect after initializing the sdk. Leave it empty if a redirect is not requirednd the unique installation id here.
The segment code. Use it to add a device to a segment. Segments can be created in the segments section of your personal account.
To transfer devices to other users of the service, use the functionality of webmasters. You can add a webmaster in the personal section of your personal account.
Add PushExpress library below
Perform the SDK initialization
If a redirect_url value is specified, a redirect will be performed after initialization.
[!IMPORTANT] Do not connect third-party Firebase libraries. The Push Express SDK automatically connects the firebase-messaging libraries and generates the FCM token. It takes 3 seconds to install service Worker and transfer all the necessary death to the server. Wait until the sdk is working and only then redirect the user to the landing page. Or use the const redirect_url parameter to automatically redirect the user after initializing the sdk.
Example code index.html
Create service worker file in your project. The file name must be as follows "push-express-sw.js".
[!IMPORTANT] The service worker file must have a name push-express-sw.js . Otherwise, the installation of service worker will fail.
Import library for service worker below.
Example code push-express-sw.js