Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
redux-reporter
Advanced tools
Redux middleware for reporting actions to third party APIs. This package is extremely useful for analytics and error handling. Can be used with various APIs such as New Relic, Sentry, Adobe DTM, Keen
npm install --save redux-reporter
Create your reporting middleware
// /middleware/myReporter.js
import reporter from 'redux-reporter';
export default reporter(({ type, payload }, getState) => {
try {
// report to external API
} catch (err) {}
});
Attach meta data to your actions
// /actions/MyActions.js
export function myAction() {
let type = 'MY_ACTION';
return {
type,
meta: {
report: { // default attribute that is selected by redux-reporter
type,
payload: 'example payload'
}
}
};
}
Configure store with your middleware
// /store/configureStore.js
import { compose, createStore, applyMiddleware } from 'redux';
import thunk from 'redux-thunk';
import rootReducer from './reducers/rootReducer';
import myReporter from './middleware/myReporter'; // import your reporter
const isBrowser = (typeof window !== 'undefined');
const enhancer = compose(
applyMiddleware(...[thunk, myReporter]),
isBrowser && window.devToolsExtension) ? window.devToolsExtension() : (f) => f
);
export default (initialState = {}) => {
return createStore(rootReducer, initialState, enhancer);
}
Reporting to Multiple APIs: You can report to multiple APIs by configuring multiple middlewares and attaching additional attributes to your actions
// /actions/MyActions.js
export function myAction() {
let type = 'MY_ACTION';
return {
type,
meta: {
analytics: {
type,
payload: 'example payload'
},
experiments: {
type,
payload: 'example payload'
}
}
};
}
// /middleware/newrelic.js
import { errorReporter as newrelicErrorReporter, crashReporter as newrelicCrashReporter } from 'redux-reporter';
const report = (error) => {
try {
window.newrelic.noticeError(error);
} catch (err) {}
};
export const crashReporter = newrelicCrashReporter(report);
export const errorReporter = newrelicErrorReporter(report);
// /actions/MyActions.js
export function myAction() {
let type = 'MY_ERROR_ACTION';
return {
type,
error: true
payload: new Error('My Handled Error')
};
}
// /middleware/newrelic.js
import reporter from 'redux-reporter';
export const analyticsReporter = reporter(({ type, payload }) => {
try {
window.newrelic.addPageAction(type, payload);
} catch (err) {}
}, ({ meta = {} }) => meta.analytics);
// /actions/MyActions.js
export function myAction() {
let type = 'MY_ACTION';
return {
type,
meta: {
analytics: {
type,
payload: 'example payload'
}
}
};
}
redux-reporter can be used for goal tracking with optimizely
// /middleware/optimizely.js
import reporter from 'redux-reporter';
export default reporter(({ type, payload }) => {
window.optimizely = window.optimizely || [];
window.optimizely.push(['trackEvent', type, payload]);
}, ({ meta = {} }) => meta.experiments);
// /actions/MyActions.js
export function myAction() {
let type = 'MY_ACTION';
return {
type,
meta: {
experiments: {
type,
payload: 'example payload'
}
}
};
}
You can also report to an Analytics provider. This example uses Adobe DTM, but this pattern will work for other APIs (keen, segment, etc.)
// /actions/MyActions.js
export function myAction() {
let type = 'MY_ACTION';
return {
type,
meta: {
analytics: {
type,
payload: {
userType: 'example',
someOtherData: '1234'
}
}
}
};
}
// /middleware/adobedtm.js
import reporter from 'redux-reporter';
// create custom select function to select desired slice of your action
const select = ({ meta = {} }) => meta.analytics;
export default reporter(({ type, payload }) => {
try {
window._satellite.setVar('payload', payload);
window._satellite.track(type);
} catch (err) {}
}, select);
// inside Adobe DTM we create a direct call rule with the same name/condition as our action type
FAQs
Redux middleware for reporting actions to third party APIs.
The npm package redux-reporter receives a total of 164 weekly downloads. As such, redux-reporter popularity was classified as not popular.
We found that redux-reporter demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.