DEV Community

Cover image for Get push notifications from Javascript in just one minute!

Posted on

Get push notifications from Javascript in just one minute!

There have been many times when, as a developer, I wanted to be notified and track certain events that happened within my projects. For example, when a user joins a newsletter, creates an account, upgrades to a premium plan, or provides feedback.

LogSnag makes it very easy to set up these notifications and creates feeds of events so you can be aware of what happened and when it happened.

Getting Started

First, I will add a new project to my LogSnag account. Let's call it my-saas for this example.

Create a new project

Next, we need an API token. Head to the settings, open the API tab, and use the + button to create a new token. You can then use the clipboard icon to copy the token.

Copy your API Token

We are almost done! Let's move to our code!

Javascript Time!

First, let's install the LogSnag npm package

npm install --save logsnag

Then, we have to import the package and initialize our client with the API token that we just copied from the application.

import { LogSnag } from 'logsnag';

const logsnag = new LogSnag('MY_API_TOKEN')
Enter fullscreen mode Exit fullscreen mode

Finally, we can use our client to publish any events from our application.

For this example, I will call my channel waitlist as I would like to be notified and keep track of users who join my waitlist. Since this is the first time we publish to this channel, LogSnag will automatically create it for us.

I'm going to pass in the user email in the description and use the unicorn emoji as the icon. Most importantly, I will set notify to true since I would like to receive a push notification for this event.

    project: "my-saas",
    channel: "waitlist",
    event: "User Joined Waitlist",
    description: "email:",
    icon: "🦄",
    notify: true
Enter fullscreen mode Exit fullscreen mode

Once we run this code, a new channel is created under the my-saas project and we get push notifications for this event on all of the devices that have LogSnag installed!

LogSnag Notification

LogSnag has been a side project for the past couple of months. It has originated from the pain points of using messaging platforms to publish and track user activity and events. LogSnag has been explicitly designed for this purpose and provides powerful features that make it much easier to track events and projects. Currently, LogSnag is in the beta stage, and you can get access by signing up for the waitlist on the website.

Discussion (0)