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

@newtonschool/ns-events-library

v1.2.21

Published

newton school event library

Downloads

68

Readme

ns-events-library

The ns-events-library is a versatile React library that simplifies event tracking for various analytics providers, helping you gain valuable insights into user interactions in your React applications.

Installation

Before getting started, ensure that you have React version 18.2.0 or higher installed in your project. You can add the ns-events-library package to your project using npm:

npm install ns-events-library

Supported Analytics Providers

The ns-events-library seamlessly integrates with the following analytics providers:

Google Analytics
Clevertap
Amplitude
Mixpanel
Facebook
Taboola
Quora
Clarity
Microsoft

Event Types

The ns-events-library supports various event types to track user interactions and activities in your React application. You can use these event types when sending analytics events. Here are the available event types:

  CLICK: 'click'
  PAGE_LOAD: 'load'
  HOVER: 'hover'
  SCROLL: 'scroll'
  EVENT_SUCCESS: 'event_success'
  EVENT_FAILURE: 'event_failure'
  TIME_SPENT_ON_PAGE: 'time_spent_on_page'
  TIME_SPENT_ON_COMPONENT: 'time_spent_on_component'
  VIEW: 'view'
  KEY_DOWN: 'keydown'
  CUT: 'cut'
  COPY: 'copy'
  PASTE: 'paste'
  COMPONENT_LOAD: 'component_load'

Usage

1. Create a Context

Begin by creating a context to manage the sending of analytics events in your React application:

import { createContext } from 'react';

const SendAnalyticsEventContext = createContext();

2. Create a Custom Hook

Create a custom hook to facilitate the sending of analytics events in your application:

import { useContext, useCallback } from 'react';

export const useSendAnalyticsEvent = () => {
  const { trackingDataEnrichedEvent } = useContext(SendAnalyticsEventContext);

  const sendAnalytics = useCallback((event) => {
    const { eventType, eventName, eventData = {} } = event;
    trackingDataEnrichedEvent(eventType, eventName, eventData);
  }, []);

  return sendAnalytics;
};

3. Integrate with Your React App

In your React application, import the EventContext component from ns-events-library and wrap your app with it:

import { EventContext } from 'ns-events-library';

// ...

<EventContext
  contextProvider={SendAnalyticsEventContext}
  config={{
    courseHash: 'xyz', // Replace with your course hash
    userName: 'xyz',   // Replace with the user's name
    enabledList: [
      'GOOGLE_ANALYTICS',
      'CLEVERTAP'
      // Add other enabled providers from the list of supported analytics providers
    ],
    enabledData: [
      { accountId: 'add-tracking-id-here' },
      { accountId: 'add-tracking-id-here', softTrack: true },
      // Add tracking IDs for the enabled providers in the same order as enabledList
    ],
    // Pass useHistory hook to track URLs (if needed)
    history: useHistory(),
  }}
>
  {/* Your React app components go here */}
</EventContext>

If you don't have a userName or courseHash, you can pass empty strings or any default values that are appropriate for your use case.

4. Environment Variable for Production

For the production environment, make sure to add the following environment variable to your .env file:

NEXT_PUBLIC_NODE_ENV=production

5. Send Events

To send events, use the sendAnalytics function like this:

const sendAnalytics = useSendAnalyticsEvent();

sendAnalytics({
  eventType: 'click',
  eventName: 'button-clicked',
  eventData: {
    // Send data you want to be tracked.
  },
});

With these steps, your React application is ready to send analytics events to the selected providers effortlessly.

Remember to replace the placeholders with actual values or descriptions that are specific to your React library and its use cases.

Debugging Events

To enable debugging for events in your application, follow these steps:

Open your browser's developer tools.

Go to the "Application" tab.

In the "Local Storage" section, add a new key-value pair:

Key: debugEvents
Value: 1

This will enable event debugging, and you can inspect the event tracking in your browser's console for debugging purposes.