Skip to content

Instantly share code, notes, and snippets.

export function trackable(action, event, properties = {}) {
const analytics = {
eventType: event,
eventPayload: properties
};
return { ...action, meta: { analytics } };
}
import constants from '../../constants';
export function loadedDashboardState(website, status, news, revenues) {
return trackable({
type: constants.DASHBOARD_STATE_LOADED,
payload: { website, status, news, revenues }
},
'Dashboard opened', // <- event name
{ name: website.name } // <- additional event data
);
import { createStore, applyMiddleware } from 'redux';
import { createAnalytics } from '../middleware';
const middlewares = [
thunk,
createLogger(),
createAnalytics({ host: 'ANALYTICS_HOST', token: 'ANALYTICS_TOKEN' })
];
const enchancer = applyMiddleware(...middlewares);
import { client } from '../analytics';
const handleAction = (store, next, action, options) => {
if (!action.meta || !action.meta.analytics) {
return next(action);
}
const { eventType, eventPayload } = action.meta.analytics;
client(options).track(eventType, eventPayload);
import { createConstants } from '../utils';
const constants = createConstants(
// account actions
'ACCOUNT_FORM_RESET',
'ACCOUNT_FORM_CHANGE',
'ACCOUNT_FORM_ERRORS',
'ACCOUNT_FORM_ERRORS_CLEAN',
'ACCOUNT_ACCESS_TOKEN_FETCHING',
'ACCOUNT_ACCESS_TOKEN_FETCHED',
export function composeComponents(component, wrappers = []) {
return wrappers.reduce((c, wrapper) => wrapper(c), component);
}
const CheckedWelcome = composeComponents(
Welcome,
[
(c) => checkBoarded(c, { withValue: true, redirectTo: '/app/dashboard' }),
(c) => requiresAuth(c)
]
);
const CheckApp = composeComponents(
App,
const routes = (
<Route path="">
<Route path="/signup" component={SignUp} />
<Route path="/signin" component={SignIn} />
// applied here..
<Route path="/welcome-on-board" component={checkBoarded(Welcome, { withValue: true, redirectTo: '/app/dashboard'}) } />
<Route path="/forgot-password" component={ForgotPassword} />
<Route path="/signout" component={SignOut} />
export default function websiteContext(Component) {
class WebsiteContextComponent extends React.Component {
static propTypes = {
dispatch: PropTypes.func.isRequired,
state: PropTypes.object.isRequire,
params: PropTypes.shape({
websiteId: PropTypes.string.isRequired
})
};
const routes = (
<Route path="">
<Route path="/signup" component={SignUp} />
<Route path="/signin" component={SignIn} />
// applied here..
<Route path="/welcome-on-board" component={checkBoarded(Welcome, { withValue: true, redirectTo: '/app/dashboard'}) } />
<Route path="/forgot-password" component={ForgotPassword} />
<Route path="/signout" component={SignOut} />