Direct Integration Guide
Last updated
Last updated
This page details the steps needed to integrate web push notifications using the preferred method of using a service worker directly on your website. Using this method:
You will need to create or update a service worker at the root of your website.
Notifications sent to users will appear as coming directly from your domain name.
You must be able to configure the service worker at the root scope of your website.
The service worker must be loaded from the same domain as your website — i.e., it cannot be loaded from a CDN or other third-party location.
You must be able to include Fanplayr's web push notification script within the service worker.
If you are unable to meet the requirements of this method, see Popup Integration for an alternative method.
Supported by modern web browsers and operating systems which implement the Push API.
Device | Browser | Support |
---|---|---|
When using a Fanplayr widget to prompt users to subscribe you should make use of the "Can Subscribe to Web Push Notifications" segmentation filter to ensure that only users who currently do not have a subscription and have a supported web browser are targeted with the widget.
Request permission to send notifications: Users who have not yet subscribed to notifications are shown a widget with a message prompting them to subscribe (e.g. "Stay up to date with our latest news and offers"). When the user clicks the primary call to action, the browser prompts them for permission to send push notifications.
User grants permission: If the user agrees to receive push notifications, they can click "Allow" or "Yes" on the browser prompt. At this point a subscription is created and stored in Fanplayr's database, which is then used to send notifications.
Fanplayr sends push notifications: Your business sends notifications to subscribed users through Fanplayr's messaging service. Users will be able to see these notifications on their device whenever their browser is open, even if they are not directly visiting your website.
It is highly recommended to use Fanplayr's Targeting features to display an intermediate widget which asks users if they are interested in subscribing to notifications before actually requesting the browser permission. This is important for a number of reasons:
If a user blocks the browser permission request to enable notifications you will not be able to request permission again unless the user explicitly resets the permission in their browser settings.
Many web browsers are becoming increasingly restrictive and can prevent showing permission requests when they are generated programmatically without any user interaction — i.e., avoid showing the browser permission request immediately when a user arrives on the page, instead show them a call to action which when clicked, triggers the request.
You must be able configure the service worker at the root scope of your website. This can be achieved in one of two ways:
By hosting the service worker JavaScript file at the root of your website — e.g., if your domain is mybrand.com and your service worker file is located at https://mybrand.com/service-worker.js, then the service worker will be active at the root by default.
Alternatively, by hosting the service worker JavaScript file at a subdirectory and ensuring that the response for the file from the server contains a special header Service-Worker-Allowed: /
, allowing the browser to make it active at the root of the website.
Follow one of the instruction guides below that best matches your scenario:
If you have previously used another service for web push notifications on your website it may be possible to migrate some of the recent subscriptions created for your users provided that:
You can provide Fanplayr with an export of the details of active user subscriptions from the other service. At a minimum, it must include the following details for each user subscription:
Subscription endpoint (example below)
Subscription p256dh key (example below)
Subscription auth key (example below)
You can provide Fanplayr with the web push VAPID public and private key pair which were used to generate the subscriptions (example below)
It is important to understand that Fanplayr may only be able to migrate a portion of the subscriptions from a previously used service due to some subscriptions becoming naturally inactive or having expired in the meantime.
It is also important to understand that the options for sending notifications to migrated subscriptions may be limited until the user returns to the website after Fanplayr Targeting has been integrated on your site.
This is because Fanplayr will not have any knowledge of the user from their migrated subscription alone and would require the user to return to the website with their subscription in order to internally associate Fanplayr's knowledge of the user with the subscription.
In the meantime, it should still be possible to send push notifications targeting all subscribers without filters.
If you are using Fanplayr's sw-load.js
script, you must ensure that this is included on your webpage before Fanplayr's tracking code.
If you are unable to upload the service worker JavaScript file to the root of your server then you may be able to proceed if you can upload it elsewhere with specific headers.
Ensure your server is delivering the service worker file with the following headers:
Content-Type: text/javascript
Service-Worker-Allowed: /
If you are manually registering the service worker (not using our sw-load.js
script) then you will need to update your code to force the worker to be loaded at the root scope. For example:
Desktop
Chrome
v42+
Desktop
Edge
v17+ Note: Edge often hides notification requests behind a small "bell" icon (🕭) in the URL bar, making it harder for users to notice the request.
Desktop
Firefox
v44+
Desktop
Opera
v29+
Desktop
Safari
v16+ on macOS Ventura
Mobile
Chrome Android
v42+
Mobile
Firefox for Android
v48+
Mobile
Opera for Android
v29+
Mobile
Safari on iOS
Not supported