Skip to main content
You can integrate the self-handled opt-in option using the web SDK. You need to select the Self-Handled opt-in on the MoEngage app. For information, refer to Configure Web Push settings.

Self-Handled Opt-in

The advanced setting where you can selectively show the Browser Opt-in on specific pages or after certain actions. You have to call our function Moengage.call_web_push() from your script to show the Push permission.
(Mandatory) Call the function Moengage.call_web_push() from your script to show the Push permission.
For more information about the sample code, refer to Sample Code.

Self Handled Opt-ins with Custom Soft-Ask

If you have built a personalized Soft-Ask for your website, MoEngage recommends the following steps: SOFTASK

Enable a Custom Soft Ask

  1. Ensure that the settings for Self Handled Opt-in are selected on the MoEngage app.
  2. Create an HTML for the personalized Soft-Ask for your website
  3. Ensure to make a note of the following class attributes in the HTML.
    1. The parent div enclosing the entire Soft-Ask-HTML
    2. The Allow Button(s)
    3. The Block Button(s)
  4. Set the display style attribute of the parent div to none.
  1. Call Moengage.call_web_push( {...} ) with the following object argument on every page:
    (Using the noted class attributes in the second step)
  1. The SDK will handle when to display the soft ask and everything else. If you want callbacks for any user interactions, refer to Fully functional Custom Soft-Ask.

Basic code sample for enabling a Custom Soft-Ask

Detailed Reference of the Custom Soft-Ask API

The function Moengage.call_web_push accepts this object as an argument:
  • If the soft_ask flag is set to true, it will make the soft ask appear (make the main_class appear) and wait for user interaction with the soft ask and fire the respective callback when interacted with.
  • If the hard ask is blocked, you will not be prompted again.

Advantages of MoEngage Custom Soft-Ask API

  • You wouldn’t know what all browsers are supported for web-push by the MoEngage SDK, so you’ll end up displaying the soft ask but without any push_token.
  • You wouldn’t know that the user has already given the necessary permissions and might end up displaying the soft ask unnecessarily.
  • You wouldn’t know when the user last dismissed the soft-ask and will end up displaying the soft ask immediately on the next page load and not after the configured optIn-reappear-time (on MoEngage Dashboard) which will lead to a bad user experience.
If you have built a personalized Soft-Ask for your website, We strongly recommend you to use the Custom Soft-Ask API.

Fully functional Custom Soft-Ask

MoEngage recommends that you call the function Moengage.call_web_push() on every rendered webpage to avoid any kind of interference with the site elements.

Soft Ask Example

In this example, we’ll implement another soft ask which is a “bell” icon at the bottom-left part of the screen. Softaskexample Here is the required HTML:

Sample Code for ask again of a soft ask

The sample code describes:
  • When a user clicks Do not Allow
  1. Search for the OPT_IN_SHOWN_TIME in localstorage (MOE_DATA)
  1. Check if softAskStatus is shown or dismissed and decide to display the soft ask based on the optInShownTime.

Next Steps

After you configure the opt-in and the user visits your website, there is a prompt for opt-in permission requests. If the user accepts the opt-in request, the reachability icon for web push is green in color on the MoEngage user profile page. For more information, refer to User Reachability.

Troubleshooting

Opt-In not Displayed

Follow these steps:
  1. Check the MoEngage dashboard whether you have configured domain type as http or https and the same is your application domain URL.
  2. You may be using some other Push notification provider and that serviceworker file is overlapping with MoEngage serviceworker file.
  3. Check the serviceworker file. It should contain the following code:

How do I change the Push Opt-In process?

You have three Push Opt-In options. For more information, refer to Configure Web Push Settings.

I wish to customize Notification permission opt-in banner or nudge.

You can customize the time (after which to show banner or nudge), Text, Fonts & Font-size. For more information, refer to Configure Web Push Settings. For further assistance, please contact your MoEngage Customer Success Manager (CSM) or the Support team.