Skip to content

Commit f2e61ea

Browse files
committed
Add Checksum to Challenges for Google Analytics
1 parent d5cb8b3 commit f2e61ea

14 files changed

+32
-5
lines changed

client/commonFramework/bindings.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ window.common = (function(global) {
129129
});
130130

131131
if (common.challengeName) {
132-
window.ga('send', 'event', 'Challenge', 'load', common.challengeName);
132+
window.ga('send', 'event', 'Challenge', 'load', common.gaName);
133133
}
134134

135135
$('#complete-courseware-dialog').on('hidden.bs.modal', function() {

client/commonFramework/execute-challenge-stream.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ window.common = (function(global) {
2020
const tail = common.arrayToNewLineString(common.tail);
2121
const combinedCode = head + code + tail;
2222

23-
ga('send', 'event', 'Challenge', 'ran-code', common.challengeName);
23+
ga('send', 'event', 'Challenge', 'ran-code', common.gaName);
2424

2525
// run checks for unsafe code
2626
return detectUnsafeCode$(code)

client/commonFramework/show-completion.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ window.common = (function(global) {
1212
'event',
1313
'Challenge',
1414
'solved',
15-
common.challengeName,
15+
common.gaName,
1616
true
1717
);
1818

common/models/challenge.json

+3
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
"suborder": {
3030
"type": "number"
3131
},
32+
"checksum": {
33+
"type": "number"
34+
},
3235
"isBeta": {
3336
"type": "boolean",
3437
"description": "Show only during dev or on beta site. Completely omitted otherwise"

package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@
2626
"license": "(BSD-3-Clause AND CC-BY-SA-4.0)",
2727
"dependencies": {
2828
"accepts": "^1.3.0",
29+
"adler32": "~0.1.7",
2930
"async": "^1.5.0",
3031
"babel-cli": "^6.3.17",
3132
"babel-core": "^6.3.26",
3233
"babel-eslint": "^4.1.4",
3334
"babel-loader": "^6.2.1",
34-
"babel-register": "^6.3.0",
3535
"babel-plugin-add-module-exports": "^0.1.2",
3636
"babel-preset-es2015": "^6.3.13",
3737
"babel-preset-react": "^6.3.13",
3838
"babel-preset-stage-0": "^6.3.13",
39+
"babel-register": "^6.3.0",
3940
"body-parser": "^1.13.2",
4041
"chai-jquery": "^2.0.0",
4142
"cheerio": "~0.19.0",

seed/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/* eslint-disable no-process-exit */
22
require('babel-register');
33
require('dotenv').load();
4+
var adler32 = require('adler32');
45

56
var Rx = require('rx'),
67
_ = require('lodash'),
@@ -40,6 +41,12 @@ destroy()
4041
.replace(/\:/g, '')
4142
.replace(/\s/g, '-');
4243

44+
challenge.checksum = adler32.sum(
45+
Buffer(challenge.title +
46+
JSON.stringify(challenge.description) +
47+
JSON.stringify(challenge.challengeSeed) +
48+
JSON.stringify(challenge.tests)));
49+
4350
challenge.fileName = fileName;
4451
challenge.helpRoom = helpRoom;
4552
challenge.order = order;

server/boot/challenge.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,10 @@ function getRenderData$(user, challenge$, origChallengeName, solution) {
178178
// htmls specific
179179
verb: randomVerb(),
180180
phrase: randomPhrase(),
181-
compliment: randomCompliment()
181+
compliment: randomCompliment(),
182+
183+
// Google Analytics
184+
gaName: challenge.title + '~' + challenge.checksum
182185
}
183186
});
184187
});

server/utils/getFromDisk$.js

+7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import path from 'path';
22
import { Observable } from 'rx';
3+
import adler32 from 'adler32';
34

45
const basePath = process.cwd() + '/seed/challenges/';
56

@@ -21,6 +22,12 @@ export default function getFromDisk$(challenge) {
2122
return _challenge;
2223
})
2324
.map(challenge => {
25+
challenge.checksum = adler32.sum(
26+
Buffer(challenge.title +
27+
JSON.stringify(challenge.description) +
28+
JSON.stringify(challenge.challengeSeed) +
29+
JSON.stringify(challenge.tests)));
30+
2431
challenge.head = challenge.head || [];
2532
challenge.tail = challenge.tail || [];
2633
challenge.challengeType = '' + challenge.challengeType;

server/views/challenges/showBonfire.jade

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ block content
9393
common.challengeType = !{JSON.stringify(challengeType)};
9494
common.dashedName = !{JSON.stringify(dashedName)};
9595
common.isCompleted = !{JSON.stringify(isCompleted)};
96+
common.gaName = !{JSON.stringify(gaName)};
9697

9798
common.username = !{JSON.stringify(user && user.username || '')};
9899

server/views/challenges/showHTML.jade

+1
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ block content
8484
common.challengeType = !{JSON.stringify(challengeType)};
8585
common.dashedName = !{JSON.stringify(dashedName)};
8686
common.isCompleted = !{JSON.stringify(isCompleted)};
87+
common.gaName = !{JSON.stringify(gaName)};
8788

8889
common.username = !{JSON.stringify(user && user.username || '')};
8990

server/views/challenges/showJS.jade

+1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ block content
8888
common.challengeType = !{JSON.stringify(challengeType)};
8989
common.dashedName = !{JSON.stringify(dashedName)};
9090
common.isCompleted = !{JSON.stringify(isCompleted)};
91+
common.gaName = !{JSON.stringify(gaName)};
9192

9293
common.username = !{JSON.stringify(user && user.username || '')};
9394

server/views/challenges/showStep.jade

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ block content
4949
common.challengeName = !{JSON.stringify(name)};
5050
common.challengeType = !{JSON.stringify(challengeType)};
5151
common.dashedName = !{JSON.stringify(dashedName || '')};
52+
common.gaName = !{JSON.stringify(gaName)};
5253
common.isHonest = !{JSON.stringify(isHonest || false)};
5354
common.isFrontEndCert = !{JSON.stringify(isFrontEndCert || false)};
5455
common.isFullStackCert = !{JSON.stringify(isFullStackCert || false)};

server/views/challenges/showVideo.jade

+1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ block content
5656
common.challengeName = !{JSON.stringify(name)};
5757
common.challengeType = !{JSON.stringify(challengeType)};
5858
common.dashedName = !{JSON.stringify(dashedName)};
59+
common.gaName = !{JSON.stringify(gaName)};
5960
common.init.push(function($) {
6061
function controlEnterHandler(e) {
6162
if (

server/views/challenges/showZiplineOrBasejump.jade

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ block content
6868
common.challengeId = !{JSON.stringify(id)};
6969
common.challengeName = !{JSON.stringify(name)};
7070
common.dashedName = !{JSON.stringify(dashedName)};
71+
common.gaName = !{JSON.stringify(gaName)};
7172
common.challengeType = !{JSON.stringify(challengeType)};
7273

7374
common.controlEnterHandler = function (e) {

0 commit comments

Comments
 (0)