Service Worker
  • 05 Feb 2024
  • 2 Minutes to read

    Service Worker


      Article Summary

      Service Worker (SW) is a JavaScript command that can work even if the browser is not open. Thanks to this JS command, Insider can send web push notifications to users who have an active token regardless of being online. Insider's Push Service sends the push message to SW and the SW shows the notification to the user. Therefore, you must append Insider's SW to your website in order to send web push. 

      SW runs in the background even if there is no internet connection. It cannot reach the DOM. The website must support HTTPS in order to be able to use the SW. It listens to the push notification which comes from the server.

      How to Integrate Service Worker and Requirements

       You can integrate the Service Worker with three easy steps:

      SSL Certificate

      Since all pages using native opt-in must have HTTPS support, the website must have a valid SSL certificate.

      Insider Tag Integration

      You must integrate Insider Tag before integrating the Service Worker.

      Insider Service Worker

      The Insider Service Worker file is downloaded from Insider Website;

      1. Follow this link. Right-click and Save As to download the Insider Service Worker file (insider/insider-sw-sdk.js). Upload the Insider Service Worker file to your domain subpath. Do not modify the name of the file or the content.

      Your title goes here
      If there is another SW file in the website, they have to be in different paths with Insider Service Worker. Otherwise, Insider' SW will be redundant and the push notifications are not sent.
      Your title goes here
      If your website does not support HTTPS, then you can the HTTP opt-in. Refer here for more information.

      2. After uploading the SW file, the path is specified on Web Push Integration Settings if it is not in the root path.

      3. After the integration, visit your website and click Allow button on the notification permission screen.

      SW file should be registered on your browser. Open the devTools and check it from the “Application > Service Workers” tab. Status color should be green and the status note should be “activated and is running”. If its color is not green, you should check the SW integration since it is wrong.

      4. After seeing the SW is registered successfully, you should visit other pages to check the registration status. While SW can work on a page, it might not work on another page if there is a mistake related with the integration. So, you should check other pages which are integrated. It should be green for the other ones, too. 

      Your title goes here
      Ensure that the name of the Service Worker is “insider-sw-sdk.js” for each page in Application tab.
      Your title goes here
      Refer here for more information on SW integration.

      How to Integrate Service Worker to Accelerated Mobile Pages (AMP)

      If you want to integrate the SW to Accelerated Mobile Pages (AMP), you should apply 4 more steps. After completing them in the following page, you can test it.

      Your title goes here
      For further information about AMP Integration, refer here.

      After integrating the AMP, you should visit your website on the mobile view. You will see a button to subscribe when you visit the page on which the integration is applied. Then, you should click the button and subscribe to the mobile site.

      Your title goes here
      If you do not see the button on the integrated page, you should check their integration.
      Your title goes here
      If a user subscribes to your website with AMP button, their token’s browser type is seen as AMP.

      Was this article helpful?


      ESC

      Eddy, a super-smart generative AI, opening up ways to have tailored queries and responses