npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ngxs-logrocket-plugin

v21.1.2

Published

NGXS plugin for [LogRocket](https://logrocket.com/) that augments LogRocket sessions with actions and state from your NGXS store.

Readme

ngxs-logrocket-plugin

NGXS plugin for LogRocket that augments LogRocket sessions with actions and state from your NGXS store.

npm version License: MIT

LogRocket Redux Tab

Features

  • Complete Action Logging - Captures all NGXS actions with their status (Dispatched, Successful, Errored, Canceled)
  • State Snapshots - Records state before and after each action
  • Optimized Performance - Runs outside Angular zone to prevent unnecessary change detection
  • Privacy Controls - Sanitize sensitive data from actions and state
  • Flexible Integration - Load LogRocket from npm package or CDN script tag
  • SSR Compatible - Safely skips logging during server-side rendering

Installation

npm install ngxs-logrocket-plugin logrocket

Or with yarn:

yarn add ngxs-logrocket-plugin logrocket

Or with pnpm:

pnpm add ngxs-logrocket-plugin logrocket

Requirements

  • @ngxs/store >= 21.0.0
  • logrocket (peer dependency)
  • Angular (compatible with your NGXS version)

Usage

Basic Setup

// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideStore } from '@ngxs/store';
import { withNgxsLogRocketReduxMiddlewarePlugin } from 'ngxs-logrocket-plugin';
import LogRocket from 'logrocket';

// Initialize LogRocket
LogRocket.init('your-app-id');

export const appConfig: ApplicationConfig = {
  providers: [
    provideStore(
      [
        /* your states */
      ],
      withNgxsLogRocketReduxMiddlewarePlugin({
        logrocket: () => LogRocket,
      }),
    ),
  ],
};

Loading LogRocket from CDN

If you load LogRocket via a script tag instead of npm:

<!-- index.html -->
<script src="https://cdn.logr-in.com/LogRocket.min.js" crossorigin="anonymous"></script>
<script>
  window.LogRocket && window.LogRocket.init('your-app-id');
</script>
// app.config.ts
export const appConfig: ApplicationConfig = {
  providers: [
    provideStore(
      [
        /* your states */
      ],
      withNgxsLogRocketReduxMiddlewarePlugin({
        logrocket: () => window.LogRocket,
      }),
    ),
  ],
};

Lazy-loading Plugin

You can also lazy-load the plugin when LogRocket is needed in your application, for example when a user logs in and LogRocket.init is called:

// somewhere in the app
import { inject, EnvironmentInjector, createEnvironmentInjector, Injector } from '@angular/core';
import { provideStates } from '@ngxs/store';

@Injectable({ providedIn: 'root' })
export class LogRocketService {
  private injector = inject(EnvironmentInjector);

  async start() {
    // Load LogRocket script.
    await loadScript('https://cdn.logr-in.com/LogRocket.min.js');

    window.LogRocket.init('your-app-id');

    // Lazy-load the NGXS plugin.
    const { withNgxsLogRocketReduxMiddlewarePlugin } = await import('ngxs-logrocket-plugin');

    // Register plugin in child injector so it's available globally.
    // This adds the plugin to NGXS without requiring app-level configuration.
    createEnvironmentInjector(
      [
        provideStates(
          [],
          withNgxsLogRocketReduxMiddlewarePlugin({
            logrocket: () => window.LogRocket,
          }),
        ),
      ],
      this.injector,
    );
  }
}

// Helper function to load external scripts.
function loadScript(src: string): Promise<void> {
  return new Promise((resolve, reject) => {
    const script = document.createElement('script');
    script.src = src;
    script.onload = () => resolve();
    script.onerror = () => reject(new Error(`Failed to load script: ${src}`));
    document.head.appendChild(script);
  });
}

Configuration

Sanitizing Actions

Remove sensitive data from actions before logging:

withNgxsLogRocketReduxMiddlewarePlugin({
  logrocket: () => LogRocket,
  actionSanitizer: (action) => {
    // Ignore specific actions
    if (action.type === '[Auth] Login Success') {
      return null; // Action won't be logged
    }

    // Redact sensitive data
    if (action.type === '[User] Update Profile') {
      return {
        ...action,
        password: undefined,
        creditCard: undefined,
      };
    }

    return action;
  },
});

Sanitizing State

Remove sensitive data from state snapshots:

withNgxsLogRocketReduxMiddlewarePlugin({
  logrocket: () => LogRocket,
  stateSanitizer: (state) => {
    return {
      ...state,
      auth: {
        ...state.auth,
        token: undefined, // Remove auth token
        password: undefined,
      },
      payment: undefined, // Remove entire payment state
    };
  },
});

Using Angular Injection in Sanitizers

Both logrocket, stateSanitizer, and actionSanitizer run in injection context, allowing you to use Angular's inject():

import { inject } from '@angular/core';
import { MySecurityService } from './my-security.service';

withNgxsLogRocketReduxMiddlewarePlugin({
  logrocket: () => LogRocket,
  stateSanitizer: (state) => {
    const security = inject(MySecurityService);
    return security.sanitizeState(state);
  },
  actionSanitizer: (action) => {
    const security = inject(MySecurityService);
    return security.shouldLogAction(action) ? action : null;
  },
});

Action Status Types

The plugin logs actions with the following statuses:

| Status | Description | | ------------ | ------------------------------------------------------ | | DISPATCHED | Action has been dispatched | | SUCCESSFUL | Action handler completed successfully | | ERRORED | Action handler threw an error | | CANCELED | Action was canceled by another action of the same type |

Example in LogRocket:

[Countries] Load countries (DISPATCHED)
[Countries] Load countries (SUCCESSFUL)
[Auth] Login (DISPATCHED)
[Auth] Login (ERRORED)

How It Works

The plugin integrates with NGXS as a middleware and leverages LogRocket's Redux middleware under the hood:

  1. Intercepts all NGXS actions before they're processed
  2. Logs action dispatch with current state
  3. Captures action completion (success, error, or cancellation)
  4. Compresses actions and state using LogRocket's binary format
  5. Performs state diffs to minimize network data

All logging operations run outside the Angular zone to prevent triggering unnecessary change detection cycles.

Viewing Logs in LogRocket

Once configured, you can view NGXS actions in the LogRocket dashboard:

  1. Open a session in LogRocket
  2. Navigate to the "Redux" tab
  3. Browse actions and state changes
  4. Click an action to see state before and after

Performance Considerations

  • Zone Optimization: All LogRocket operations run outside Angular's zone
  • Data Compression: Actions and state are compressed using binary format
  • State Diffing: Only state changes are transmitted, not full snapshots
  • Error Handling: LogRocket errors are caught and logged without breaking your app
  • SSR Safe: Automatically skips logging on server to prevent errors

TypeScript Support

Full TypeScript support is included. The plugin exports all necessary types:

import type { NgxsLogRocketReduxMiddlewareOptions } from 'ngxs-logrocket-plugin';

Troubleshooting

Actions Not Appearing in LogRocket

  1. Verify LogRocket is initialized before NGXS
  2. Check that the plugin is registered with provideStore
  3. Ensure you're not returning null from actionSanitizer

Performance Issues

  • Use actionSanitizer to filter high-frequency actions
  • Sanitize large state objects to reduce payload size
  • Verify you're using the factory pattern () => LogRocket (not direct reference)

License

MIT © arturovt

Related Projects

Version Compatibility

This package follows the major version of @ngxs/store:

| ngxs-logrocket-plugin | @ngxs/store | | --------------------- | ----------- | | 21.x.x | >=21.0.0 |