I want to use the Cloudflare API for Web Analytics site access

I would like to use Web Analytics to count the number of visits to my site.

Normally, I would need to add the following JS snippet before the final Body tag of the HTML page and access it in a browser,
Can we do this from Node.js using the Cloudflare API without adding the JS snippet to the HTML?

JS Snippets


Thank you for reaching out to us. i’ll be glad to assist you with your query.

Currently, Cloudflare Web Analytics requires the JS snippet to properly track site visits. The API does not provide a way to do this from Node.js without the JS snippet. The beacon should be added just before the closing body tag of each HTML page you wish to track. If you’re running a single-page application, Cloudflare does support SPA analytics - you can read more about it in their blog post here:

1 Like