Skip to content

Commit 3df7593

Browse files
adliuscslzchen
authored andcommitted
Added a check with comments on obtaining and using preprints GUID
The preprints GUID used by the GA tracking event is retreived from window.DEFAULT_URL, which is the third segment of the URL path.
1 parent 06518bc commit 3df7593

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

mfr/server/static/js/mfr.child.hypothesis.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,24 @@
6464
hypothesisLoaded = true;
6565

6666
var sidePanelOpened = false;
67+
// window.DEFAULT_URL should be the wb link in this format:
68+
// https://<wb-domain>/v1/resources/<preprint-guid>/providers/osfstorage/<file-id>?direct=&mode=render
69+
// TODO: parse and validate the WB URL before retrieving the preprints GUID
70+
var wbLink = window.DEFAULT_URL;
71+
var preprintGuid;
72+
if (wbLink.split('/').length >= 6) {
73+
preprintGuid = wbLink.split('/')[5];
74+
} else {
75+
preprintGuid = 'preprint-guid-unknown';
76+
}
6777
var sendAnalyticsIfExpanded = function (expanded) {
6878
if (expanded && !sidePanelOpened) {
6979
sidePanelOpened = expanded;
7080
ga('send', 'event', {
7181
eventCategory: 'Hypothesis',
7282
eventAction: 'Open Hypothesis Panel',
73-
eventLabel: window.DEFAULT_URL.split('/')[5],
83+
//`eventLabel` is the guid of the preprint to which the file belongs
84+
eventLabel: preprintGuid,
7485
});
7586
}
7687
};

0 commit comments

Comments
 (0)