Code to use

How to install

Easy and clean

1. Create a JSLogger account.

2. Include the script in your web page, preferably before any other script:

<script type="text/javascript" src="//jslogger.com/jslogger.js"></script>
<script type="text/javascript">window.jslogger = new JSLogger();</script>

3. Start monitoring errors http://jslogger.com/manage.

CDN support (recommended)

The JSLogger tracker can be loaded from CDN. The advantage is that the script will be delivered much faster around the world.

Unfortunatelly, we don't support a CDN version for HTTPS but, don't worry, the script will be delivered directly from our server for your secure connection.

<script type="text/javascript">
document.write('<script type="text/javascript" src="' + ('https:'==document.location.protocol?'https://':'http://c.') + 'jslogger.com/jslogger.js"><\/script>');
</script>
<script type="text/javascript">window.jslogger = new JSLogger();</script>

Dynamic loading

You can load JSLogger dynamically in your page. The only downside is that a couple of logs can be missed while the script wasn't loaded yet.

<script type="text/javascript">
(function () {
var jsl=document.createElement('script');jsl.type='text/javascript';jsl.async=true;
jsl.src=('https:'==document.location.protocol?'https:':'http:')+'//jslogger.com/jslogger.js';
jsl.onload=function(){jslogger=new JSLogger();};
var s=document.getElementsByTagName('script')[0];s.parentNode.insertBefore(jsl,s);
})();
</script>

How to track?

All Javascript errors in your site will be logged to our server by default. But you can also log and track events on your own.

Logs

To log errors or other types of notifications use the .log(data) function

jslogger.log("I am an exception")
jslogger.log({exception: {name: "SignupFail", message: "The signup request failed."}})

Events

To log special events use the .event(data) function

jslogger.event("The signup button was clicked.")
jslogger.event({signup: {from: "Header red button"}})

Examples

Log an Ajax request error with jQuery:

$.ajax({
  url: "/signup",
  success: function () {
    jslogger.event({signup: {from: "Header red button"}});
  },
  error: function (jqXHR, textStatus, errorThrown) {
    jslogger.log({signup_error: {from: "Header red button", xhr: jqXHR, status: textStatus, error: errorThrown}});
  }
})

Track mouse events:

$("#payment-button").mouseover(function () {
  jslogger.event("The client found the payment button...");
})

$("#payment-button").click(function () {
  jslogger.event("The client payed!");
})

Track window events:

$(window).scroll(function () {
  jslogger.event("The client scrolled your page for " + $(window).scrollTop() + " px.");
})

Easy integration with the jQueryUI widgets:

$("#dialog-confirm").dialog({
  modal: true,
  buttons: {
    "Delete item": function() {
      $(this).dialog("close");
      jslogger.event("Item deleted!");
    },
    Cancel: function() {
      $(this).dialog("close");
      jslogger.event("Item was not deleted.");
    }
  }
})

Options

If you don't want to send logs to the server in development mode, set track option to false :

JSLogger({track: false});

If you don't want to track the errors in your site, set logWindowErrors to false :

JSLogger({logWindowErrors: false});

All your logs are authorized by the domain they come from. Each project has a unique domain name assigned to it. You can use your API key when sending logs from a desktop app or one hosted on your local machine. The key will ignore the domain referal.

JSLogger({apiKey: "YOUR_PROJECT_API_KEY"});

Libraries

Questions, bug reports or feedback?

Please send an e-mail to support@jslogger.com or use our Help page. We'll respond right away.

For a quick response you can always ping us on Twitter - @jslogger or tweet about how awesome JSLogger is - #jslogger.

Like us on Facebook and become a part of the JSLogger community.

Track issues on GitHub.

Check out our blog for Javascript tutorials and JSLogger news.