Tracking Fiddle Usage
This example shows how to use the activity endpoint to track the usage of this jsFiddle.
by Breinify
HTML
<script src="https://cdn.rawgit.com/Breinify/brein-api-library-javascript-browser/90bb431e/dist/breinify-api.min.js"></script>
<div id="result">
There is actually nothing special to show here. The activity is sent and can be
tracked via the dashboard (see <a href="https://www.breinify.com">breinify.com</a>).
</div>
CSS
#result, #result kbd {
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
text-align: justify;
}
#result kbd {
color: #42A2DE;
}
JavaScript
// we simple create a sessionId to have a unique identifier
var sId = 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random()*16|0,v=c=='x'?r:r&0x3|0x8;return v.toString(16);
});
// we generate a cookie if there isn't one yet
if (Breinify.UTL.cookie.check('breinify_jsFiddle')) {
sId = Breinify.UTL.cookie.get('breinify_jsFiddle');
} else {
Breinify.UTL.cookie.set('breinify_jsFiddle', sId, 100 * 365);
}
// we send the activity, marked as jsFiddle activity and tagged with the fiddle's id
Breinify.activity({ 'sessionId': sId }, 'jsFiddle', { 'fiddle': 'ojkvwwd9' });