{"id":17897,"library":"redux-analytics","title":"Redux Analytics Middleware","description":"The `redux-analytics` package offers a Redux middleware designed to integrate analytics tracking into Redux applications. It works by inspecting actions for a specific metadata structure: `action.meta.analytics`. For an action to be processed, this `analytics` metadata must itself conform to the Flux Standard Action (FSA) pattern, meaning it must have at least a `type` and a `payload` property. The middleware is instantiated with a callback function that receives these analytics `type` and `payload` (along with the full Redux state), allowing developers to connect to any third-party analytics service. As of version 0.3.1, this project appears to be a historical artifact from the early days of Redux, with no significant updates or active maintenance since its initial development around 2015. Its key differentiator was its strict adherence to the FSA convention for both the action and its embedded analytics metadata, promoting a consistent action structure.","status":"abandoned","version":"0.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/markdalgleish/redux-analytics","tags":["javascript"],"install":[{"cmd":"npm install redux-analytics","lang":"bash","label":"npm"},{"cmd":"yarn add redux-analytics","lang":"bash","label":"yarn"},{"cmd":"pnpm add redux-analytics","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This package was developed during an earlier era of JavaScript module systems. While `import` syntax can be used with bundlers, the original intent was likely CommonJS `require`.","wrong":"const analytics = require('redux-analytics');","symbol":"analytics","correct":"import analytics from 'redux-analytics';"}],"quickstart":{"code":"import { createStore, applyMiddleware } from 'redux';\nimport analytics from 'redux-analytics';\n\n// Mock analytics tracking library\nconst track = (type, payload) => {\n  console.log('Analytics Event:', type, payload);\n  // In a real app, this would send data to Google Analytics, Segment, etc.\n};\n\n// Redux reducer (minimal for demonstration)\nconst initialState = {\n  user: { id: 'user-123', plan: 'premium' },\n  app: { version: '1.0.0' }\n};\nfunction rootReducer(state = initialState, action) {\n  switch (action.type) {\n    case 'USER_LOGGED_IN':\n      return { ...state, user: { ...state.user, id: action.payload.userId } };\n    default:\n      return state;\n  }\n}\n\n// Analytics middleware setup\nconst analyticsMiddleware = analytics(({ type, payload }, state) => {\n  // Example: Augment analytics payload with shared state data\n  track(type, { ...state.app, userId: state.user.id, ...payload });\n});\n\n// Create Redux store\nconst store = createStore(rootReducer, applyMiddleware(analyticsMiddleware));\n\n// Dispatch an action with valid analytics metadata\nstore.dispatch({\n  type: 'ITEM_ADDED_TO_CART',\n  payload: { itemId: 'sku789', quantity: 2 },\n  meta: {\n    analytics: {\n      type: 'ecommerce_add_to_cart',\n      payload: {\n        product: 'Super Widget',\n        value: 19.99\n      }\n    }\n  }\n});\n\n// Dispatch another action without analytics metadata (should be ignored by middleware)\nstore.dispatch({\n  type: 'UPDATE_UI_SETTING',\n  payload: { theme: 'dark' }\n});\n\n// Dispatch an action with invalid analytics meta (should log an error to console)\nstore.dispatch({\n  type: 'INVALID_ANALYTICS_ACTION',\n  meta: {\n    analytics: { // Missing payload, thus not a valid FSA for analytics meta\n      type: 'invalid_event'\n    }\n  }\n});","lang":"javascript","description":"This example demonstrates how to set up `redux-analytics` middleware, dispatch an action with valid analytics metadata, an action without, and an action with invalid metadata."},"warnings":[{"fix":"Consider using newer Redux patterns like sagas, thunks, or dedicated analytics integration libraries, possibly tied to action types, rather than relying on this unmaintained middleware.","message":"This package is effectively abandoned. It has not been updated since 2016 (v0.3.1), and is not recommended for new projects. Modern Redux setups have moved towards different patterns for analytics integration.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Ensure `action.meta.analytics` is an object with at least `type` and `payload` properties, for example: `{ type: 'EVENT_NAME', payload: { ...data } }`.","message":"The `analytics` metadata within your action's `meta` property must itself be a Flux Standard Action (FSA). If it does not conform (e.g., missing `type` or `payload`), an error will be printed to the console, and the event will be ignored.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-23T00:00:00.000Z","next_check":"2026-07-22T00:00:00.000Z","problems":[{"fix":"Modify your action to ensure `action.meta.analytics` adheres to the FSA structure: `{ type: 'MY_ANALYTICS_EVENT', payload: { ...eventData } }`.","cause":"The `meta.analytics` property on your Redux action is missing either the `type` or `payload` field, or is not a plain object, thereby violating the Flux Standard Action pattern.","error":"Error: analytics meta must be a Flux Standard Action"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}