HomeGuidesAPI Reference
Submit Documentation FeedbackJoin Developer CommunityLog In

Web Push

This topic describes web push initialization in Optimizely Data Platform (ODP).

Advanced Initialization

If you want to create your own web push subscribe experience, ODP supports custom initialization options.

To manually handle Web Push initialization (instead of automatically initializing) go to step 5 of Web Push wizard within ODP: Account Settings -> Integrations -> Web Push.

๐Ÿ“˜

Note

Integration of web push will not be marked as "live" but should be configured.

Display Subscription Modal on Specific Page

In JavaScript on your website, AFTER ODP is initialized, perform any JS logic and call this when you are ready to show the subscription UI:

{
    "codes": [{
        "code": "zaius.dispatch('webPush', 'initialize', {websiteID: ''})",
        "language": "javascript",
        "name": "Show Subscribe"
    }]
}

๐Ÿšง

Important

websiteID is the name given in the web push subscribe setup, NOT your tracker_id.

Custom Initialization

In JavaScript on website, AFTER ODP is initialized, perform any JS logic and call this when you are ready to show the subscription UI:

zaius.dispatch('webPush', 'initialize', 
               {websiteID: '<ZAIUS_WEBSITE_ID>', 
                subscribeUI: {enabled: false}}
              );

//Then, check the subscription status before showing your subscription UI:
zaius.dispatch('webPush', 'subscriptionStatus', function(status, token) {
  if (status !== 'subscribed' && status !== 'denied') {
    // show subscribe UI
  }
});

//Finally, when you want the browser to ask the user to allow push notifications call:
zaius.dispatch('webPush', 'askToSubscribe');

Did this page help you?