@voicenter-team/lead-tracker
v1.0.4
Published
LeadTracker is a comprehensive library for managing lead tracking, collecting user data, automating web actions, and generating DIDs to effectively track and manage call leads.
Downloads
752
Readme
title: Getting started navigation: title: Getting Started
Lead Tracker Library
Overview
The LeadTracker library is designed to streamline lead tracking on your website by collecting user information, handling API calls, generating DIDs to track call leads, and automating actions based on specified configurations. This document provides an overview of the library, its installation, usage, and detailed descriptions of its types and methods.
Installation
To install the Lead Tracker Library, simply include the library file in your project:
<script src="https://mirrored-lead-tracker-cdn.pages.dev/lead-tracker.umd.js"></script>
Or, if you're using a module bundler, you can install it via npm:
npm install @voicenter-team/lead-tracker
Usage Example
import LeadTracker, { InitOptions } from '@voicenter-team/lead-tracker';
const defaultOptions: InitOptions = {
cookiesAllowed: false,
actions: {
call: [
{ selector: '.call-me' },
{ selector: '#callMe' },
{ selector: '#callMeMobile', activeMaxWidth: 768 }
],
href: [
{ selector: '.replace-my-href' },
{ selector: '#replaceMyHref' },
{ selector: '#replaceMyHrefMobile', activeMinWidth: 768 }
]
}
};
const leadTracker = new LeadTracker({
autoRefreshDID: true,
silent: false,
token: 'your-api-token'
});
leadTracker.init({ ...defaultOptions }).then(async () => {
await leadTracker.actionsProceed();
await leadTracker.saveLeadInfo();
document.getElementById('getAllQuery')?.addEventListener('click', async () => {
const queryParams = await leadTracker.getLeadInfo();
console.log('Query params:', queryParams);
alert('Check the console for the query params');
});
document.getElementById('getDID')?.addEventListener('click', async () => {
const did = await leadTracker.getDID();
console.log('DID:', did);
alert('Check the console for the DID');
});
document.getElementById('updateOptions')?.addEventListener('click', async () => {
await leadTracker.proceed({
cookiesAllowed: true,
actions: {
text: [
{ selector: '.replace-me' },
{ selector: '#replaceMe' },
{ selector: '#replaceMeMobile', activeMinWidth: 768, activeMaxWidth: 1024 }
]
}
});
alert('Options updated');
});
document.getElementById('clearOptions')?.addEventListener('click', async () => {
localStorage.clear();
await leadTracker.proceed({ ...defaultOptions, baseInfo: { prikoldesc: 'PrikolDesc' } });
alert('Options cleared');
});
})
So first, you need to create a new instance of the LeadTracker class with the required options.
Then, you can proceed with the initialization by calling the proceed
method with the desired options.
The LeadTracker, in order to optimize the performance, will not generate DID if it is not required.
API Reference
LeadTracker Class
Constructor
constructor(options: LeadTrackerConfig)
options
- Configuration options for LeadTracker.
Methods
getLeadInfo()
: Returns a promise that resolves with an array of query parameters.saveLeadInfo()
: Saves collected information via the API handler.getDID()
: Returns a promise that resolves with the DID (phone number).init(options: Partial<InitOptions>)
: Initializes the lead tracker.setOptions(options: Partial<InitOptions>)
: Updates the options.actionsProceed()
: Processes actions.
LeadTracker Types
LeadTrackerConfig
| Property | Type | Default | Description |
|------------------|-------------|---------|-------------------------------------------------------------|
| token
| string | - | The JWT token for the API. |
| silent
| boolean | true | If set to true, will not log any messages. |
| autoRefreshDID
| boolean | false | If true, will automatically refresh the DID upon expiration |
InitOptions
| Property | Type | Default | Description |
|-------------------|----------|---------|----------------------------------------------------------------------------|
| cookiesAllowed
| boolean | false | If true, will allow cookies. |
| actions
| object | - | Actions configuration. Refer to ActionsConfig |
| baseInfo
| object | - | Additional information to be sent with the API request. Accepts any object |
ActionsConfig
| Property | Type | Default | Description |
|----------|----------|---------|------------------------------------------------------------------------------------------------------|
| call
| object[] | - | Array of objects with selectors for call actions. Refer to SelectorConfig |
| href
| object[] | - | Array of objects with selectors for href actions. Refer to SelectorConfig |
| text
| object[] | - | Array of objects with selectors for text actions. Refer to TextSelectorConfig |
SelectorConfig
| Property | Type | Default | Description |
|------------------|--------|---------|--------------------------------------------|
| selector
| string | - | CSS selector for the element. |
| activeMinWidth
| number | - | Minimum width for the action to be active. |
| activeMaxWidth
| number | - | Maximum width for the action to be active. |
TextSelectorConfig - extends SelectorConfig
| Property | Type | Default | Description |
|----------|--------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| mask
| string | - | An optional property that specifies a format mask for the input value. The mask uses #
to represent numerical values and any other character will be displayed as-is. For example, a mask of ###-####-##.#
applied to the input 12345678901
will format the result as 123-4567-89.01
. This is useful for standardizing the appearance of numerical inputs. |
Contributing
Contributions to the Lead Tracker Library are welcome! If you encounter any issues or have suggestions for improvements, please open an issue or submit a pull request on the GitHub repository.
License
The Lead Tracker Library is open-source software licensed under the MIT license.