@bufferapp/analytics-middleware
Advanced tools
Comparing version 1.74.2 to 1.76.0
import keyWrapper from '@bufferapp/keywrapper'; | ||
export const actionTypes = keyWrapper('ANALYTICS', { | ||
INIT: 'INIT', | ||
PAGE_CHANGE: 'PAGE_CHANGE', | ||
@@ -10,9 +9,2 @@ TRACK_EVENT: 'TRACK_EVENT', | ||
export const actions = { | ||
init(userId, payload) { | ||
return { | ||
type: actionTypes.INIT, | ||
userId, | ||
payload, | ||
}; | ||
}, | ||
trackEvent(eventName, payload) { | ||
@@ -19,0 +11,0 @@ return { |
import { actions, actionTypes } from './actions'; | ||
describe('actions', () => { | ||
it('init triggers INIT with userId and payload', () => { | ||
const userId = 'foo1'; | ||
const payload = { foo: 'foo' }; | ||
expect(actions.init(userId, payload)).toEqual({ | ||
type: actionTypes.INIT, | ||
userId, | ||
payload, | ||
}); | ||
}); | ||
it('trackEvent triggers TRACK_EVENT with eventName and payload', () => { | ||
@@ -15,0 +5,0 @@ const eventName = 'event 1'; |
@@ -1,2 +0,2 @@ | ||
import Bugsnag from '@bugsnag/js'; | ||
import { BufferTracker } from '@bufferapp/buffer-tracking-browser-ts' | ||
import { actionTypes } from './actions'; | ||
@@ -6,15 +6,9 @@ | ||
switch (action.type) { | ||
case actionTypes.INIT: | ||
if (window.analytics) { | ||
window.analytics.identify(action.userId, action.payload); | ||
Bugsnag.setUser(action.userId); | ||
} | ||
break; | ||
case actionTypes.TRACK_EVENT: | ||
if (window.analytics) { | ||
window.analytics.track( | ||
action.eventName, | ||
Object.assign({ | ||
product: window.PRODUCT_TRACKING_KEY, | ||
}, action.payload)); | ||
BufferTracker[action.eventName]({ | ||
...action.payload, | ||
product: window.PRODUCT_TRACKING_KEY, | ||
organizationId: store.getState().profiles.organizationId | ||
}) | ||
} | ||
@@ -24,6 +18,7 @@ break; | ||
if (window.analytics) { | ||
window.analytics.track('Page Viewed', | ||
Object.assign({ | ||
product: window.PRODUCT_TRACKING_KEY, | ||
}, action.payload)); | ||
BufferTracker.pageViewed({ | ||
...action.payload, | ||
product: window.PRODUCT_TRACKING_KEY, | ||
organizationId: store.getState().profiles.organizationId | ||
}) | ||
} | ||
@@ -30,0 +25,0 @@ break; |
@@ -0,1 +1,2 @@ | ||
import { BufferTracker } from '@bufferapp/buffer-tracking-browser-ts' | ||
import './analytics.mock'; | ||
@@ -5,3 +6,13 @@ import { actionTypes } from './actions'; | ||
jest.mock('@bufferapp/buffer-tracking-browser-ts', () => ({ | ||
BufferTracker: { | ||
pageViewed: jest.fn(), | ||
reportCreated: jest.fn(), | ||
}, | ||
})) | ||
const state = { | ||
profiles: { | ||
organizationId: 'fooOrg', | ||
} | ||
}; | ||
@@ -31,21 +42,6 @@ | ||
it(`On ${actionTypes.INIT} should identify user on segment`, () => { | ||
const action = { | ||
type: actionTypes.INIT, | ||
userId: 'foo1', | ||
payload: { | ||
email: 'foo@buffer.com', | ||
organizationId: 'org1', | ||
createdAt: 'mock-createdAt-date', | ||
}, | ||
}; | ||
middleware(store)(next)(action); | ||
expect(window.analytics.identify) | ||
.toHaveBeenCalledWith(action.userId, action.payload); | ||
}); | ||
it(`On ${actionTypes.TRACK_EVENT} should push an event to segment`, () => { | ||
const action = { | ||
type: actionTypes.TRACK_EVENT, | ||
eventName: 'event foo', | ||
eventName: 'reportCreated', | ||
payload: { | ||
@@ -56,6 +52,7 @@ bar: 'bar', | ||
middleware(store)(next)(action); | ||
expect(window.analytics.track) | ||
.toHaveBeenCalledWith(action.eventName, { | ||
expect(BufferTracker.reportCreated) | ||
.toHaveBeenCalledWith({ | ||
bar: 'bar', | ||
product: 'analyze', | ||
organizationId: 'fooOrg', | ||
}); | ||
@@ -72,8 +69,9 @@ }); | ||
middleware(store)(next)(action); | ||
expect(window.analytics.track) | ||
.toHaveBeenCalledWith('Page Viewed', { | ||
expect(BufferTracker.pageViewed) | ||
.toHaveBeenCalledWith({ | ||
bar: 'bar', | ||
product: 'analyze', | ||
organizationId: 'fooOrg', | ||
}); | ||
}); | ||
}); |
{ | ||
"name": "@bufferapp/analytics-middleware", | ||
"version": "1.74.2", | ||
"version": "1.76.0", | ||
"description": "Analyze Demographic Data Store", | ||
@@ -14,3 +14,6 @@ "main": "index.js", | ||
}, | ||
"gitHead": "f9d6b39c5aba1a68702bbbf75baf5b44a8351d9f" | ||
"gitHead": "975cf467d03ca2ef0c494d7c77893343ca0b968c", | ||
"dependencies": { | ||
"@bufferapp/buffer-tracking-browser-ts": "^0.0.21" | ||
} | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
0
4564
1
152
+ Added@bufferapp/buffer-tracking-browser-ts@0.0.21(transitive)
+ Added@types/segment-analytics@0.0.33(transitive)