0.0.2 • Published 1 year ago

@symplify.com/webpush v0.0.2

Weekly downloads
-
License
-
Repository
-
Last release
1 year ago

Symplify Web Push

What is it and what can I use it for?

Symplify Web Push messaging enables you to Pop Up when your customer is on site. You can for example use Symplify Web Push to inform selected customers that they have an active offer available, tips and tricks within the platform or showcasing features based on the recipient profile.

You can of course personalize all messages and use the different Symplify modules, like Journeys and Campaigns to generate your Symplify Web Push messages.

  • Create welcome messages for new users with link and instructions for navigating the app or best use the application
  • Send a reminder that pops up after login so they remember to complete their registration with credit card, loyalty card and shipping address etc.
  • Showcase new features and encourage users to try them out
  • Send coupons and offers
  • Remind customers of abandoned carts or loyalty credits on their accounts
  • Offer order tracking after sales

How to identify the recipient

We need a secret identifier that is used when connecting to the Symplify Web Push service. The secret is a securely hashed signature created by calling our REST API with the id of your contact. If the contact is present in any of your lists in Symplify, we will return a hash which you can use to connect to the contact's inbox.

NOTE: Since communicating with our REST API is done on the server side, this will require some development on your side. Read about using our API here

A basic usage pattern is:

  • The user logs in to your site.
  • Once you know the id of your user, call our user hash resource.
  • Cache the user hash in your web server session storage or in your database.
    • Do not call the user hash resource for every page.
    • User hashes are valid for 90 days.
  • Include the script on pages where Symplify Web Push messages should be displayed.

Secure user hashes are generated using the REST resource /webpush.

POST /rest/{customerid}/webpush
{
  "contactId": "the id of the user in your database", (originalId in Symplify)
  "privacyLevel": "SENSITIVE|NOT_SENSITIVE" (defaults to SENSITIVE)
}

An example response would look like

{
  "userHash": "e94187765acfe001e415107c68f6a6fd5e74b66042145fe28609787b2e881b67"
}

Install

npm install @symplify.com/webpush

or

yarn add @symplify.com/webpush

API

Types:

interface Message {
  id: string;
  userId: string;
  hasBeenRead: boolean;
  subject: string;
  body?: string;
  loadBody: () => void;
  deleteMessage: () => void;
  markRead: () => void;
}

Methods:

start(userHash: string): void

stop(): void

subscribeToPush(): void

unsubscribeFromPush(): void

isPushDisabled(): boolean

onIncomingMessage(callback: (message: Message) => void): void

offIncomingMessage(callback: (message: Message) => void): void

onMessage(callback: (messages: Message[]) => void): void

offMessage(callback: (messages: Message[]) => void): void