# Umami Analytics

> Adds the privacy-friendly Umami analytics script (cloud or self-hosted) to every public page, skipping logged-in staff.

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

## Code

```php
add_action( 'wp_head', function () {
    $website_id = 'YOUR-WEBSITE-ID';                  // Umami website ID.
    $script_url = 'https://cloud.umami.is/script.js'; // Your script URL if self-hosted.

    if ( 'YOUR-WEBSITE-ID' === $website_id || current_user_can( 'edit_posts' ) ) {
        return;
    }

    printf( "<script defer src=\"%s\" data-website-id=\"%s\"></script>\n", esc_url( $script_url ), esc_attr( $website_id ) );
} );
```

## Notes

Replace YOUR-WEBSITE-ID with your Umami website ID (and $script_url if self-hosted); nothing is output while the placeholder is in place.

## How to use it

Install the free WPIDE plugin (https://wordpress.org/plugins/wpide/), find "Umami Analytics" 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/
