Skip to content

Commit 507183d

Browse files
Adding event tracking of the tutorial Start, End, Previous, and Next.
Adding a tracking event whenever a submission is parsed.
1 parent c2285e1 commit 507183d

File tree

1 file changed

+65
-8
lines changed

1 file changed

+65
-8
lines changed

js/main.js

Lines changed: 65 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,43 @@ define(function(require, exports, module) {
1111
Submission = require('submission'),
1212
Tutorial = require('tutorial');
1313

14+
function trackEvent(category, action, label, value, _isInteractive) {
15+
var dataLayer = window.dataLayer || [],
16+
isInteractive = (_isInteractive === undefined) ? true : _isInteractive;
17+
dataLayer.push({
18+
'event': 'event',
19+
'eventCategory': 'Conditional - ' + category,
20+
'eventAction': action,
21+
'eventLabel': label,
22+
'eventValue': value,
23+
'isNonInteractive': !Boolean(isInteractive)
24+
});
25+
}
26+
27+
function trackEventTutorialStart(stepNum) {
28+
trackEvent('Tutorial', 'Start', 'Step ' + stepNum);
29+
}
30+
31+
function trackEventTutorialEnd(stepNum) {
32+
trackEvent('Tutorial', 'End', 'Step ' + stepNum);
33+
}
34+
35+
function trackEventTutorialNext(prevStep, nextStep) {
36+
trackEvent('Tutorial', 'Next', 'Step ' + prevStep + ' to ' + nextStep);
37+
}
38+
39+
function trackEventTutorialPrev(prevStep, nextStep) {
40+
trackEvent('Tutorial', 'Prev', 'Step ' + prevStep + ' to ' + nextStep);
41+
}
42+
43+
function trackEventInputMixedOperators() {
44+
trackEvent('Parse', 'Mixed Operators');
45+
}
46+
47+
function trackEventInputParse() {
48+
trackEvent('Parse', 'Success');
49+
}
50+
1451
function calculateColumnClasses(/*Expression*/ expression, newDepth) {
1552
var columnClasses = [],
1653
depth = newDepth || 0,
@@ -98,7 +135,8 @@ define(function(require, exports, module) {
98135
$introText = $('.js-intro-text'),
99136
$alertMixedOperators = $('.js-alert-mixed-operators'),
100137
$truthTable = $('.js-truth-table'),
101-
$startTutorial = $('.js-tutorial-start');
138+
$startTutorial = $('.js-tutorial-start'),
139+
lastTutorialStepNum = null;
102140

103141
$input.change(function() {
104142
var input = $input.val(),
@@ -119,6 +157,7 @@ define(function(require, exports, module) {
119157
if(expression.hasMixedOperatorsDeep()) {
120158
$inputForm.addClass('has-error');
121159
$alertMixedOperators.removeClass('hidden');
160+
trackEventInputMixedOperators();
122161
} else {
123162

124163
$truthTable.removeClass('hidden');
@@ -129,28 +168,46 @@ define(function(require, exports, module) {
129168
printCells(expression, columnClasses)
130169
);
131170

171+
trackEventInputParse();
172+
132173
}
133174

134175
}
135176
});
136177

137178
$startTutorial.click(function() {
138-
var hasStarted = false,
179+
var thisStepNum = function(tour) { return tour.getCurrentStep() + 1; },
139180
userInput;
140181

141182
var tutorial = new Tutorial.Tutorial({
183+
debug: true,
184+
//template: tutorialTemplate,
142185
onShow: function() {
143-
// onStart does not fire if the user has previously seen the tutorial
144-
if(!hasStarted) {
145-
hasStarted = true;
186+
// onStart does not fire if the user has previously seen the tutorial,
187+
// so detect the start using onShow
188+
if(lastTutorialStepNum === null) {
146189
userInput = $input.val();
147190
$input.val('').change();
148191
}
149-
$input.change();
150192
},
151-
onEnd: function() {
152-
hasStarted = false;
193+
onShown: function(tour) {
194+
// the step number is only accurate in onShown, not onShow
195+
if(lastTutorialStepNum === null) {
196+
trackEventTutorialStart(thisStepNum(tour));
197+
} else {
198+
if(lastTutorialStepNum < thisStepNum(tour)) {
199+
trackEventTutorialNext(lastTutorialStepNum, thisStepNum(tour));
200+
} else {
201+
trackEventTutorialPrev(lastTutorialStepNum, thisStepNum(tour));
202+
}
203+
}
204+
205+
lastTutorialStepNum = thisStepNum(tour);
206+
},
207+
onEnd: function(tour) {
208+
lastTutorialStepNum = null;
153209
$input.val(userInput).change();
210+
trackEventTutorialEnd(thisStepNum(tour));
154211
}
155212
});
156213

0 commit comments

Comments
 (0)