For any web site or web app we highly recommend using our JustLog.IT Javascript library in your pages. Our pre-built library wraps all the logging functionality. Track actions, performance, and make sure you are logging any script errors.
Add the following script block into your web site or application. This script will initialize the JustLog.IT javascript library, initializing it properly. The only thing you need to do is add the logging token in from your application settings.
<script type="text/javascript"> (function (token) { function append(scriptid, url, async) { var d = document, sn = 'script', f = d.getElementsByTagName(sn)[0]; if (!f) f = d.head; var s = d.createElement(sn); s.async = async; s.id = scriptid; s.src = url; f.parentNode.insertBefore(s, f); } if (!window.justlogit) window.justlogit = {}; window.justlogit.token = token; window.justlogit.userid = 'web user id'; window.justlogit.dnt = false; window.justlogit.handleGlobalErrors = true; append('justlogit', '//cdn.justlog.it/justlogit.min.js', false); })('your token here'); </script>
That's it. Our library doesn't have any external dependencies so you're good to go.
The following are the Properties and Methods available in the JLI Javascript library.
These are the public properties available on the logging object. To access the object use the window.justlogit parent object.
This is the list of methods on the logging interface you can call to store values from your running web application.
When our script initially executes (loads) it will attach a global logging object to the window object. Thisglobal object is called justlogit.
To call logging methods from anywhere in your javascript code by making the following call: window.justlogit.
This section provides some details on how the Javascript library interfaces withthe JustLog.IT REST-ful API. This section is here to answer any questions you may have on how this works in case you have concerns around it.
When logging errors the Javascript library executes a POST call using the XMLHttpRequestjavascript object. The passed in error object is processed into a json object structure and posts it to the error logging endpoint.
All other logging calls use a light-weight mechanism to trigger a GET request to feed the detailsto the logging system. This mechanism is typically referred to as a Pixel Drop. A Pixel Drop forces a GET request by writing a hidden image to the html dom using javascript. The source (src) value for the image is the url plus query string for the logging system. The reason this is lighter weight than using an XMLHttpRequest object is it puts the load onto the browsers dom processor instead of the javascript engine. Most browsers handle async resource requests very efficiently.
In order to really have visibility into what is happening with your application it is important to be able to correlate actions to your specific users. This helps in troubleshooting errors, looking for performance issues, and tracking flows through your app.
To track your users the best option is for you to provide us with a unique user identifier. For example, the same identifier you use to track them after they have logged in. There are 2 options to set this up. First you
can assign the id as the script loads:
window.justlogit.userid = 'your id';
Or you can call the following method:
window.jsutlogit.setUserMarker('your id');
User tracking is enabled by default. And if you don't provide an identifier our script will automatically generate a "correlation id". The correlation id is just a random number that we attempt to store in a cookie and use for future visits from this user. It allows us to try and track user flows even without a specific identifier. This allows for some basic correlation even on your web site where users do not log in or provide an identifier.
If you want to disable user tracking, you can do this as the script loads by setting this variable:
window.justlogit.dnt = true;
Or you can call the following method:
window.jsutlogit.doNotTrack(true);
Turning off tracking does not prevent log entries from being sent. It prevents personally identifiable information (PII) from being stored with the logged information. It also prevents the system from attempting to geo-locate the information beyond the country level. It will also prevent any user identifier from being passed with the log entries. Obviously this will significantly reduce the usefulnes of the user activity tracking, making it very difficult to look at user flows.
A very common thing you might want to do is log the load times for your web pages. Slow web pages aredefinitely the bane of web users and something that has been proven to directly, negatively, impact revenue on sites due to users leaving.
Our javascript library can be used to log page load speeds with reasonable accuracy. Note that the only wayto get 100% accurate load times is from the browser since it controls the entire load. Load times recorded by scripts are less accurate as they require the start time of the load to be recorded after the page starts loading.
That said you can get a decent level of accuracy by following these steps:
That call will log the performance of the page load, at least up to the point where the DOM is ready, so allinitial resource calls have completed. In addition we will automatically capture values such as the user agent so you can see which browser this applies to and the location of the request so you can correlate slower performance with location if necessary.