-
Notifications
You must be signed in to change notification settings - Fork 36
/
Copy pathsend-feedback.js
26 lines (24 loc) · 1.11 KB
/
send-feedback.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// A function to open new issue in GitHub based on {{feedback_url}}.
// Activated when you click the "Send Feedback" button in the footer.
function openGitHubIssue() {
var baseUrl = document.querySelector('.pytorch-body').getAttribute('data-feedback-url');
if (!baseUrl) {
console.error('Feedback URL not found');
return;
}
var pageUrl = window.location.href;
var pageTitle = document.querySelector('h1')?.textContent.split('#')[0].trim() || 'Page';
var issueTitle = encodeURIComponent(`Feedback about ${pageTitle}`);
var issueBody = encodeURIComponent(`There is the following issue on this page: ${pageUrl}`);
var labels = encodeURIComponent("module: docs,page-feedback");
var feedbackUrl = `${baseUrl}/issues/new?title=${issueTitle}&body=${issueBody}&labels=${labels}`;
// Track event in Google Analytics
window.dataLayer = [];
window.dataLayer.push({
'event': 'send_feedback',
'page_title': pageTitle,
'page_location': pageUrl
});
console.log('Data Layer event pushed: send_feedback', pageUrl);
window.open(feedbackUrl, '_blank');
}