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

cptn-browser

v1.0.7

Published

Browser JS library for sending events to cptn.io ingestion API

Downloads

13

Readme

GitHub

cptn-browser

JS library for sending tracking events from browser clients to cptn.io instance's Source end point.

This library is not intended to be used with NodeJS applications.

Usage

Embed into web pages

Add the following code snippet to web pages. Change the <Ingestion url> and <key> values to appropriate values for your Source end point.

<script>
    (function () {
        var script = document.createElement('script');
        script.src = 'https://unpkg.com/cptn-browser/dist/browser.js';
        script.onload = function () {
            window.cptn = new Cptn({ url: '<Ingestion url>', key: '<key>' });
        };
        document.head.appendChild(script);
    })();
</script>

Use as a NPM module:

npm install cptn-browser 

Use as ES module

import Cptn from 'cptn-browser';

const cptn = new Cptn({url:"<Ingestion url>", key:"<key>"});
cptn.capture({
    "type": "click",
    "element": "add_to_cart"
});

//key is optional if the source url is unsecured

Use as CommonJS module

const Cptn = require('cptn-browser');

const cptn = new Cptn({url:"<Ingestion url>", key:"<key>"});
cptn.capture({
    "type": "click",
    "element": "add_to_cart"
});

//key is optional if the source url is unsecured

Supported methods:

capture

Send custom captured events

cptn.capture(type, properties);

//Following payload will be sent along with common attributes
{
    type,
    properties
}

page

Track page load events

cptn.page(category, name, properties);

//Following payload will be sent along with common attributes
{
    type:"page",
    category,
    name,
    properties
}

screen

Track screen view events

cptn.screen(name, properties);

//Following payload will be sent along with common attributes
{
    type:"screen",
    name,
    properties
}

identify

Send identify event and associate userId for all subsequent events

cptn.identify(userId, properties);

//Following payload will be sent along with common attributes. UserId will be part of common attributes
{
    type:"identify",    
    properties
}

Note: userId value will also be persisted to cookies and will be automatically associated for subsequent events until clearIdentity is invoked.

group

Send group event and associate groupId for all subsequent events

cptn.group(groupId, properties);

//Following payload will be sent along with common attributes. UserId will be part of common attributes
{
    type:"group", 
    groupId,
    properties
}

track

Send track event with custom details

cptn.track(event, properties);

//Following payload will be sent along with common attributes.
{
    type:"track", 
    event,
    properties
}

clearIdentity

clears the currently set userId, groupId and removes userId cookie

cptn.clearIdentity()

AnonymousId

All events sent will have an anonymousId value. This value is generated if not present and will be persisted to cookies. All subsequent events will use the same anonymousId until the cookies are cleared.

Common Attributes:

Following are the common attributes part of the events captured:

    {
        ...event,
        anonymousId,
        timestamp: new Date().toISOString(),
        userId,
        context: {
            userAgent: window?.navigator?.userAgent,
            page: {
                url: window?.location?.href,
                referrer: window?.document?.referrer,
                title: window?.document?.title,
                path: window?.location?.pathname,
                search: window?.location?.search,
                hash: window?.location?.hash,
            },
            screen: {
                width: window?.screen?.width,
                height: window?.screen?.height,
            },
            locale: window?.navigator?.language,
            timezone: Intl?.DateTimeFormat()?.resolvedOptions()?.timeZone,
            tzOffset: new Date().getTimezoneOffset(),
            groupId
        }
    }

IP tracking

cptn.io supports capturing user ip address starting with Cupertino release (coming up soon). When enabled, the inbound event will be enriched with the remote IP address as below.

{
    ...event,
    cptn {
        remote_ip
    }
}

User privacy and GDPR compliance

This library uses cookies to persist anonymousId and passed userId information. Obtaining consent from the user is not in scope for this project and it must be determined by your application.

You application must make the determination to ask for user consent and then instantiate or load the library into your web page after user consent.