@bufferapp/analytics-middleware
Advanced tools
Comparing version 1.76.0 to 1.76.1
@@ -5,2 +5,20 @@ import { BufferTracker } from '@bufferapp/buffer-tracking-browser-ts' | ||
export default store => next => (action) => { // eslint-disable-line no-unused-vars | ||
let organizationId = null; | ||
const state = store.getState(); | ||
// This is used to get the organizationId from the user context exposed by the App-Shell | ||
if ( | ||
window.__userData && | ||
window.__userData.data && | ||
window.__userData.data.account && | ||
window.__userData.data.account.currentOrganization && | ||
window.__userData.data.account.currentOrganization.id | ||
) { | ||
organizationId = window.__userData.data.account.currentOrganization.id; | ||
} else if ( | ||
state.profiles && | ||
state.profiles.organizationId | ||
) { | ||
organizationId = store.getState().profiles.organizationId | ||
} | ||
switch (action.type) { | ||
@@ -12,3 +30,3 @@ case actionTypes.TRACK_EVENT: | ||
product: window.PRODUCT_TRACKING_KEY, | ||
organizationId: store.getState().profiles.organizationId | ||
organizationId, | ||
}) | ||
@@ -22,3 +40,3 @@ } | ||
product: window.PRODUCT_TRACKING_KEY, | ||
organizationId: store.getState().profiles.organizationId | ||
organizationId, | ||
}) | ||
@@ -25,0 +43,0 @@ } |
@@ -73,2 +73,27 @@ import { BufferTracker } from '@bufferapp/buffer-tracking-browser-ts' | ||
}); | ||
it('should push an event with the organizationId from the account Object', () => { | ||
window.__userData = { | ||
data: { | ||
account: { | ||
currentOrganization: { | ||
id: 'fooOrgGlobal', | ||
}, | ||
}, | ||
}, | ||
} | ||
const action = { | ||
type: actionTypes.PAGE_CHANGE, | ||
payload: { | ||
bar: 'bar', | ||
}, | ||
}; | ||
middleware(store)(next)(action); | ||
expect(BufferTracker.pageViewed) | ||
.toHaveBeenCalledWith({ | ||
bar: 'bar', | ||
product: 'analyze', | ||
organizationId: 'fooOrgGlobal', | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "@bufferapp/analytics-middleware", | ||
"version": "1.76.0", | ||
"version": "1.76.1", | ||
"description": "Analyze Demographic Data Store", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
5645
193