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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@zenfi/js-sdk

v1.3.3

Published

JS SDK for Zenfi partners

Downloads

7

Readme

Zenfi JavaScript SDK

JavaScript SDK for Zenfi partners. Useful to:

  • Auto-fill inputs with user data, making forms completion easier.
  • Track lead events (register, clicks, etc).

Usage

NodeJS

Install with npm or yarn:

npm install --save zenfi-sdk

Browser

Add the following script to your project:

<!-- Latest version -->
<script src="https://cdn.jsdelivr.net/gh/zenfi/js-sdk@main/dist/index.js" type="text/javascript"></script>

<!-- Or specify a version -->
<script src="https://cdn.jsdelivr.net/gh/zenfi/js-sdk@v1.3.3/dist/index.js" type="text/javascript"></script>

<!-- This will export a variable named "ZenfiSDK": -->
<script type="text/javascript">
  var zenfi = new ZenfiSDK(...args);
  zenfi.fillTargets();
</script>

API

new ZenfiSDK(...)

Creates a new instance of the Zenfi SDK.

Parameters

| Parameter | Type | Default value | Description | | --------- | ---- | - | ----------- | |cookiesDomain|String|-|The domain space where the cookies will be available. When this value is empty, cookies will be only accessible in the current domain / subdomain.| |partnerName|String|-|The name of the platform which implements this code. This parameter is required to send events to the Zenfi API.| |targets|[Object]|[]|The list of html elements and their configuration to be filled.| |targets.dataKey|String|-|The name of the key in the leadInfo object which contains the information to be filled.| |targets.selector|String | Function|-|The css selector to find the element in the DOM. If a function is passed, it will receive an object with { dataKey, strategy, value } as param properties and must return a string with the css selector.| |targets.strategy|Enum(value | text | click)|value|Indicates the type of strategy to fill the DOM element. Possible values are: value: sets the value property of an input, text: puts the content inside the HTML tag as text, used for <div />s, click: triggers a click on the DOM element.| |targets.beforeAction|Function|-|An optional function that is executed before the target is filled. It will receive an object with { selector, strategy, value } properties.| |targets.afterAction|Function|-|An optional function that is executed after the target is filled. It will receive an object with { element, selector, strategy, value } properties (element is the DOM node being filled).|

Example

const zenfi = new ZenfiSDK({
  partnerName: 'credifast',
  cookiesDomain: 'credifast.com',
  targets: [
    {
      dataKey: 'name',
      strategy: 'html',
      selector: '#nameInput',
    },
    {
      dataKey: 'email',
      strategy: 'value',
      selector: ({ dataKey }) => `#${dataKey}Input`,
      beforeAction: () => console.log('before filling info'),
      afterAction: ({ element }) => element.classList.add('changed'),
    },
  ],
});

.fetchData()

Fetches the lead information from the Zenfi API.

Parameters

This function takes no parameters.

Example

const zenfi = new ZenfiSDK();
await zenfi.fetchData();

console.log(zenfi.leadInfo);
/*
Prints:

{
  name: 'Chewbacca',
  email: 'chewy@lucasfilm.com'
}

*/

.fillTargets()

Auto-fills the labels and inputs specified in the targets configuration. It also fetches the lead information from the Zenfi API, if information is not available yet.

Parameters

This function takes no parameters.

Example

const zenfi = new ZenfiSDK({
  targets: [
    {
      dataKey: 'name',
      selector: '#nameInput',
      strategy: 'html',
    },
    {
      dataKey: 'email',
      strategy: 'value',
      selector: ({ dataKey }) => `#${dataKey}Input`,
      afterAction: ({ element }) => element.classList.add('changed'),
    },
  ]
});
await zenfi.fillTargets();
// It will fill the #nameInput and #emailInput nodes automatically.

.trackConversion(name, properties)

Sends a conversion event to the Zenfi API (the user is moving forward in the funnel): https://api.zenfi.mx/webhooks/leads/:partner/converted.

Parameters

| Parameter | Type | Description | | --------- | ---- | ----------- | |name|String|Any descriptive name for the event to be tracked (eg. register, click, addToCart).| |properties|Object|Any data related with the event to be tracked.|

Example

zenfi.trackConversion('addToCart', {
  price: 100,
  amount: 2,
});
// It will track a "addToCart" event

.trackAbortion(name, properties)

Sends an abortion event to the Zenfi API (the user was rejected and can not move forward in the funnel): https://api.zenfi.mx/webhooks/leads/:partner/aborted.

Parameters

| Parameter | Type | Description | | --------- | ---- | ----------- | |name|String|Any descriptive name for the event to be tracked (eg. rejected, declinedOffer).| |properties|Object|Any data related with the event to be tracked.|

Example

zenfi.trackConversion('declinedOffer', {
  reason: 'User got a better interest rate elsewhere'
});
// It will track a "declinedOffer" event

.trackPageView()

Sends an conversion event with name "PageView" to the Zenfi API. It includes metadata about the visited URL: href, hash, search, protocol, hostname and pathname.

Parameters

This function takes no parameters.

Example

zenfi.trackPageView();
// It will track a "PageView" event

.initPageViewsTracking()

Starts a listener that tracks page view events automatically.

Parameters

This function takes no parameters.

Example

zenfi.initPageViewsTracking();
// Listens to url changes and sends events

License

MIT