How to configure Cloudflare Web Analytics in a worker?

Cloudflare Web Analytics is awesome and faster than google analytics, privacy is added benefit.

However I have a worker that resolves to a subdomain and fetches data from external origin.
Is it possible to add Cloudflare Web Analytics inside the worker?
So far the only way seems to be a script tag intended for HTML.
Any ideas?

Yes. You can use the HTMLRewriter to insert the <script> into the response.