Skip to content
This repository was archived by the owner on Nov 15, 2024. It is now read-only.

Commit e7977f5

Browse files
committed
fix apiweb tracking
1 parent 6be039b commit e7977f5

File tree

5 files changed

+21
-16
lines changed

5 files changed

+21
-16
lines changed

api_server/modules/apiweb/templates/ide_redirect.hbs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,17 @@
88
{{> partial_html_head }}
99
<script>
1010
!function () {
11-
CODESTREAM.track("codestream/ide_redirect displayed", {
11+
window.CODESTREAM.track("codestream/ide_redirect displayed", {
1212
"event_type": "modal_display",
1313
"platform": "codestream",
1414
"path": "N/A (codestream)",
1515
"section": "N/A (codestream)",
16-
"userId": "{{nrUserId}}",
1716
"meta_data": "content: {{analyticsContentType}}",
1817
"meta_data_2": "source: {{src}}",
1918
"meta_data_3": "new_to_codestream: {{newToCodeStream}}",
2019
"meta_data_4": "item_guid: {{itemGuid}}",
2120
"meta_data_5": "ab_test_version: {{abTest}}",
22-
});
21+
}, "{{nrUserId}}");
2322
}();
2423
</script>
2524
<script>

api_server/modules/apiweb/templates/partial_html_head.hbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
crossorigin="anonymous"></script>
88
<script>
99
window.CODESTREAM = window.CODESTREAM || {};
10-
window.CODESTREAM.track = function(e, p) {
10+
window.CODESTREAM.track = function(e, p, uid) {
1111
var xhr = new XMLHttpRequest();
1212
xhr.open('POST', '/web/track', true);
1313
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
1414
xhr.send(JSON.stringify({
1515
event: e,
1616
properties: p,
17+
nrUserId: uid,
1718
_csrf: "{{csrf}}"
1819
}));
1920
};

api_server/modules/apiweb/templates/partial_launcher.hbs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -422,28 +422,28 @@ window.CODESTREAM.openEditor = function(ide) {
422422
function () {
423423
//fail
424424
const source = "{{src}}" || "shared_link";
425-
CODESTREAM.track("codestream/ide_redirect failed", {
425+
window.CODESTREAM.track("codestream/ide_redirect failed", {
426426
"event_type": "response",
427427
"platform": "codestream",
428428
"path": "N/A (codestream)",
429429
"section": "N/A (codestream)",
430430
"meta_data": `ide_detail: ${moniker}`,
431431
"meta_data_2": `selection_method: ${ideSelection}`,
432432
"meta_data_3": `source: ${source}`
433-
});
433+
}, options.nrUserId);
434434
console.log(`CodeStream: failed in ${(new Date() - startTime)/1000}s for Moniker=${moniker} Path=${protocol} IDESelection=${ideSelection}`);
435435
}, function () {
436436
//success
437437
const source = "{{src}}" || "shared_link";
438-
CODESTREAM.track("codestream/ide selected", {
438+
window.CODESTREAM.track("codestream/ide selected", {
439439
"event_type": "response",
440440
"platform": "codestream",
441441
"path": "N/A (codestream)",
442442
"section": "N/A (codestream)",
443443
"meta_data": `ide_detail: ${moniker}`,
444444
"meta_data_2": `selection_method: ${ideSelection}`,
445445
"meta_data_3": `source: ${source}`
446-
});
446+
}, options.nrUserId);
447447
console.log(`CodeStream: success in ${(new Date() - startTime)/1000}s for Moniker=${moniker} Path=${protocol} IDESelection=${ideSelection}`);
448448
});
449449
}

api_server/modules/apiweb/templates/partial_launcher_detailed.hbs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -423,30 +423,28 @@ window.CODESTREAM.openEditor = function(ide) {
423423
function () {
424424
//fail
425425
const source = "{{src}}" || "shared_link";
426-
CODESTREAM.track("codestream/ide_redirect failed", {
426+
window.CODESTREAM.track("codestream/ide_redirect failed", {
427427
"event_type": "response",
428428
"platform": "codestream",
429429
"path": "N/A (codestream)",
430430
"section": "N/A (codestream)",
431-
"userId": options.nrUserId,
432431
"meta_data": `ide_detail: ${moniker}`,
433432
"meta_data_2": `selection_method: ${ideSelection}`,
434433
"meta_data_3": `source: ${source}`
435-
});
434+
}, options.nrUserId);
436435
console.log(`CodeStream: failed in ${(new Date() - startTime)/1000}s for Moniker=${moniker} Path=${protocol} IDESelection=${ideSelection}`);
437436
}, function () {
438437
//success
439438
const source = "{{src}}" || "shared_link";
440-
CODESTREAM.track("codestream/ide selected", {
439+
window.CODESTREAM.track("codestream/ide selected", {
441440
"event_type": "response",
442441
"platform": "codestream",
443442
"path": "N/A (codestream)",
444443
"section": "N/A (codestream)",
445-
"userId": options.nrUserId,
446444
"meta_data": `ide_detail: ${moniker}`,
447445
"meta_data_2": `selection_method: ${ideSelection}`,
448446
"meta_data_3": `source: ${source}`
449-
});
447+
}, options.nrUserId);
450448
console.log(`CodeStream: success in ${(new Date() - startTime)/1000}s for Moniker=${moniker} Path=${protocol} IDESelection=${ideSelection}`);
451449
});
452450
}

api_server/modules/apiweb/web_track_request.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ class WebTrackRequest extends RestfulRequest {
2626
string: ['event'],
2727
object:['properties']
2828
},
29+
optional: {
30+
string: ['nrUserId']
31+
}
2932
}
3033
);
3134

@@ -38,8 +41,12 @@ class WebTrackRequest extends RestfulRequest {
3841
async process () {
3942
await this.requireAndAllow();
4043

41-
const { event, properties } = this.request.body;
42-
this.api.services.analytics.track(event, properties, { request: this });
44+
const { event, properties, nrUserId } = this.request.body;
45+
const options = { request: this };
46+
if (nrUserId) {
47+
options.nrUserId = nrUserId;
48+
}
49+
this.api.services.analytics.track(event, properties, options);
4350
}
4451
}
4552

0 commit comments

Comments
 (0)