zoomianalytics
v1.1.26
Published
A JavaScript/TypeScript library for tracking and sending analytics events.
Downloads
50
Readme
ZoomiAnalytics
ZoomiAnalytics is a JavaScript/TypeScript library for tracking user activities and sending analytics events to a specified server endpoint. It helps you collect data on user interactions with various types of content (e.g., videos, podcasts, text) and track events like starting, pausing, and completing content.
Features
- Track user events such as
start,end,play,pause, etc. - Support for multiple content types, including video, podcast, text, and more.
- Events are sent in batches to a configurable server endpoint.
- Supports automatic event sending upon page navigation or tab/browser closure.
- Configurable batch size and event retry logic.
- Collect detailed playback data like
currentPosition,isPlaying, andcurrentPlaybackRate. - Handles navigation changes (e.g.,
window.location.pathname) and tab closure to ensure events are sent before the page is unloaded.
Installation
To install ZoomiAnalytics via npm, use the following command:
npm install zoomianalyticsUsage
Initialization Before you can start tracking events, initialize the ZoomiAnalytics instance with your API key and the server endpoint URL.
import ZoomiAnalytics from "zoomianalytics";
const apiKey = "your-api-key";
const apiName = "your-api-name"; // Name of the API that will process the events
const analytics = new ZoomiAnalytics(apiKey, apiName);Track Events
You can track events by calling the trackEvent() method. The trackEvent method requires an event object with the following properties:
- userId: The ID of the user triggering the event.
- courseId: The ID of the course being interacted with.
- courseItemId: The ID of the content item (e.g., video, podcast).
- contentType: The type of content being interacted with. Possible values are Video, Podcast, Text, Course, etc.
- courseTitle: The title of the course (optional).
- eventType: The type of event (e.g., start, end, pause, complete).
- currentPosition: The current playback position in the content.
- isPlaying: Whether the content is currently playing.
- currentPlaybackRate: The playback rate of the content.
- newPosition: The new position after a change in the content.
const event = {
userId: 123,
courseId: 456,
courseItemId: 789,
contentType: ContentItemTypes.Video (|| 0),
eventType: EventTypes.Play (|| 3),
currentPosition: 120,
isPlaying: true,
currentPlaybackRate: 1.0,
newPosition: 130,
courseTitle: 'Couse Name',
contentDuration: 456.5 (value in seconds)
};
analytics.trackEvent(event);