Removed tracking 'comments section viewable' ahoy event (#19354)

* Removed tracking 'comments section viewable' ahoy event

* Returned focus on comments when there is an anchor
This commit is contained in:
Anna Buianova 2023-04-21 13:31:37 +03:00 committed by GitHub
parent 0f495f2952
commit 025cbeb35a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,4 @@
import { h, render } from 'preact';
import ahoy from 'ahoy.js';
import { Snackbar, addSnackbarItem } from '../Snackbar';
import { addFullScreenModeControl } from '../utilities/codeFullscreenModeSwitcher';
import { initializeDropdown } from '../utilities/dropdownUtils';
@ -88,26 +87,13 @@ function showAnnouncer() {
document.getElementById('article-copy-link-announcer').hidden = false;
}
// Temporary Ahoy Stats for displaying comments section either on page load or after scrolling
function trackCommentsSectionDisplayed() {
const callback = (entries, observer) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
ahoy.track('Comment section viewable', { page: location.href });
observer.disconnect();
}
if (location.hash === '#comments') {
//handle focus event on text area
const element = document.getElementById('text-area');
const event = new FocusEvent('focus');
element.dispatchEvent(event);
}
});
};
const target = document.getElementById('comments');
const observer = new IntersectionObserver(callback, {});
observer.observe(target);
function focusOnComments() {
if (location.hash === '#comments') {
//handle focus event on text area
const element = document.getElementById('text-area');
const event = new FocusEvent('focus');
element.dispatchEvent(event);
}
}
function copyArticleLink() {
@ -175,6 +161,6 @@ targetNode && embedGists(targetNode);
setupDisplayAdDropdown();
initializeUserSubscriptionLiquidTagContent();
focusOnComments();
// Temporary Ahoy Stats for comment section clicks on controls
trackCommentClicks('comments');
trackCommentsSectionDisplayed();