@bufferapp/analytics-middleware
Advanced tools
Comparing version 0.91.0 to 0.91.2
import keyWrapper from '@bufferapp/keywrapper'; | ||
export const actionTypes = keyWrapper('ANALYTICS', { | ||
INIT: 'INIT', | ||
PAGE_CHANGE: 'PAGE_CHANGE', | ||
TRACK_EVENT: 'TRACK_EVENT', | ||
INIT: 'INIT', | ||
}); | ||
@@ -23,4 +24,11 @@ | ||
}, | ||
pageChange(pageName, payload) { | ||
return { | ||
type: actionTypes.PAGE_CHANGE, | ||
pageName, | ||
payload, | ||
}; | ||
}, | ||
}; | ||
export default actions; |
@@ -23,2 +23,12 @@ import { actions, actionTypes } from './actions'; | ||
}); | ||
it('pageChange triggers PAGE_CHANGE with pageName and payload', () => { | ||
const pageName = 'page 1'; | ||
const payload = { foo: 'foo' }; | ||
expect(actions.pageChange(pageName, payload)).toEqual({ | ||
type: actionTypes.PAGE_CHANGE, | ||
pageName, | ||
payload, | ||
}); | ||
}); | ||
}); |
@@ -19,2 +19,11 @@ import { actionTypes } from './actions'; | ||
break; | ||
case actionTypes.PAGE_CHANGE: | ||
if (window.analytics) { | ||
window.analytics.page( | ||
action.pageName, | ||
Object.assign({ | ||
product: window.PRODUCT_TRACKING_KEY, | ||
}, action.payload)); | ||
} | ||
break; | ||
default: | ||
@@ -21,0 +30,0 @@ break; |
@@ -59,2 +59,18 @@ import './analytics.mock'; | ||
}); | ||
it(`On ${actionTypes.PAGE_CHANGE} should push a page change to segment`, () => { | ||
const action = { | ||
type: actionTypes.PAGE_CHANGE, | ||
pageName: 'page foo', | ||
payload: { | ||
bar: 'bar', | ||
}, | ||
}; | ||
middleware(store)(next)(action); | ||
expect(window.analytics.page) | ||
.toHaveBeenCalledWith(action.pageName, { | ||
bar: 'bar', | ||
product: 'analyze', | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "@bufferapp/analytics-middleware", | ||
"version": "0.91.0", | ||
"version": "0.91.2", | ||
"description": "Analyze Demographic Data Store", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
Sorry, the diff of this file is not supported yet
515097
609