Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ENG-6958][DRAFT] Add pageload logging #10940

Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions website/settings/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,10 @@ def parent_dir(path):
DATACITE_URL = 'https://mds.datacite.org'
DATACITE_PREFIX = '10.70102' # Datacite's test DOI prefix -- update in production


# OSF's RepoId on Datacite to track stats for DOIs. See https://support.datacite.org/docs/datacite-usage-tracker.
DATACITE_TRACKER_REPO_ID = None

# crossref
CROSSREF_USERNAME = None
CROSSREF_PASSWORD = None
Expand Down
43 changes: 43 additions & 0 deletions website/static/js/components/tracker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
let dataciteConfig = {};
function init(repoId){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can remove this.

dataciteConfig.repoId=repoId;
}

function getRepoId() {
if (dataciteConfig.repoId) {
return dataciteConfig.repoId;
} else {
return window.contextVars.dataciteTracker.repoId;
}
}

function trackView(metricName, doi) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let's hardcode metricName

if (!doi || doi.trim().length === 0) {
return;
}
const repoID = getRepoId();

const payload = {
n: metricName,
u: window.location.href,
i: repoID,
p: doi,
};
const r = new XMLHttpRequest();
r.open('POST', `https://analytics.datacite.org/api/metric`, true);
r.setRequestHeader('Content-Type', 'application/json');
r.send(JSON.stringify(payload));
r.onreadystatechange = () => {
if (r.readyState !== 4)
return;
if (r.status === 400) {
console.error('[DataCiteTracker] ' + r.responseText);
}

};
}

module.exports = {
trackView: trackView,
init: init
};
8 changes: 7 additions & 1 deletion website/static/js/pages/project-dashboard-page.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ var node = window.contextVars.node;
var nodeApiUrl = ctx.node.urls.api;
var nodeCategories = ctx.nodeCategories || [];
var currentUserRequestState = ctx.currentUserRequestState;

const tracker = require('js/components/tracker');

// Listen for the nodeLoad event (prevents multiple requests for data)
$('body').on('nodeLoad', function(event, data) {
Expand All @@ -42,6 +42,11 @@ $('body').on('nodeLoad', function(event, data) {
new CitationList('#citationList');
new CitationWidget('#citationStyleInput', '#citationText');
}

if (data.node.identifiers.doi) {
tracker.trackView(data.node.identifiers.doi);
}

// Initialize nodeControl
new NodeControl.NodeControl('#projectScope', data, {categories: nodeCategories, currentUserRequestState: currentUserRequestState});

Expand Down Expand Up @@ -102,6 +107,7 @@ var institutionLogos = {


$(document).ready(function () {

// activate bootstrap popovers
$('[data-toggle="popover"]').popover();
// Allows dropdown elements to persist after being clicked
Expand Down
10 changes: 10 additions & 0 deletions website/templates/base.mako
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,16 @@
</script>
% endif

% if settings.DATACITE_TRACKER_REPO_ID:
<script>
window.contextVars = $.extend(true, {}, window.contextVars, {
dataciteTracker: {
repoId: ${ settings.DATACITE_TRACKER_REPO_ID | sjson, n },
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dataciteTracker.repoId => dataciteTrackRepoId

},
});
</script>
% endif


${self.javascript_bottom()}
</body>
Expand Down
Loading