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.
<head>
<script type="text/javascript">
...
// Moengage Initialization script here
// Docs: https://developers.moengage.com/hc/en-us/articles/360060713252-Web-SDK-Integration
...
// call to show the Chrome's push notification opt-in box.
Moengage.call_web_push();
</script>
</head>
(Mandatory) Call the function Moengage.call_web_push()
from your script to show the Push permission.
<head>
<script type="text/javascript" src="https://cdn.moengage.com/webpush/moe_webSdk.min.latest.js>
<script type="text/javascript">
Moengage = moe(
{
app_id: "YOUR_APP_ID_GOES_HERE"
});
///call to show the browser's native notification opt-in box.
Moengage.call_web_push();
</script>
</head>
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:
Enable a Custom Soft Ask
-
- Ensure that the settings for Self Handled Opt-in are selected on the MoEngage app.
- Create an HTML for the personalized Soft-Ask for your website
- Ensure to make a note of the following class attributes in the HTML.
- The
parent div
enclosing the entire Soft-Ask-HTML - The
Allow Button(s)
- The
Block Button(s)
- The
- Set the display style attribute of the parent div to none.
<div class="moe-main-class" style="display:none;">... Soft-ask-html....<div>
- Call
Moengage.call_web_push( {...} )
with the following object argument on every page:
(Using the noted class attributes in the second step){ "soft_ask":true, "main_class":"moe-main-class", //parent div enclosing the entire Soft-Ask-HTML "allow_class":"moe-allow-class", //the Allow Button(s) "block_class":"moe-block-class" //the Block Button(s) }
- 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
...
<script type="text/javascript">
Moengage = moe(
{
app_id: "YOUR_APP_ID_GOES_HERE"
});
///call the function call_web_push with this object argument to make your custom Soft-Ask visible
Moengage.call_web_push({
"soft_ask":true,
"main_class":"moe-main-class",
"allow_class":"moe-allow-class",
"block_class":"moe-block-class"
});
</script>
</head>
<body>
<!-- Your Custom Soft Ask Div -->
<!-- Don't forget to set the style-display of your main_class to none-->
<div class="moe-main-class" style="display:none;">
Recieve Notifications ?
...
<button class="moe-allow-class">YES</button>
<button class="moe-block-class>NO</button>
</div>
</body>
Detailed Reference of the Custom Soft-Ask API
The function Moengage.call_web_push
accepts this object as an argument:
*{
"**soft_ask**":true,
"**main_class**":"moe-main-class",
"**allow_class**":"moe-allow-class",
"**block_class**":"moe-block-class",
}*
Parameter | Description |
---|---|
soft_ask | boolean (assumed as false if not present which will trigger the hard ask) |
main_class |
string (class name of the soft ask HTML) Do not forget to set the style-display of yourmain_class to none initially. |
allow_class | string (class name of the allow button) |
block_class | string (class name of the block button) |
info |
Note
|
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 what state of the browser is unsupported. For example, Incognito mode doesn't support web-push but you'll still end up displaying the soft ask there.
- 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
...
<script type="text/javascript">
Moengage = moe(
{
app_id: "YOUR_APP_ID_GOES_HERE"
});
///call the function call_web_push with this object argument to make your Custom Soft-Ask visible
Moengage.call_web_push({
"soft_ask":true,
"main_class":"moe-main-class",
"allow_class":"moe-allow-class",
"block_class":"moe-block-class",
});
</script>
</head>
<body>
<!-- Your Custom Soft Ask Div -->
<div class="moe-main-class" style="display:none;">
<div class="moe-chrome-style-notification moe-chrome-style-notification-safari"
data-rapid_height="50"><div class="moe-safari-notification-inner-wrapper"><div
class="moe-notification-image-wrapper-safari">
<img src="https://www.moengage.com/img/icon-web-push.png"></div>
<div class="moe-text-wrapper-safari">
<span class="moe-notification-title-safari">The website "Your Website"
would like to send you awesome offers!</span>
<p class="moe-notification-message-safari">Notifications can be turned
off anytime from browser settings.</p></div>
<div style="clear: both;">
<div class="moe-modal-branding"><span><a href="https://moengage.com"
target="_blank">Powered by </a></span><a href="https://moengage.com"
target="_blank" style="text-decoration: none;"><img src="https://cdn.moengage.com/images/logo-dark.png"></a>
</div>
<div class="moe-button-wrapper">
<button class="moe-chrome-style-notification-btn moe-btn-close moe-block-class">Don't
Allow</button>
<button class="moe-chrome-style-notification-btn moe-btn-allow moe-allow-class">Allow</button>
</div><div style="clear:both"></div></div>
</div></div></div>
<!-- Styles for the Custom Soft Ask created above -->
<style>.moe-modal-branding img {vertical-align: bottom!important;width:
63px!important;height: 30px!important;padding-right: 2px!important;display: inline-block!important;margin-bottom:-9px;margin-left:-5px;}.moe-modal-branding
span a {text-decoration: none!important;color: #000!important;font-size: 10px!important;line-height:
1.2em!important;font-weight: 400!important;}.moe-modal-branding {float:left;font-size:
10px;margin-top: -2px;font-family: Arial!important;line-height: 1.2em!important;}.moe-chrome-style-notification-safari{width:422px;top:1px;left:calc(50%
- 211px);background-color:#FFFFFF;margin:0;padding:0}.moe-chrome-style-notification{box-shadow:0
0 4px #888;font-size:11px;font-weight:400;position:fixed;z-index:2147483647}.moe-safari-notification-inner-wrapper{margin:0;padding:0
20px 10px}.moe-notification-image-wrapper-safari{float:left;position:relative;margin:15px
15px 0 0!important;padding:0!important;display:inline-block}.moe-chrome-style-notification-safari
*{word-spacing:normal!important;letter-spacing:normal!important;font-family:"Open
Sans",sans-serif!important}.moe-text-wrapper-safari{position:relative!important;padding:10px
0 0!important;color:#000!important;text-align:left!important;margin:0!important;line-height:1.4em!important;display:inline-block!important;width:calc(100%
- 80px)!important}.moe-notification-title-safari{margin-bottom:5px;text-align:left;font-size:14px;font-weight:700;line-height:1.4em;color:#000;font-family:"Open
Sans",sans-serif}.moe-notification-message-safari{font-size:12px!important;line-height:1.4em!important;margin:10px
0!important;padding:0!important;text-align:left!important;font-family:"Open Sans",sans-serif!important}.moe-chrome-style-notification
.moe-button-wrapper{float:right!important;margin:0!important;padding:0!important}.moe-chrome-style-notification-safari
.moe-chrome-style-notification-btn.moe-btn-close{background:#FFF!important;color:#000!important;border-color:#CCC!important;margin-right:20px!important;width:100px!important}.moe-chrome-style-notification-safari
.moe-chrome-style-notification-btn{width:90px!important;height:26px!important;font-size:14px!important;cursor:pointer!important;line-height:1.1em!important;border-radius:4px!important;color:#fff!important;background:
linear-gradient(to bottom,#23bd9f,#12ac8e)!important;border: 1px solid #12ac8e!important;display:inline-block!important;font-weight:400!important;margin:0!important;padding:5px!important;text-transform:none!important;box-sizing:border-box!important;font-family:Arial!important;text-shadow:none!important;box-shadow:none!important;white-space:nowrap!important}.moe-notification-image-wrapper-safari
img{height:65px!important;width:65px!important}</style>
</body>
warning |
Warning MoEngage recommends that you call the function |
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.
Here is the required HTML:
...
<head>
<!-- Your head elements-->
<!-- Initialize Moengage Web SDK here -->
<!-- CSS for soft ask -->
<style>#subscription-floating-button{position: fixed; display: flex; justify-content:
center; align-items: center; left: 15px; bottom: 15px; width: 4em; height: 4em;
line-height: 6em; background-color: white; border-radius: 1000px; cursor: pointer;
box-shadow: 0 5px 20px rgba(0,0,0,.3);}#subscription-floating-button:before{content:
""; position: absolute; left: 5px; top: 5px; bottom: 5px; right: 5px; border:
solid 2px #e54b4d; border-radius: 100%; opacity: .7;}#subscription-floating-button
img{max-width: 70%;}#subscription-floating-button #tooltip{position: absolute;
left: calc(100% + 15px); top: 50%; transform: translateY(-50%); line-height:
normal; white-space: nowrap; background-color: #000; color: white; font-family:
sans-serif; font-size: 14px; padding:.8em; border-radius: 5px; opacity: 0; -webkit-font-smoothing:
antialiased; transition: all .3s; pointer-events: none;}#subscription-floating-button
#tooltip:before{content: ""; position: absolute; width: 15px; height: 15px; background-color:
#000; left: -7px; top: 50%; margin-top: -8px; transform: rotate(45deg); user-select:
none;}#subscription-floating-button:hover img{animation: shake 0.82s cubic-bezier(.36,.07,.19,.97)
both;}#subscription-floating-button:hover #tooltip{opacity: 1;}@keyframes shake{10%,
90%{transform: rotate(-2deg);}20%, 80%{transform: rotate(3deg);}30%, 50%, 70%{transform:
rotate(-5deg);}40%, 60%{transform: rotate(5deg);}}</style>
</head>
<body>
<!-- DIV for soft ask -->
<div class="moe-main-class" style="display: none"> <div class="moe-allow-class"
id="subscription-floating-button"> <img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAwMAAAMDCAMAAADJ/DkRAAACQFBMVEUAAADlS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS03lS00b1kIHAAAAv3RSTlMAAQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSYnKCkqKywtLi8wMTIzNDU2Nzg5Ojs8PT4/QEF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/wHU8D0i4N3pEQAAAABJRU5ErkJggg=="
alt=""> <div id="tooltip">Subscribe to notifications</div></div></div>
<!-- Call Moengage WEB SDK Method -->
<script>
Moengage.call_web_push({
"soft_ask": true,
"main_class": "moe-main-class",
"allow_class": "moe-allow-class",
"block_class": "moe-block-class"
});
</script>
</body>
Sample Code for ask again of a soft ask
The sample code describes:
- When a user clicks Do not Allow
- Search for the
OPT_IN_SHOWN_TIME
in localstorage (MOE_DATA
)var moeData = localStorage.getItem('MOE_DATA') moeData = JSON.parse(moeData) var optInShownTime = moeData.OPT_IN_SHOWN_TIME // it is epoch time in milliseconds
- Check if
softAskStatus
isshown
ordismissed
and decide to display the soft ask based on theoptInShownTime
.var softAskStatus = moeData.OPT_IN_SHOWN_TIME // it can be one of these: shown, allowed, dismissed
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:
- Check the MoEngage dashboard whether you have configured domain type as `http` or `https` and the same is your application domain URL.
- You may be using some other Push notification provider and that serviceworker file is overlapping with MoEngage serviceworker file.
- Check the serviceworker file. It should contain the following code:
importScripts('https://cdn.moengage.com/webpush/releases/serviceworker_cdn.min.latest.js');
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.
Reach out to us directly from your MoEngage Dashbaord -> Need Help? -> Contact Support or send an email to support@moengage.com.