npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@perceptinsight/percept-node

v1.0.6

Published

The official Percept NodeJS library

Downloads

25

Readme

percept-node

Official Percept NodeJS library

Quick Start Guide

1. Install

npm install @perceptinsight/percept-node
or
yarn add @perceptinsight/percept-node

2. Initialize Percept SDK

import Percept from '@perceptinsight/percept-node';

Percept.init('Your Project Token');

init method takes an optional initOptions param as second argument. initOptions properties:

| property | required | default value | | ---------------------- | -------- | ------------- | | autoFlushBatchSize | false | 50 | | autoFlushThresholdMs | false | 5000 | | maxApiRetry | false | 2 |

3. Capture Event

Let's get started by sending event data. You can send an event from anywhere in your application.

// Track only event-name. Second argument is the distinct user id. Pass it as undefined if it is not available. We use this id for all user analysis
Percept.capture('Referral Banner Click', 'USER123');

// Track event-name with property
Percept.capture('Screen View', 'USER123', {'screenName': 'Homepage'});

These calls are queued and flushed on regular interval based on the duration and batch size specified while initialising the sdk.

4. Capture Bulk Events

You can bypass the queue and capture multiple events in bulk with this call

await Percept.bulkCapture([
    {
        eventName: 'Page Viewed',
        properties: {
            'screenName': 'Homepage'
        }
    },
    {
        eventName: 'Order Placed',
        properties: {
            'orderId': 'order123f31',
            'totalAmount': '1200'
        }
    }
], 'USER123');

The response is returned in this call, so that you can handle retry on failures. As such we suggest you to use this with await

5. Set user properties

use setUserProperties method to set properties on the user profile

// sets user `isVerifiedAccount` property to true
Percept.setUserProperties('USER123', {isVerifiedAccount: true})

We expose some default user property keys in PERCEPT_DEFAULT_USER_PROPERTIES_KEYS. Please use them as this helps in standarization and usage in the Engage feature provided by Percept.

import Percept, {PERCEPT_DEFAULT_USER_PROPERTIES_KEYS} from '@perceptinsight/percept-js'

// sets user `phone` property to '123456789' and `isVerifiedAccount` property to true
Percept.setUserProperties('USER234', {[PERCEPT_DEFAULT_USER_PROPERTIES_KEYS.PHONE]: 123456789, isVerifiedAccount: true})

6. Manually flush the queue

Percept inner events processing queue can be manually flushed by calling this method

Percept.flushPendingEvents();

7. Shut down

Call shutdown function before closing the server to flush any pending events in queue

await Percept.shutDown()

This flushes the events queue and resets the token.