1.1.1 • Published 5 months ago

rozmova-analytics v1.1.1

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

rozmova-analytics

npm-version minified-size

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.

1.1.1

5 months ago

1.1.0

5 months ago

1.0.29

5 months ago

1.0.28

5 months ago

1.0.27

5 months ago

1.0.26

6 months ago

1.0.25

6 months ago

1.0.24

6 months ago

1.0.23

6 months ago

1.0.22

6 months ago

1.0.21

6 months ago

1.0.20

6 months ago

1.0.19

6 months ago

1.0.18

6 months ago

1.0.17

6 months ago

1.0.16

6 months ago

1.0.15

6 months ago

1.0.14

6 months ago

1.0.13

6 months ago

1.0.12

6 months ago

1.0.11

6 months ago

1.0.10

6 months ago

1.0.9

6 months ago

1.0.8

6 months ago

1.0.7

6 months ago

1.0.6

7 months ago

1.0.5

7 months ago

1.0.4

7 months ago

1.0.3

7 months ago

1.0.2

7 months ago

1.0.1

7 months ago