pulsex
Version:
A lightweight and powerful JavaScript library for tracking user activity on websites. Easily monitor user interactions, including page visits, clicks, time spent, and engagement patterns. Designed for flexibility and performance, PulseX integrates seamles
70 lines (69 loc) • 2.64 kB
TypeScript
import { PulseXConfig, EventPayload } from "./types";
export default class PulseX {
private config;
private sessionId;
private queue;
private engagementTrackingTasks;
constructor(config: PulseXConfig);
start(): void;
/**
* Tracks user engagement for a specific section of the webpage.
*
* @param {string} sectionId - The ID of the HTML element to track.
* @param {number} [threshold] - The minimum time (in milliseconds) the user must view the section for it to be considered engaged.
*
* @remarks
* - If the element with the given `sectionId` is not found, a warning will be logged.
* - The section will be added to the tracking list, and engagement will be recorded only if the user views it for at least `threshold` milliseconds.
* - If `threshold` is not provided, it may default to a predefined value in the tracking system.
*
* @example
* ```ts
* tracker.trackSectionEngagement("homepage", 3000); // Track "homepage" section with a 3-second threshold
* ```
*/
trackSectionEngagement(sectionId: string, threshold?: number): void;
private startEngagementTracking;
private createBasePayload;
private getQueue;
private sendData;
private setupVisibilityListener;
private saveQueueToLocalStorage;
private clearQueue;
private loadQueue;
/**
* Tracks click events on a specified element.
*
* @param {string} elementId - The ID of the element to track clicks on.
*
* @example
* ```ts
* tracker.trackClick("loginBtn"); // Tracks click events on element with ID 'loginBtn'
* ```
*/
trackClick(elementId: string): void;
/**
* Tracks hover events on a specified element.
* Records hover duration and, if a click occurs during the hover, includes the click data.
*
* @param {string} elementId - The ID of the element to track hover events on.
*
* @example
* ```ts
* tracker.trackHover("product-card"); // Tracks hover events on element with ID 'product-card'
* ```
*/
trackHover(elementId: string): void;
/**
* Tracks form submission events on a specified form.
*
* @param {string} formId - The ID of the form to track submissions for.
*
* @example
* ```ts
* tracker.trackFormSubmission("login-form"); // Tracks form submissions on form with ID 'login-form'
* ```
*/
trackFormSubmission(formId: string): void;
savePayloadToLocalStorage(payload: EventPayload): void;
}