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

@onthebarrelhead/lending-analytics

v0.17.7

Published

A package for NerdWallet's lending single threaded team (STT) that provides analytics tracking capabilities. This package is designed to be installed as an NPM module and requires all dependencies to be installed as peer dependencies.

Downloads

312

Readme

@onthebarrelhead/lending-analytics

A package for NerdWallet's lending single threaded team (STT) that provides analytics tracking capabilities. This package is designed to be installed as an NPM module and requires all dependencies to be installed as peer dependencies.

Docs

View the typedocs
View the example client
View the changelog

Installation

You can install this package using NPM with the following command:

yarn add @onthebarrelhead/lending-analytics

Usage

AnalyticsProvider

The AnalyticsProvider component is used to wrap your application with an analytics context that provides access to the analytics object. The component takes the following props:

  • deployableName (required): The name of the deployable.
  • deployableVersion (required): The version of the deployable.
  • writeKey (optional): The write key for Segment analytics. If this prop is not provided, analytics will be logged to the console instead.
  • debug (optional): A boolean value indicating whether debug information should be displayed.
  • children (required): The child components to be wrapped with the analytics context.

Example:

import { AnalyticsProvider } from '@onthebarrelhead/lending-analytics'

const App = () => {
  return (
    <AnalyticsProvider deployableName="MyApp" deployableVersion="1.0.0" writeKey="YOUR_SEGMENT_WRITE_KEY">
      <MyComponent />
    </AnalyticsProvider>
  )
}

useAnalytics

The useAnalytics hook provides access to the analytics object within a component wrapped by the AnalyticsProvider. Example usage:

import { useAnalytics } from '@onthebarrelhead/lending-analytics'

const MyComponent = () => {
  const { analytics } = useAnalytics()

  const handleClick = () => {
    analytics.track('Button Clicked')
  }

  return <button onClick={handleClick}>Click Me!</button>
}

AnalyticsPageView

The AnalyticsPageView component is used to track page views within your application. The component takes the following props:

  • name (optional): The name of the page view.
  • contentId (optional): The ID of the content being viewed.
  • contentSource (optional): The source of the content being viewed.
  • children (required): The child components to be tracked as part of the page view.

Example:

import { AnalyticsPageView } from '@onthebarrelhead/lending-analytics'

const MyPage = () => {
  return (
    <AnalyticsPageView name="My Page">
      <MyComponent />
    </AnalyticsPageView>
  )
}

useAnalyticsPageView

The useAnalyticsPageView hook provides access to the current page view context within a component wrapped by the AnalyticsPageView. Example usage:

import { useAnalyticsPageView } from '@onthebarrelhead/lending-analytics'

const MyComponent = () => {
  const { pageViewId, pageName } = useAnalyticsPageView()

  return (
    <div>
      <h1>{pageName}</h1>
      <p>Page view ID: {pageViewId}</p>
    </div>
  )
}

AnalyticsSkuViewed

The AnalyticsSkuViewed component is used to track SKU impressions within your application. The component takes the following props:

  • id: ID of the viewed SKU
  • source: Source of the viewed SKU
  • name: Name of the viewed SKU
  • productType: Type of product associated with the viewed SKU
  • level: Level of the viewed SKU
  • institutionId (optional): ID of the institution associated with the viewed SKU
  • institutionName (optional): Name of the institution associated with the viewed SKU
  • productId (optional): ID of the product associated with the viewed SKU
  • productName (optional): Name of the product associated with the viewed SKU
  • offerId (optional): ID of the offer associated with the viewed SKU
  • offerName (optional): Name of the offer associated with the viewed SKU
  • monetizable: Whether or not the viewed SKU is monetizable. This can also be overridden at the shopping finished level to provide more flexibility.
  • impressionSection: Section of the website or app where the SKU was viewed
  • impressionPosition: Position of the SKU within the impression section
  • children (optional): Either a JSX element or a function that takes an AnalyticsSkuViewedContextValue context object as an argument and returns a JSX element.

Example:

import { AnalyticsSkuViewed } from '@segment/analytics-react'

function ProductPage({ product }) {
  return (
    <AnalyticsSkuViewed
      id="097a5c08-4339-11ea-8c79-8bd12b91c634"
      name="Chase Freedom Unlimited Card"
      productType="credit_cards"
      level="offer"
      source="marketplace"
      productId="253b9c27-2948-12cb-8c79-8bd12b122c581"
      product_name="Freedom Unlimited Card"
      monetizable="yes_assumed"
      institutionId="124b6c08-1237-11ea-8c79-8bd12b12d429"
      institutionName="Chase"
      impressionSection="Best Credit Card Roundup"
      impressionPosition={2}
    >
      {({ fireShoppingFinishedEvent }) => {
        return (
          <ProductCard>
            <Button
              href={cta.url}
              onClick={() => {
                fireShoppingFinishedEvent({
                  monetizable: cta.monetizable,
                  destinationUrl: cta.url,
                  ctaType: 'APPLY_NOW'
                })
              }}
            >
              Apply Now
            </Button>
          </ProductCard>
        )
      }}
    </AnalyticsSkuViewed>
  )
}

Versioning

Changesets is an npm module that helps with managing semantic versioning for packages. It provides a command-line interface (CLI) for creating and managing "changesets" – small files that describe changes made to a package since the last release. Changesets can be thought of as "mini-changelogs" that provide a clear and concise summary of the changes made to a package.

  1. When contributing, use yarn changeset to describe your changes. The cli will walk you through the options and a summary.
yarn changeset
  1. When ready to release, run: yarn changeset:version to automatically rev our package.json and generate a changelog