Live demo of datalayer.js
This page loads datalayer.js which wraps window.dataLayer.push so every push runs
after the next browser paint instead of synchronously during interaction. That keeps INP from being blown
up by GTM tags that do heavy work on click.
Click the button. The page calls dataLayer.push immediately, but the wrapped version waits
for the next animation frame + a small buffer before invoking the original push. The log below records
both timestamps so you can see the gap.
(no events yet)
Open DevTools → Performance and record while clicking — you'll see the push body land in the next frame, not the click handler frame.
Source: github.com/corewebvitals/pagespeed/.../datalayer-schedule-after-paint