layout: page title: JavaScript Helper Library prev_section: drafts next_section: variables permalink: /helper_libs/javascript/

Due to the high number of Data Analytic tools using web technologies, a JavaScript helper library was created to aid developers in instrumenting their JavaScript tools with logging capabilities.

The current version of the JavaScript API uses Web Workers, this allows logging to happen as a background process, and should have minimal interference with other processes that are happening on the web client.


Getting Started

###Download both the latest logging library and the latest worker library from Github here.

###Include the logging library {% highlight html %} ; {% endhighlight %}

###Instantiate the Logger {% highlight javascript %} // web worker url var worker = ‘js/draper.activity_worker-2.1.1.js’ var ac = new activityLogger(worker); .testing(true) // simulate POST, won‘t send log .echo(true) // log to console .mute([‘SYS’]); // don’t log SYSTEM actions {% endhighlight %}

###Register the Logger {% highlight javascript %} ac.registerActivityLogger( “http://xd-draper.xdata.data-tactics-corp.com:1337”, “my-component”, “v0.1” ); {% endhighlight %}

###Log a User Activity {% highlight javascript %} $(‘#button’).mouseenter(function() { ac.logUserActivity( ‘User hovered over element to read popup’, // description ‘hover_start’, // activity_code ac.WF_EXPLORE // workflow State ); }) {% endhighlight %}


##Function Reference activityLoggernew activityLogger(workerUrl)

{% highlight javascript %} ac.logSystemActivity(‘asking server for data.’);

$.getJSON(‘https://my_endpoint/get_data’, data, function(data) { ac.logSystemActivity(‘received data from server.’); $(“#result”).text(data.result); }); {% endhighlight %}