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

Wrong OCI picked up if scroll happens before beacon fires - Beacon side #31

Open
2 tasks
Miraeld opened this issue Oct 8, 2024 · 0 comments · May be fixed by #32
Open
2 tasks

Wrong OCI picked up if scroll happens before beacon fires - Beacon side #31

Miraeld opened this issue Oct 8, 2024 · 0 comments · May be fixed by #32
Assignees

Comments

@Miraeld
Copy link

Miraeld commented Oct 8, 2024

Describe the bug
Wrong OCI will be picked up if the page is scrolled and the beacon script is fired after.
This issue will handle the rocket-scripts side.

Reproduce the problem

Identify the root cause

The issue is that the OCI data is collected incorrectly if the user scrolls before the beacon fires. This can happen when the user scrolls on mobile or refreshes the page away from the fold.

Scope a solution

To solve the issue, we must create a new function in BeaconManager.js:

  _isPageScrolled() {
        return window.pageYOffset > 0 || document.documentElement.scrollTop > 0;
    }

and finalize the process of beacon if it returns true:

    async init() {
        this.scriptTimer = new Date();
        if (!await this._isValidPreconditions()) {
            this._finalize();
            return;
        }

        if (this._isPageScrolled()) {
            this.logger.logMessage('Bailing out because the page has been scrolled');
            this._finalize();
            return;
        }
// ...

Development steps:

  • Create the function _isPageScrolled()
  • Modify init function to finalize if the newly added function returns true.

Effort estimation:

XS

Is a refactor needed in that part of the codebase?

No

@Miraeld Miraeld transferred this issue from wp-media/wp-rocket Oct 8, 2024
@Miraeld Miraeld self-assigned this Oct 8, 2024
@Miraeld Miraeld added bug Something isn't working and removed bug Something isn't working labels Oct 8, 2024
@Miraeld Miraeld linked a pull request Oct 8, 2024 that will close this issue
11 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant