{"id":18721,"library":"redux-action-analytics-middleware","title":"Redux Action Analytics Middleware","description":"A Redux middleware that triggers analytics callbacks for whitelisted actions. Current stable version is 2.8.0. The project has an active release cadence with periodic dependency updates. Key differentiators: decoupled from any specific analytics tool, consolidates analytics logic in middleware, provides pre- and post-action state to callbacks, and uses Flow types. It strips no data from actions, so callbacks must handle sensitive information.","status":"active","version":"2.8.0","language":"javascript","source_language":"en","source_url":"https://github.com/TomasBarry/redux-action-analytics-middleware","tags":["javascript","redux","middleware","analytics"],"install":[{"cmd":"npm install redux-action-analytics-middleware","lang":"bash","label":"npm"},{"cmd":"yarn add redux-action-analytics-middleware","lang":"bash","label":"yarn"},{"cmd":"pnpm add redux-action-analytics-middleware","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports a single default export, the AnalyticsMiddleware function. CommonJS require works but TypeScript users should use default import.","wrong":"const AnalyticsMiddleware = require('redux-action-analytics-middleware')","symbol":"default","correct":"import AnalyticsMiddleware from 'redux-action-analytics-middleware'"},{"note":"This is a default export, not a named export. Using curly braces will result in undefined.","wrong":"import { AnalyticsMiddleware } from 'redux-action-analytics-middleware'","symbol":"AnalyticsMiddleware","correct":"import AnalyticsMiddleware from 'redux-action-analytics-middleware'"},{"note":"TrackableActionType is a type alias (string) used internally; it is not exported. Import only the default export.","wrong":null,"symbol":"TrackableActionType","correct":"import AnalyticsMiddleware from 'redux-action-analytics-middleware'"}],"quickstart":{"code":"import AnalyticsMiddleware from 'redux-action-analytics-middleware'\nimport { createStore, applyMiddleware } from 'redux'\n\nconst trackCallback = (action, preState, postState) => {\n  console.log('Tracked action:', action)\n  console.log('State change:', preState, '->', postState)\n}\n\nconst trackableActions = ['USER_LOGIN', 'PURCHASE_ITEM']\n\nconst middleware = AnalyticsMiddleware({\n  trackCallback,\n  trackableActions\n})\n\nconst reducer = (state = { count: 0 }, action) => {\n  switch (action.type) {\n    case 'INCREMENT':\n      return { ...state, count: state.count + 1 }\n    default:\n      return state\n  }\n}\n\nconst store = createStore(reducer, applyMiddleware(middleware))\n\nstore.dispatch({ type: 'USER_LOGIN' }) // Triggers analytics\nstore.dispatch({ type: 'INCREMENT' }) // Not tracked","lang":"javascript","description":"Configures the analytics middleware with a simple console.log callback and a whitelist of action types, then creates a Redux store with it."},"warnings":[{"fix":"Add data sanitization logic inside the trackCallback before sending to analytics.","message":"The middleware does not strip data from actions. If an action contains sensitive information, the trackCallback must handle sanitization.","severity":"gotcha","affected_versions":"all"},{"fix":"Use the package's generic parameter for State type, and import types from Redux's flow-typed definitions if needed.","message":"Flow typing integration is facing challenges: Action, Dispatch, and Store can no longer be imported from Redux in Flow. This may affect TypeScript or Flow users.","severity":"deprecated","affected_versions":">=2.6.0"},{"fix":"Always treat the action as read-only inside the callback, or clone it before modification.","message":"The trackCallback receives the action object directly. Modifying the action inside the callback may affect the reducer if not careful.","severity":"gotcha","affected_versions":"all"},{"fix":"Use constants for action types to avoid typos.","message":"The trackableActions array is compared by string equality. Make sure action types are exactly matched, including any prefixes or namespaces.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Change to: import AnalyticsMiddleware from 'redux-action-analytics-middleware'","cause":"The import statement used named import instead of default import.","error":"AnalyticsMiddleware is not a function"},{"fix":"Ensure trackableActions contains the exact action type strings and that the dispatched action has a 'type' property.","cause":"The trackableActions array is empty or the action type does not match any whitelisted type.","error":"Cannot read property 'type' of undefined in trackCallback"},{"fix":"Make sure the reducer returns an object and the middleware is properly passed to applyMiddleware.","cause":"The middleware is applied incorrectly or the reducer returns a non-object state (e.g., null or primitive).","error":"TypeError: preActionState is not an object"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}