Analytics Utility Functions

1.1.1 · active · verified Sun Apr 19

analytics-utils is a lightweight utility library providing common data manipulation functions specifically designed to support the 'analytics' module ecosystem. Currently at version 1.1.1, this package does not follow a strict time-based release cadence but typically releases new versions in conjunction with updates or new features in the primary 'analytics' library. Its key differentiators include a focused API tailored for analytics payload processing, often leveraging immutable data patterns, and first-class TypeScript support. It is not intended as a general-purpose utility library like Lodash or Ramda, but rather as a specialized toolkit for tasks such as deep property access, data cleaning, and transformation within an analytics context.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates importing and using common `analytics-utils` functions like `get`, `set`, and `isPlainObject` for manipulating analytics event data, showcasing deep property access, immutable updates, and type checking.

import { get, set, isPlainObject } from 'analytics-utils';

interface AnalyticsEvent {
  eventName: string;
  payload: Record<string, any>;
  context?: Record<string, any>;
}

const originalEvent: AnalyticsEvent = {
  eventName: 'UserLoggedIn',
  payload: {
    userId: 'abc-123',
    email: 'user@example.com',
    preferences: {
      theme: 'dark',
      notifications: true
    }
  },
  context: {
    platform: 'web',
    device: 'desktop'
  }
};

// Get a deep property
const userTheme = get(originalEvent, 'payload.preferences.theme');
console.log('User Theme:', userTheme); // 'dark'

// Set a deep property (immutably returns a new object)
const updatedEvent = set(originalEvent, 'payload.preferences.notifications', false);
console.log('Original notifications:', get(originalEvent, 'payload.preferences.notifications')); // true
console.log('Updated notifications:', get(updatedEvent, 'payload.preferences.notifications'));   // false

// Check if a value is a plain object
const isPayloadObject = isPlainObject(originalEvent.payload);
console.log('Is payload a plain object?', isPayloadObject); // true

const isUserThemeObject = isPlainObject(userTheme);
console.log('Is userTheme a plain object?', isUserThemeObject); // false

view raw JSON →