About Blocmetrics

Created by Caroline Courtney, © 2016

Use Case

There are plenty of good analytic services, but that doesn't mean you can't build a better one. Your analytics service will offer a few key features:

Register your Application

Sign up (if you haven't already) and then 'Register New App', and enter your app's name and url to add your app to Blocmetrics' list of registered domains.

For best results, register (or edit) your url to leave the slash off the end: http://live-url.net    not > http://live-url.net/.

Generate Event request snippet:

copy this code into your app/assets/javascripts/application.js file:


// Blocmetrics event request
var blocmetrics = {};
blocmetrics.report = function(eventName) {
  var event = {event: { name: eventName}};
  var request = new XMLHttpRequest();
  request.open("POST", "https://mighty-eyrie-26757.herokuapp.com/api/events", true);
  request.setRequestHeader('Content-Type', 'application/json');
  request.send(JSON.stringify(event));
};

put this event report in any view:


<script type='text/javascript'>
  blocmetrics.report('A cool Thing happened');
</script>

Change A cool Thing happened to a meaningful... event name. Make it distinctive and descriptive for each 'thing' you want to report!

Create events the old-fashioned 'curl' way:

$ curl -v -H "Accept: application/json" -H "Origin: http://reg.app" -H "Content-Type: application/json" -X POST -d '{"name":"foobar"}'  https://mighty-eyrie-26757.herokuapp.com/api/events

except change http://reg.app to the app's real url, foobar to an actual event's name.