Skip to content

Commit 508f3f1

Browse files
author
dashdashzako
committed
Log simpler version of app state
1 parent 3570e4a commit 508f3f1

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

src/middleware/analytics.ts

+10-12
Original file line numberDiff line numberDiff line change
@@ -13,29 +13,27 @@ const analytics: Middleware = (store) => (next) => (
1313
) => {
1414
if (loggedActions.includes(action.type)) {
1515
const state: IAianaState = store.getState();
16+
const partialState = {
17+
...state.player,
18+
...state.preferences
19+
};
1620

1721
const playerEvent = {
1822
createdAt: Date.now(),
19-
payload: action.payload,
2023
mediaId: state.player.mediaId,
21-
state,
24+
payload: action.payload,
25+
state: partialState,
2226
type: action.type,
2327
userId: getUserId()
2428
};
2529

2630
const strData = JSON.stringify(playerEvent);
31+
const loggerEndpoint = (window as any).loggerEndpoint;
2732

28-
if (process.env.NODE_ENV !== 'production') {
33+
if (process.env.NODE_ENV !== 'production' && !loggerEndpoint) {
2934
console.log(strData);
30-
} else {
31-
const loggerEndpoint = (window as any).loggerEndpoint;
32-
const blob = new Blob([strData], {
33-
type: 'application/json; charset=UTF-8'
34-
});
35-
36-
if (loggerEndpoint) {
37-
navigator.sendBeacon(loggerEndpoint, blob);
38-
}
35+
} else if (loggerEndpoint) {
36+
navigator.sendBeacon(loggerEndpoint, strData);
3937
}
4038
}
4139

0 commit comments

Comments
 (0)