Put worker in front of Cloudflare Pages for logging

We need to do certain logging on requests that go to the main page of our website hosted on Cloudflare Pages. We want to go with a Worker, but can’t find a way to put a worker in front of Cloudflare Pages (so that the worker gets hit, but then the content is served by Pages).

We’ve tried creating a separate redirect.example.com worker which does the logging that redirects with 302 to the main page. But that adds extra DNS lookup and round-trip, which make too big of a difference for us.

How can we run worker on requests that are served by Cloudflare Pages?