From c3926423af788a90fba778949d5f5246d549a057 Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Tue, 3 Feb 2015 01:57:35 -0500 Subject: [PATCH] Adding analytics to bonfire --- public/js/lib/bonfire/bonfireFramework.js | 12 +++++++++++- public/js/main.js | 11 ++++++++++- views/bonfire/show.jade | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/public/js/lib/bonfire/bonfireFramework.js b/public/js/lib/bonfire/bonfireFramework.js index 83a8742b5c..965dca2968 100644 --- a/public/js/lib/bonfire/bonfireFramework.js +++ b/public/js/lib/bonfire/bonfireFramework.js @@ -22,6 +22,11 @@ var editor = myCodeMirror; editor.setSize("100%", "auto"); +var attempts = 0; +if (attempts) { + attempts = 0; +} + // Default value for editor if one isn't provided in (i.e. a challenge) var nonChallengeValue = '/*Welcome to Bonfire, Free Code Camp\'s future CoderByte replacement.\n' + 'Please feel free to use Bonfire as an in-browser playground and linting tool.\n' + @@ -100,15 +105,18 @@ $('#submitButton').on('click', function () { }); function bonfireExecute() { + attempts++; + ga('send', 'event', 'Bonfire', 'ran-code', bonfireName); userTests= null; $('#codeOutput').empty(); var userJavaScript = myCodeMirror.getValue(); userJavaScript = removeComments(userJavaScript); userJavaScript = scrapeTests(userJavaScript); // simple fix in case the user forgets to invoke their function - if (challengeEntryPoint) { + if (challengeEntryPoint && challengeSeed) { userJavaScript = challengeEntryPoint + ' ' + userJavaScript; } + console.log(userJavaScript); submit(userJavaScript, function(cls, message) { if (cls) { codeOutput.setValue(message.error); @@ -224,5 +232,7 @@ var runTests = function(err, data) { }; function showCompletion() { + + ga('send', 'event', 'Bonfire', 'solved', bonfireName + ', Time: ' + (Math.floor(Date.now() / 1000) - started) +', Attempts: ' + attempts); $('#complete-bonfire-dialog').modal('show'); } \ No newline at end of file diff --git a/public/js/main.js b/public/js/main.js index 8c9b83aa31..7ba0af65d3 100644 --- a/public/js/main.js +++ b/public/js/main.js @@ -1,4 +1,7 @@ $(document).ready(function() { + if (bonfireName !== undefined) { + ga('send', 'event', 'Bonfire', 'load', bonfireName + ':' + Math.floor(Date.now() / 1000)); + } var CSRF_HEADER = 'X-CSRF-Token'; @@ -61,7 +64,6 @@ $(document).ready(function() { var bonfireSolution = myCodeMirror.getValue(); var thisBonfireHash = passedBonfireHash || null; var didCompleteWith = $('#completed-with').val() || null; - completedBonfire(didCompleteWith, bonfireSolution, thisBonfireHash); }); @@ -83,6 +85,7 @@ $(document).ready(function() { // Bonfire instructions functions $('#more-info').on('click', function() { + ga('send', 'event', 'Bonfire', 'more-info', bonfireName); $('#brief-instructions').hide(); $('#long-instructions').show().removeClass('hide'); @@ -91,6 +94,12 @@ $(document).ready(function() { $('#brief-instructions').show(); $('#long-instructions').hide(); }); + + // Bonfire analytics + $('#submitButton').on('click', function() { + attempts++; + ga('send', 'event', 'Bonfire', 'ran-code', bonfireName); + }) }); var profileValidation = angular.module('profileValidation',['ui.bootstrap']); diff --git a/views/bonfire/show.jade b/views/bonfire/show.jade index 259634d536..98d06ca127 100644 --- a/views/bonfire/show.jade +++ b/views/bonfire/show.jade @@ -90,6 +90,8 @@ block content var challengeSeed = !{JSON.stringify(challengeSeed)}; var challengeEntryPoint = !{JSON.stringify(challengeEntryPoint)}; var passedBonfireHash = !{JSON.stringify(bonfireHash)}; + var bonfireName = !{JSON.stringify(name)}; + var started = Math.floor(Date.now() / 1000); .col-xs-12.col-sm-12.col-md-8 #mainEditorPanel form.code