GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update analytics data sending method by Shrishti0423 · Pull Request #4002 · javascript-tutorial/en.javascript.info

Conversation

@Shrishti0423

@Shrishti0423 Shrishti0423 commented Oct 22, 2026

Copy link
Copy Markdown

Updated the analytics example to use the visibilitychange event instead of unload.

The analytics data is sent using navigator.sendBeacon() when the document becomes hidden, which is more reliable for sending data when a user leaves or switches away from a page.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Shrishti0423
Update analytics data sending method
8212df2
Replaced 'unload' event with 'visibilitychange' to send analytics data when the document is hidden.
@javascript-translate-bot javascript-translate-bot added review needed Review needed, please approve or request changes labels Oct 22, 2026
@javascript-translate-bot
javascript-translate-bot requested a review from a team October 22, 2026 19:30
AKzar1el
AKzar1el reviewed Nov 2, 2026
View reviewed changes

@AKzar1el AKzar1el left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The new handler can run repeatedly while the page stays open, but the surrounding section still describes a one-time unload event.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread 2-ui/5-loading/01-onload-ondomcontentloaded/article.md Outdated
window.addEventListener("unload", function() {
navigator.sendBeacon("/analytics", JSON.stringify(analyticsData));
document.addEventListener("visibilitychange", function() {
if (document.visibilityState === "hidden") {

@AKzar1el AKzar1el Nov 2, 2026

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

visibilitychange also fires when someone switches tabs or minimizes the browser, so this can send the same accumulated analyticsData multiple times without an unload. Could the example either clear the sent batch after a successfully queued beacon or guard one-time reporting, and update the surrounding window.onunload explanation? Otherwise readers copying it may double-count activity.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@Shrishti0423 Shrishti0423 Nov 3, 2026

Copy link
Copy Markdown
Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Thanks for the feedback! I've updated the example to use a one-time reporting guard based on the return value of navigator.sendBeacon(). This prevents the same analytics data from being queued multiple times when the page becomes hidden repeatedly. I've also updated the surrounding explanation to describe the visibilitychange event and when it fires.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@Shrishti0423
Fix analytics reporting on visibility change
1a7496a
Updated the explanation of using the visibilitychange event and navigator.sendBeacon for sending analytics data.
@CLAassistant

CLAassistant commented Nov 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@AKzar1el AKzar1el AKzar1el left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

review needed Review needed, please approve or request changes

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@Shrishti0423 @CLAassistant @AKzar1el @javascript-translate-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.