Installations
npm install analytics-event-factory
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
18.20.6
NPM Version
10.8.2
Score
70.2
Supply Chain
98.2
Quality
85.6
Maintenance
100
Vulnerability
100
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (100%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
Download Statistics
Total Downloads
861
Last Day
2
Last Week
5
Last Month
29
Last Year
861
GitHub Statistics
22 Stars
84 Commits
1 Watchers
2 Branches
1 Contributors
Updated on Mar 06, 2025
Bundle Size
2.49 kB
Minified
910.00 B
Minified + Gzipped
Package Meta Information
Latest Version
1.1.0
Package Id
analytics-event-factory@1.1.0
Unpacked Size
16.21 kB
Size
5.26 kB
File Count
32
NPM Version
10.8.2
Node Version
18.20.6
Published on
Feb 09, 2025
Total Downloads
Cumulative downloads
Total Downloads
861
Dev Dependencies
5
analytics-event-factory
analytics-event-factory
is a lightweight and customizable library for standardizing analytics event creation and dispatch. It helps maintain a structured and consistent format for event metadata, making it easier to track user interactions and debug analytics pipelines.
🚀 Installation
1npm install analytics-event-factory
💡 Features
- Flexible event creation system.
- Easily configurable event metadata and labels.
- Supports callback functions for custom event processing.
- Page and element-based event standardization.
📖 Usage Example
1import { eventCreator } from "analytics-event-factory"; 2 3// Callback function to handle the event 4function logEvent(eventMetadata) { 5 console.log( 6 "\n---------------EVENT LOG-----------------\n", 7 JSON.stringify(eventMetadata, null, 2), 8 "\n-------------END OF EVENT LOG-------------\n" 9 ); 10} 11 12// Create an event handler 13const eventHandler = eventCreator({ 14 callback: logEvent, 15 options: { 16 page: { 17 showOnLabel: true, // optional, default is false if not provided 18 currentPage: "home", // optional, but only required if showOnLabel is true 19 showOnMetadata: true, // optional, default is false if not provided 20 }, 21 element: { 22 showElementIdOnLabel: true, // optional, default is false if not provided 23 }, 24 }, 25}); 26 27// Dispatching an event 28eventHandler.button.click({ 29 id: "btn-1", 30 timestamp: Date.now(), 31 description: "Button clicked", 32}); 33 34// Dispatching another event (without metadata) 35eventHandler.button.click();
Expected Output
1// return of the first event fired 2{ 3 "label": "home.button.click.btn-1", // pattern: [page].[element-type].[action].[element-id] 4 "metadata": { 5 "elementId": "btn-1", 6 "timestamp": 1739059943235, 7 "description": "Button clicked", 8 "page": "home", 9 } 10} 11 12// return of the second event fired 13{ 14 "label": "home.button.click", // pattern: [page].[element-type].[action] 15 "metadata": {} 16} 17
🔧 Configuration Options
The eventCreator
function accepts two primary configuration objects:
callback
A function that will be executed whenever an event is dispatched.
options
An object to customize event behavior.
Option | Type | Description |
---|---|---|
page.showOnLabel | boolean? | Show the page name in the event label. |
page.currentPage | string? | The current page name. |
page.showOnMetadata | boolean? | Include the page name in the event metadata. |
element.showElementIdOnLabel | boolean? | Show the element ID in the event label. |
📚 API Reference
eventCreator({ callback, options })
Creates an event handler with the given callback and configuration options.
Parameters
callback
: A function to handle dispatched events.options
: An object for configuration, as described in the table above.
Event Dispatch Methods
Each event handler provides functions to dispatch events by type (e.g., button.click
). Event metadata can be passed as an argument.
Metadata Structure
1{ 2 "label": "[page].[element-type].[action].[element-id]", // where page and element-id are optional 3 "metadata": { 4 "elementId": "[element-id]", // optional 5 "page": "[page]" // optional 6 // others metadata here 7 } 8}
🤝 Contributing
Feel free to open issues or submit pull requests if you find bugs or have suggestions for improvements.
📄 License
This project is licensed under the MIT License.

No vulnerabilities found.

No security vulnerabilities found.