{"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.","language":"javascript","status":"abandoned","last_verified":"Thu Apr 23","install":{"commands":["npm install redux-analytics"],"cli":null},"imports":["import analytics from 'redux-analytics';"],"auth":{"required":false,"env_vars":[]},"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.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}