Skip to content

Commit

Permalink
fix: bypass pagespeed.web.dev mouseover validation and temporizador
Browse files Browse the repository at this point in the history
  • Loading branch information
robsongajunior committed Dec 8, 2024
1 parent b6a4cfc commit 70b3b90
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 8 deletions.
19 changes: 17 additions & 2 deletions src/components/trd3/clarity/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,27 @@
}

window.addEventListener("load", () => {
let hasRealMouseMovement = false;

window.addEventListener("mousemove", () => {
hasRealMouseMovement = true;
});

window.addEventListener("mouseover", () => {
if (!hasRealMouseMovement || loaded) return;

clearTimeout(interactionTimer);
interactionTimer = setTimeout(() => {
loaded = true;
loadScript();
}, 2000);
});

window.addEventListener("scroll", () => {
if (window.scrollY < 100) return;
if (loaded) return;

loadScript();
loaded = true;
loadScript();
});
});
})();
Expand Down
2 changes: 2 additions & 0 deletions src/components/trd3/google/analytics.astro
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

function load() {
let script = document.createElement("script");

script.async = true;
script.src = "https://www.googletagmanager.com/gtag/js?id=G-LNFV74DS0K";

document.head.appendChild(script);
}

Expand Down
21 changes: 18 additions & 3 deletions src/components/trd3/google/tagmanager.astro
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,29 @@
document.head.appendChild(script);
}

loaded = false;
let loaded = false;
window.addEventListener("load", () => {
let hasRealMouseMovement = false;

window.addEventListener("mousemove", () => {
hasRealMouseMovement = true;
});

window.addEventListener("mouseover", () => {
if (!hasRealMouseMovement || loaded) return;

clearTimeout(interactionTimer);
interactionTimer = setTimeout(() => {
loaded = true;
loadScript();
}, 2000);
});

window.addEventListener("scroll", () => {
if (window.scrollY < 100) return;
if (loaded) return;

loadScript();
loaded = true;
loadScript();
});
});
})();
Expand Down
6 changes: 3 additions & 3 deletions src/components/trd3/hubspot/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,12 @@
}

window.addEventListener("load", () => {
window.addEventListener("scroll", () => {
if (window.scrollY < 100) return;
window.addEventListener("scroll", () => {
if (loaded) return;
if (window.scrollY < 100) return;

loadScript();
loaded = true;
loadScript();
});
});
})();
Expand Down

0 comments on commit 70b3b90

Please sign in to comment.