Skip to content

Commit

Permalink
Update events to be monitored
Browse files Browse the repository at this point in the history
  • Loading branch information
dashdashzako committed Oct 21, 2019
1 parent ddf9927 commit 72c66bb
Showing 1 changed file with 88 additions and 12 deletions.
100 changes: 88 additions & 12 deletions src/middleware/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,105 @@
import { Middleware } from 'redux';
import { PayloadAction } from 'redux-starter-kit';
import { loadConfiguration } from '../actions/shared/configuration';
import { setSubtitlesText } from '../actions/subtitles';
import { getUserId } from '../utils/user';
import { IAianaState } from '../reducers';
import { updateWidget } from '../actions/shared/remote-loader';
import { updateActiveAdditionalInformationTrack } from '../actions/additional-information';
import { addBookmark } from '../actions/bookmarks';
import {
previousChapter,
nextChapter,
updateActiveChaptersTrack
} from '../actions/chapters';
import {
updateRating,
seek,
toggleFullscreenChangeAction,
playMedia,
pauseMedia,
changePlaybackRate,
changeVolume,
toggleMute
} from '../actions/player';
import {
importPreferencesAction,
exportPreferences,
changeMediaSource,
updateLineHeight,
changeActiveTheme,
changeUILanguage,
toggleFontUppercase,
toggleTextHighlighting,
updateFontSizeMultiplier,
updateActiveFontFace,
toggleWidgetVisibility,
setWidgetsLock
} from '../actions/preferences';
import { updateActivePreset } from '../actions/presets';
import {
previousSlide,
nextSlide,
updateActiveSlidesTrack
} from '../actions/slides';
import { updateActiveSubtitles } from '../actions/subtitles';

// TODO: what actions should be monitored?
const loggedActions = [loadConfiguration.type, setSubtitlesText.type];
const loggedActions = [
updateWidget.type,
updateActiveAdditionalInformationTrack.type,
addBookmark.type,
previousChapter.type,
nextChapter.type,
updateActiveChaptersTrack.type,

updateRating.type,
seek.type,
seek.type,
toggleFullscreenChangeAction.type,
playMedia.type,
pauseMedia.type,
changePlaybackRate.type,
changeVolume.type,
toggleMute.type,

importPreferencesAction.type,
exportPreferences.type,
changeMediaSource.type,
updateLineHeight.type,
changeActiveTheme.type,
changeUILanguage.type,
toggleFontUppercase.type,
toggleTextHighlighting.type,
updateFontSizeMultiplier.type,
updateActiveFontFace.type,
toggleWidgetVisibility.type,
setWidgetsLock.type,

updateActivePreset.type,

previousSlide.type,
nextSlide.type,
updateActiveSlidesTrack.type,

updateActiveSubtitles.type
];

const analytics: Middleware = (store) => (next) => (
action: PayloadAction<any>
) => {
const result = next(action);

if (loggedActions.includes(action.type)) {
const state: IAianaState = store.getState();
const partialState = {
...state.player,
...state.preferences
};

const playerEvent = {
createdAt: Date.now(),
eventName: action.type,
mediaId: state.player.mediaId,
payload: action.payload,
state: partialState,
type: action.type,
player: {
...state.player
},
preferences: {
...state.preferences
},
userId: getUserId()
};

Expand All @@ -37,7 +113,7 @@ const analytics: Middleware = (store) => (next) => (
}
}

return next(action);
return result;
};

export default analytics;

0 comments on commit 72c66bb

Please sign in to comment.