# Cloudflare Web Analytics Beacon

> Adds Cloudflare's free, cookieless Web Analytics beacon to your public pages, for sites not proxied through Cloudflare or that want manual setup.

- Type: PHP
- Runs: Frontend only
- Category: [Analytics & Tracking](https://wpide.com/library/category/analytics/)
- Tags: cloudflare, analytics, privacy, cookieless
- Author: WPIDE Team
- Installs: 0
- Updated: 2026-10-28
- Page: https://wpide.com/library/analytics-cloudflare-web-analytics/

## Code

```php
add_action( 'wp_footer', function () {
    $token = 'YOUR_TOKEN'; // Web Analytics site token.

    if ( 'YOUR_TOKEN' === $token || current_user_can( 'edit_posts' ) ) {
        return;
    }

    printf( "<script defer src=\"https://static.cloudflareinsights.com/beacon.min.js\" data-cf-beacon=\"%s\"></script>\n", esc_attr( wp_json_encode( array( 'token' => $token ) ) ) );
} );
```

## Notes

Replace YOUR_TOKEN with the token from Cloudflare dashboard > Analytics & Logs > Web Analytics. Nothing is output while the placeholder is in place.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Cloudflare Web Analytics Beacon" in its snippet library and add it in one click; or create a new PHP snippet in WPIDE (or any code snippets plugin) and paste the code above. More snippets: https://wpide.com/library/
