|
164 | 164 | });
|
165 | 165 | }
|
166 | 166 |
|
| 167 | + /** |
| 168 | + * Track page feedback (thumbs up/down) - new functionality |
| 169 | + */ |
| 170 | + function trackPageFeedback(feedbackValue, pageUrl, pageTitle) { |
| 171 | + console.log("trackPageFeedback called:", { |
| 172 | + feedbackValue, |
| 173 | + pageUrl, |
| 174 | + pageTitle, |
| 175 | + }); |
| 176 | + |
| 177 | + // Send feedback event to same analytics endpoint |
| 178 | + sendAnalyticsEvent("reaction", { |
| 179 | + feedback_value: feedbackValue === 1 ? "like" : "dislike", // 1 for thumbs up, 0 for thumbs down |
| 180 | + // feedback_type: "reaction", |
| 181 | + page_url: pageUrl, |
| 182 | + }); |
| 183 | + } |
| 184 | + |
167 | 185 | /**
|
168 | 186 | * Get result count from search results
|
169 | 187 | */
|
|
348 | 366 | console.log("MkDocs search tracking initialized");
|
349 | 367 | }
|
350 | 368 |
|
| 369 | + /** |
| 370 | + * Initialize feedback tracking - new functionality for page feedback |
| 371 | + */ |
| 372 | + function initializeFeedbackTracking() { |
| 373 | + console.log("Initializing MkDocs feedback tracking..."); |
| 374 | + |
| 375 | + // Track feedback button clicks |
| 376 | + document.addEventListener("click", function (e) { |
| 377 | + // Check if clicked element is a feedback button |
| 378 | + const feedbackButton = e.target.closest(".md-feedback__icon"); |
| 379 | + |
| 380 | + if (!feedbackButton) { |
| 381 | + return; |
| 382 | + } |
| 383 | + |
| 384 | + console.log("Feedback button clicked:", feedbackButton); |
| 385 | + |
| 386 | + // Get feedback value from data-md-value attribute |
| 387 | + const feedbackValue = feedbackButton.getAttribute("data-md-value"); |
| 388 | + |
| 389 | + if (feedbackValue === null) { |
| 390 | + console.warn("No feedback value found on button"); |
| 391 | + return; |
| 392 | + } |
| 393 | + |
| 394 | + // Get current page information |
| 395 | + const pageUrl = window.location.href; |
| 396 | + const pageTitle = document.title || "Unknown Page"; |
| 397 | + |
| 398 | + // Convert feedback value to number |
| 399 | + const feedbackValueNum = parseInt(feedbackValue, 10); |
| 400 | + |
| 401 | + console.log("Tracking feedback:", { |
| 402 | + value: feedbackValueNum, |
| 403 | + url: pageUrl, |
| 404 | + title: pageTitle, |
| 405 | + }); |
| 406 | + |
| 407 | + // Track the feedback |
| 408 | + trackPageFeedback(feedbackValueNum, pageUrl, pageTitle); |
| 409 | + }); |
| 410 | + |
| 411 | + console.log("MkDocs feedback tracking initialized"); |
| 412 | + } |
| 413 | + |
351 | 414 | /**
|
352 | 415 | * Initialize when DOM is ready
|
353 | 416 | */
|
354 | 417 | function init() {
|
355 | 418 | initializeContext();
|
356 | 419 |
|
357 | 420 | if (document.readyState === "loading") {
|
358 |
| - document.addEventListener("DOMContentLoaded", initializeSearchTracking); |
| 421 | + document.addEventListener("DOMContentLoaded", function () { |
| 422 | + initializeSearchTracking(); |
| 423 | + initializeFeedbackTracking(); |
| 424 | + }); |
359 | 425 | } else {
|
360 | 426 | initializeSearchTracking();
|
| 427 | + initializeFeedbackTracking(); |
361 | 428 | }
|
362 | 429 | }
|
363 | 430 |
|
|
384 | 451 | sendEvent: sendAnalyticsEvent,
|
385 | 452 | trackSearch: trackSearchQuery,
|
386 | 453 | trackClick: trackResultClick,
|
| 454 | + trackFeedback: trackPageFeedback, |
387 | 455 | updateContext: function () {
|
388 | 456 | initializeContext();
|
389 | 457 | },
|
|
395 | 463 | console.log("Found search results:", searchResults);
|
396 | 464 | return searchResults;
|
397 | 465 | },
|
| 466 | + testFeedbackDetection: function () { |
| 467 | + const feedbackButtons = document.querySelectorAll(".md-feedback__icon"); |
| 468 | + console.log("Found feedback buttons:", feedbackButtons); |
| 469 | + return feedbackButtons; |
| 470 | + }, |
398 | 471 | getCurrentSearchState: function () {
|
399 | 472 | const searchContainer = document.querySelector(".md-search");
|
400 | 473 | const searchInput = document.querySelector(".md-search__input");
|
|
422 | 495 | }
|
423 | 496 | }
|
424 | 497 | },
|
| 498 | + simulateFeedbackClick: function (value = 1) { |
| 499 | + const feedbackButton = document.querySelector( |
| 500 | + `.md-feedback__icon[data-md-value="${value}"]` |
| 501 | + ); |
| 502 | + if (feedbackButton) { |
| 503 | + console.log("Simulating feedback click:", feedbackButton); |
| 504 | + feedbackButton.click(); |
| 505 | + } |
| 506 | + }, |
425 | 507 | };
|
426 | 508 | })();
|
0 commit comments