lib/analytics.js
//-- todo: move this whole thing into a seperate merge app like auth
move this whole thing into a seperate merge app like auth
move this whole thing into a seperate merge app like auth
function $formatter(type, d, {user,sId,ip,ref}) {
  if (!config.log || !config.log.trk[type]) return
  var ident = user != null ? `${user.name||user._id}`.gray : `${sId.substring(0,12)}`.cyan
  var jdata = type == 'view'
    ? `${(d.url||'').cyan} ${ref?ref.replace(/https\:\/\/|http\:\/\//g,'<<< ').replace('www.','').blue:''}`
    : JSON.stringify(d.data||{}).replace(/^\{/,'').replace(/\}$/,'').replace(/\"([^(\")"]+)\":/g,"$1:".dim).gray
  var label = type
  if (type == 'event') label = d.name
  if (type == 'view') label = `VIEW:${d.type}`
  $logIt(`trk.${type}`
    , label.toUpperCase()
    , `${ip.replace(':ffff','')}`.cyan+`\t${ident}`
    , jdata
  )
}
function $formatter ( type , d , { user , sId , ip , ref } ) { if ( ! config . log || ! config . log . trk [ type ] ) return var ident = user != null ? ` ${ user . name || user . _id } ` . gray : ` ${ sId . substring ( 0 , 12 ) } ` . cyan var jdata = type == 'view' ? ` ${ ( d . url || '' ) . cyan } ${ ref ? ref . replace ( / https\:\/\/|http\:\/\/ / g , '<<< ' ) . replace ( 'www.' , '' ) . blue : '' } ` : JSON . stringify ( d . data || { } ) . replace ( / ^\{ / , '' ) . replace ( / \}$ / , '' ) . replace ( / \"([^(\")"]+)\": / g , "$1:" . dim ) . gray var label = type if ( type == 'event' ) label = d . name if ( type == 'view' ) label = ` ${ d . type } ` $logIt ( ` ${ type } ` , label . toUpperCase ( ) , ` ${ ip . replace ( ':ffff' , '' ) } ` . cyan + ` \t ${ ident } ` , jdata ) }
todo: move this whole thing into a seperate merge app like auth
todo : move this whole thing into a seperate merge app like auth