DEV Community

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

Posted on

2 2 1 1 1

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.

logsnag.publish({
    project: "my-saas",
    channel: "waitlist",
    event: "User Joined Waitlist",
    description: "email: john.doe@yahoo.com",
    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.

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay