JavaScript API

Open the panel, read the unread count and listen to events from your code.

Once loaded, the widget exposes window.WhatsNew.

Method What it does
WhatsNew.open() Opens the panel and marks everything as read
WhatsNew.close() Closes the panel
WhatsNew.toggle() Opens or closes the panel
WhatsNew.unreadCount() The number of updates the visitor hasn't seen
WhatsNew.markAllRead() Marks everything as read without opening the panel
WhatsNew.on(event, listener) Listens to an event; returns a function that removes the listener
WhatsNew.destroy() Removes the widget and its badges from the page
WhatsNew.version The widget's version

Events

const stop = WhatsNew.on("unread", (count) => {
  document.title = count ? `(${count}) My app` : "My app";
});

WhatsNew.on("open", () => console.log("panel opened"));
WhatsNew.on("close", () => console.log("panel closed"));
WhatsNew.on("post_click", ({ id, url, title }) => console.log("read", title));

stop(); // remove the "unread" listener
Event Value
unread The new unread count, whenever it changes
open none
close none
post_click { id, url, title } of the update the visitor followed

Calling it before the script loads

The script loads asynchronously, so window.WhatsNew may not exist yet when your code runs. Define a queue first; the widget runs the queued commands as soon as it loads:

<script>
  window.WhatsNew = window.WhatsNew || { q: [], push(c) { this.q.push(c); } };

  WhatsNew.push(["on", "unread", (count) => updateMyBadge(count)]); // method name + arguments
  WhatsNew.push((wn) => console.log(wn.unreadCount()));           // or a function given the API
</script>
<script async src="https://cdn.whatsnew.xrisstech.com/w.js" data-key="pk_your_public_key"></script>

After the widget loads, WhatsNew.push() keeps working and runs commands right away. Loading the script twice keeps the first widget.

Coming soon

WhatsNew.identify({ id, sig }) for signed-in users: read state synced across devices and updates targeted to segments of your users.