-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(Matomo): get started moving events to middleware
- Loading branch information
plondon
committed
Sep 26, 2019
1 parent
1481ea5
commit 032ebd5
Showing
15 changed files
with
55 additions
and
104 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
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
42 changes: 42 additions & 0 deletions
42
packages/blockchain-wallet-v4-frontend/src/middleware/matomoMiddleware.js
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 { contains, path, prop } from 'ramda' | ||
|
||
const PAYLOAD = ['payload'] | ||
const NAME = ['payload', 'name'] | ||
const TYPE = ['payload', 'type'] | ||
const FORM = ['meta', 'form'] | ||
const FIELD = ['meta', 'field'] | ||
|
||
// keep alphabetized | ||
const TYPE_WHITELIST = [ | ||
'@@redux-form/CHANGE', | ||
'@@redux-form/SET_SUBMIT_SUCCEEDED', | ||
'@EVENT.KYC.INITIALIZE_VERIFICATION', | ||
'@EVENT.KYC.UPDATE_EMAIL', | ||
'LOG_ERROR_MSG', | ||
'SHOW_MODAL' | ||
] | ||
|
||
const matomoMiddleware = () => store => next => action => { | ||
const eventCategory = prop('type', action) | ||
const eventAction = | ||
path(FORM, action) || | ||
path(NAME, action) || | ||
path(TYPE, action) || | ||
JSON.stringify(path(PAYLOAD, action)) | ||
const eventName = path(FIELD, action) | ||
|
||
const logEvent = contains(action.type, TYPE_WHITELIST) | ||
|
||
if (logEvent) { | ||
window._paq.push(['trackEvent', eventCategory, eventAction, eventName]) | ||
} | ||
// if (logEvent) { | ||
// console.log('action', action) | ||
// console.log('logEvent', logEvent) | ||
// console.log(['trackEvent', eventCategory, eventAction, eventName]) | ||
// } | ||
|
||
return next(action) | ||
} | ||
|
||
export default matomoMiddleware |
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
Oops, something went wrong.