Skip to content

Instantly share code, notes, and snippets.

@adam-hert
Created March 11, 2016 17:52
Show Gist options
  • Save adam-hert/888855d7af85f8aed1cd to your computer and use it in GitHub Desktop.
Save adam-hert/888855d7af85f8aed1cd to your computer and use it in GitHub Desktop.
<html>
<head>
<script type="text/javascript" src="http://d1g52r1j47671p.cloudfront.net/spa-timing.js"></script>
<script type ='text/javascript'>
//define Your RUM key
var key = 'Your_key_here';
//Define the tracer and appName
var tracer = new Tracer({
rumKey: key,
//which app the RUM data belongs to in TraceView (needs to exist already)
appName: 'Test_spa'
});
//define a asynchronous GET function
function httpGetAsync(theUrl, callback)
{
var xmlHttp = new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4 && xmlHttp.status == 200)
callback(xmlHttp.responseText);
}
xmlHttp.open("GET", theUrl, true); // true for asynchronous
xmlHttp.send(null);
}
//Get some content asynchronously and insrutument it. 'Get Some Content' will show up as the 'Action' and JS as the controller in the TraceView UI
tracer.run('Get Some content', function (done) {
console.log('Test timing of content')
httpGetAsync('/testcontent.html', function dosomestuff(response, callback){done();});
})
document.addEventListener("DOMContentLoaded", function(event) {
//Example of instrumenting an event listener
button.addEventListener('click', function () {
tracer.run('click', function (done) {
//Your javascript code
console.log('clicked a button!')
done()
})
})
});
</script>
</head>
<body>
Hello World SPA
<button type="button" id='button'>Click Me!</button>
<button
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment