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

@convertnative/browser-sdk

v1.0.1

Published

JavaScript library to track events and receive push notifications with ConvertNative.

Downloads

2

Readme


Get started

Option A. Install as npm package

  1. Install the browser SDK package.
    npm install @convertnative/browser-sdk
    # or
    yarn add @convertnative/browser-sdk
  2. Import and initialize the client.
    import Client from "@convertnative/browser-sdk";
    
    const client = new Client({
      workspaceId: 'YOUR_WORKSPACE_ID',
      publicKey: 'YOUR_WORKSPACE_PUBLIC_KEY',
    })
    // use the client here

Option B. Add the ConvertNative snippet

  1. Add the script tag.
    <script async src="https://cdn.convertnative.com/sdks/browser/v1/browser.js"></script>
  2. Initialize the client.
    <script>
     window._convertNative = []
     window._convertNative.push(function (ConvertNative) {
       const client = new ConvertNative({
         workspaceId: 'YOUR_WORKSPACE_ID',
         publicKey: 'YOUR_WORKSPACE_PUBLIC_KEY',
       })
       // use the client here
     })
    </script>

Enabling push notifications

To enable push notifications you will need to setup a service worker. If you need any assistance please contact your account manager.

  1. Create the file sw.js with the content below.
    importScripts('https://cdn.convertnative.com/sdks/browser/v1/service-worker.js')
  2. Register the service worker through the ConvertNative client.
    await client.registerServiceWorker({scriptURL: 'sw.js'})
  3. Subscribe to push notifications.
    await client.pushNotifications().subscribe()
    console.log('subscribed!')

Tracking events

List of trackable events

[!TIP] Don't hesitate to check event payload definitions here.

  • pageViewed
  • productViewed
  • searchSubmitted
  • categoryViewed
  • productAddedToCart
  • productRemovedFromCart
  • cartViewed
  • checkoutStarted
  • checkoutShippingInfoCompleted
  • checkoutBillingInfoCompleted
  • checkoutCompleted

Examples

// Track a page view
client.events().pageViewed()

// Track search submitted
client.events().searchSubmitted({ query: 'Sneakers' })

// Track product added to cart
client.events().productAddedToCart({
   productID: '1',
   productName: 'Product A',
   productURL: 'https://...',
   variantID: '1-red',
   variantName: 'Red',
   quantity: 1,
   unitPrice: '12.43'
})

Set user details

[!NOTE]
User details are not stored and must be set on every ConvertNative client instantiation.

// Set details
client.events().setUserDetails({
   id: 1,
   email: '[email protected]',
   firstName: 'John',
   lastName: 'Doe',
})
// Clear user details
client.events().setUserDetails(null)