Skip to content

Instantly share code, notes, and snippets.

@Daylon
Last active June 29, 2016 16:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Daylon/2fa54dc47a8889017ea624419feb3dfa to your computer and use it in GitHub Desktop.
Save Daylon/2fa54dc47a8889017ea624419feb3dfa to your computer and use it in GitHub Desktop.
Simple error to Mixpanel tracker
'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