-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dashdashzako
committed
Oct 10, 2019
1 parent
4be2315
commit 11668e9
Showing
6 changed files
with
71 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
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'; | ||
|
||
// TODO: what actions should be monitored? | ||
const loggedActions = [loadConfiguration.type, setSubtitlesText.type]; | ||
|
||
const analytics: Middleware = (store) => (next) => ( | ||
action: PayloadAction<any> | ||
) => { | ||
if (loggedActions.includes(action.type)) { | ||
const state: IAianaState = store.getState(); | ||
|
||
const playerEvent = { | ||
createdAt: Date.now(), | ||
payload: action.payload, | ||
mediaId: state.player.mediaId, | ||
state, | ||
type: action.type, | ||
userId: getUserId() | ||
}; | ||
|
||
const strData = JSON.stringify(playerEvent); | ||
|
||
if (process.env.NODE_ENV !== 'production') { | ||
console.log(strData); | ||
} else { | ||
const loggerEndpoint = (window as any).loggerEndpoint; | ||
|
||
if (loggerEndpoint) { | ||
navigator.sendBeacon(loggerEndpoint, strData); | ||
} | ||
} | ||
} | ||
|
||
return next(action); | ||
}; | ||
|
||
export default analytics; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import queryString from 'query-string'; | ||
import { IQueryString } from '../types'; | ||
|
||
export function getUserId() { | ||
const parsedQueryString: IQueryString = queryString.parse( | ||
window.location.search | ||
); | ||
|
||
const { uid } = parsedQueryString; | ||
|
||
if (uid) { | ||
return uid; | ||
} | ||
|
||
return null; | ||
} |