Last active
June 29, 2016 16:23
-
-
Save Daylon/2fa54dc47a8889017ea624419feb3dfa to your computer and use it in GitHub Desktop.
Simple error to Mixpanel tracker
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
'use strict' | |
import Mixpanel from 'mixpanel' | |
let init = () => (window.onerror = catchError) | |
, trackerFeedback = () => console.info( 'This error has been reported!') | |
, throwError = function( msg, source, linenumber ){ | |
if( | |
typeof msg === 'string' | |
&& typeof source === 'string' | |
&& typeof linenumber === 'number' | |
){ | |
catchError( msg, source, linenumber ) | |
} | |
} | |
, catchError = function( | |
msg = '' | |
, source = '' | |
, linenumber = -1 | |
, ...props | |
){ | |
if( window.btoa ){ | |
let payload = { msg, source, linenumber } | |
, b64 = window.btoa( JSON.stringify( Object.assign( payload, props ) ) ) | |
Mixpanel.track( | |
"Error" | |
, b64 | |
, trackerFeedback | |
) | |
} | |
} | |
module.exports = { init, throwError } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment