Gathering detailed insights and metrics for analytics-event-factory
Gathering detailed insights and metrics for analytics-event-factory
Gathering detailed insights and metrics for analytics-event-factory
Gathering detailed insights and metrics for analytics-event-factory
npm install analytics-event-factory
Typescript
Module System
Node Version
NPM Version
TypeScript (94.35%)
JavaScript (5.65%)
Total Downloads
1,003
Last Day
1
Last Week
3
Last Month
34
Last Year
1,003
22 Stars
97 Commits
1 Watchers
2 Branches
1 Contributors
Updated on Apr 21, 2025
Minified
Minified + Gzipped
Latest Version
2.0.0
Package Id
analytics-event-factory@2.0.0
Unpacked Size
27.82 kB
Size
7.36 kB
File Count
41
NPM Version
10.8.2
Node Version
18.20.8
Published on
Apr 21, 2025
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
-80%
3
Compared to previous week
Last Month
-63.8%
34
Compared to previous month
Last Year
0%
1,003
Compared to previous year
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.
1npm install analytics-event-factory
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();
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
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. |
eventCreator({ callback, options })
Creates an event handler with the given callback and configuration options.
callback
: A function to handle dispatched events.options
: An object for configuration, as described in the table above.Each event handler provides functions to dispatch events by type (e.g., button.click
). Event metadata can be passed as an argument.
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}
Feel free to open issues or submit pull requests if you find bugs or have suggestions for improvements.
This project is licensed under the MIT License.
No vulnerabilities found.
No security vulnerabilities found.