Skip to content

Commit 5de7821

Browse files
committed
added post request sent to server for tracking on run and debug
1 parent cf6f491 commit 5de7821

File tree

5 files changed

+81
-12
lines changed

5 files changed

+81
-12
lines changed

client/scripts/debugger/debugger.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,7 @@
576576
resetOutErr();
577577
}
578578
debuggingStarted();
579+
return getSessionHistory();
579580
}
580581

581582
function handleDebugError(err) {

client/scripts/debugger/user.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,12 @@
148148
state.severity = 'error';
149149
editor.updateLinting(CodeMirror.lintResult([state]));
150150
}
151+
PD.sendActivity({
152+
action: 'run',
153+
meta: {
154+
error: hist.error
155+
}
156+
});
151157
}
152158

153159
function start_debugger(ev) {
@@ -158,7 +164,13 @@
158164
storage["py_src"] = src;
159165
}
160166

161-
Debugger.start_debugger(src, true);
167+
var hist = Debugger.start_debugger(src, true);
168+
PD.sendActivity({
169+
action: 'debug',
170+
meta: {
171+
error: hist.error
172+
}
173+
});
162174
}
163175

164176
function stop_debugger(ev) {

client/scripts/game/player.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@
152152
state.severity = 'error';
153153
editor.updateLinting(CodeMirror.lintResult([state]));
154154
}
155+
PD.sendActivity({
156+
action: 'run',
157+
event: 'python-debugger.od-sandbox',
158+
meta: {
159+
error: hist.error
160+
}
161+
});
155162
}
156163

157164
function start_debugger(ev) {
@@ -163,7 +170,15 @@
163170
if (storage) {
164171
storage["py_game_src"] = src;
165172
}
166-
Debugger.start_debugger(src, true);
173+
var hist = Debugger.start_debugger(src, true);
174+
175+
PD.sendActivity({
176+
action: 'debug',
177+
event: 'python-debugger.od-sandbox',
178+
meta: {
179+
error: hist.error
180+
}
181+
});
167182
}
168183

169184
function stop_debugger(ev) {

client/scripts/main.js

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
(function(i, s, o, g, r, a, m) {
2+
i['GoogleAnalyticsObject'] = r;
3+
i[r] = i[r] || function() {
4+
(i[r].q = i[r].q || []).push(arguments)
5+
}, i[r].l = 1 * new Date();
6+
a = s.createElement(o),
7+
m = s.getElementsByTagName(o)[0];
8+
a.async = 1;
9+
a.src = g;
10+
m.parentNode.insertBefore(a, m)
11+
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');
12+
13+
ga('create', 'UA-68861516-1', 'auto');
14+
ga('send', 'pageview');
15+
16+
var PD = {
17+
promprtForId: function promprtForId() {
18+
var local = window.localStorage
19+
if (!local.getItem('student-id')) {
20+
var id = prompt("please enter your guc student id: 37-*****")
21+
local.setItem('student-id', id);
22+
}
23+
},
24+
sendActivity: function sendActivity(activity) {
25+
var local = window.localStorage
26+
if (!local.getItem('student-id')) {
27+
var id = prompt("please enter your guc student id: 37-*****")
28+
local.setItem('student-id', id);
29+
}
30+
activity.meta = activity.meta || {};
31+
activity.meta['student-id'] = local.getItem('student-id');
32+
activity.event = activity.event || 'python-debugger.editor';
33+
activity.action = activity.action || 'run';
34+
35+
$.post('http://www.kodr.in/api/activity', activity).done(function() {
36+
console.log('sucess');
37+
}).fail(function(xhr) {
38+
console.log('could not send', xhr);
39+
});
40+
41+
},
42+
logout: function logout() {
43+
var local = window.localStorage
44+
if (local.getItem('student-id')) {
45+
local.removeItem('student-id');
46+
}
47+
}
48+
}
49+
50+
PD.promprtForId();

client/templates/layouts/base.swig

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,20 +89,11 @@
8989

9090
<!-- build:js(client) scripts/main.js -->
9191
<script src="scripts/debugger/debugger.js" type="text/javascript" charset="utf-8"></script>
92+
<script src="scripts/main.js" type="text/javascript" charset="utf-8"></script>
9293
<!-- endbuild -->
9394

9495
{% block extra_page_script %}
9596
{% endblock %}
9697

97-
<script>
98-
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
99-
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
100-
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
101-
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
102-
103-
ga('create', 'UA-68861516-1', 'auto');
104-
ga('send', 'pageview');
105-
106-
</script>
10798
</body>
10899
</html>

0 commit comments

Comments
 (0)