rozmova-analytics v1.1.1
rozmova-analytics
A lightweight JavaScript analytics library designed to streamline event tracking, user identification, and common analytics parameter management. This package integrates with Mixpanel and Google Analytics to provide seamless data collection and insights.
Installation
Install the package using npm:
npm install rozmova-analytics
Alternatively, you can include the library via jsDelivr to use in browser:
<script src="https://cdn.jsdelivr.net/npm/rozmova-analytics/dist/index.umd.js"></script>
Usage
Import the library in your project and initialize it:
import {
generateUserId,
getCommonParams,
getUserId,
init,
resetUser,
setUser,
trackEvent,
setLocale,
} from "rozmova-analytics";
// Initialize the library
init({ locale: "en", platform: "web", isClearly: true });
// Set user
setUser("user-id-123", { email: "user@example.com", name: "John Doe" });
// Track an event
trackEvent("button_click", { button_name: "Sign Up" });
Or use in browser:
// Initialize the library
window.Analytics.init({ locale: "en", platform: "web" });
// Set user
window.Analytics.setUser("user-id-123", {
email: "user@example.com",
name: "John Doe",
});
// Track an event
window.Analytics.trackEvent("button_click", { button_name: "Sign Up" });
API
init(initParams:{locale?: string, platform?: string})
Initializes the analytics library, setting up Mixpanel and Google Analytics integrations. Optionally, set a locale and platform.
generateUserId()
Generates a unique user ID, stores it in cookies and localStorage, and returns the ID.
getUserId()
Retrieves the user ID from cookies, localStorage, or URL query parameters. If not found, generates a new one.
getCommonParams()
Returns an object with common analytics parameters such as device, browser, referrer, and UTM parameters.
setLocale(newLocale: string)
Sets the locale for analytics data.
setUser(userId: string, userParams: { email: string; name: string })
Associates a user with the provided user ID and sets user properties in Mixpanel and Google Analytics.
resetUser()
Resets the current user, generating a new user ID and reinitializing the library.
trackEvent(eventName: string, properties?: EventParams, services = {ga: true, mixpanel: true, customerIO: true})
Tracks an event with the specified name and optional properties, services.
Browser Support
The package works on modern browsers and supports the following:
- Chrome
- Firefox
- Safari
- Edge
Example Integration
import { init, trackEvent, setUser, resetUser } from "rozmova-analytics";
// Initialize analytics
init({ locale: "en", platform: "ios", isClearly: true });
// Track a page view event
trackEvent("page_view", { page: "Home" });
// Set user details
setUser("user-456", { email: "user456@example.com", name: "Jane Doe" });
// Reset the user
resetUser();
Contributing
Contributions are welcome! Please fork the repository and create a pull request with your changes.
License
This project is licensed under the MIT License.
5 months ago
5 months ago
5 months ago
5 months ago
5 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
6 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago
7 months ago