Guide
How to add Umami to WordPress
There are three ways to connect a WordPress site to Umami. All three load the same tracking script. They differ in how much you have to maintain afterwards.
Short answer
To add Umami to WordPress, copy your website ID and script URL from Umami (Websites → Edit → Tracking code), then add the tracking script to every page. You can do that with a plugin such as Connect for Umami, with a few lines in your theme's functions.php, or by pasting the script tag into your site's head. Visits appear in Umami within seconds.
Before you start: get your tracking details from Umami
Every method needs the same two values.
Add your website in Umami
Log in to Umami (Umami Cloud or your own instance), go to Websites and add your site if it is not there yet.
Open the tracking code
Click Edit next to the website and find the Tracking code section.
Note the two values
The script URL is the
src. On Umami Cloud it ishttps://cloud.umami.is/script.js; on a self-hosted instance it is usuallyhttps://your-umami-host/script.js. The website ID is thedata-website-id, a long code with dashes.
<script defer src="https://cloud.umami.is/script.js" data-website-id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"></script>The three methods compared
| Plugin | functions.php snippet | Header script | |
|---|---|---|---|
| Time to set up | About two minutes | About ten minutes | About five minutes |
| Needs code | No | Yes | No |
| Survives a theme change or update | Yes | Only in a child theme or code-snippet plugin | Depends on where you pasted it |
| Leaves out your own visits | Yes | If you write it that way | No |
| Tracks clicks, forms and store events | Yes, with switches | Only with more code | Only with more code |
| Shows stats inside WordPress | Yes | No | No |
Method 1: add Umami with the Connect for Umami plugin
The quickest route, and the one to choose if you also want events, store tracking or stats in your WordPress dashboard.
Install and activate the plugin
In WordPress, go to Plugins → Add New → Upload Plugin, choose the Connect for Umami zip from your WPUmami account, then activate it.
Enter your Umami details
Go to Settings → WPUmami. On the Tracking tab, paste the website ID and the script URL, then click Save Changes.
Check the status panel
The panel at the top of the screen should read Tracking is on and confirm the script URL is responding.
Confirm a visit in Umami
Open your site in a private browser window, then look at Realtime in Umami. Use a private window because the plugin leaves out logged-in administrators by default.
Method 2: add Umami with code in functions.php
If you are comfortable editing PHP, you can load the tracker yourself. Put this in a child theme's functions.php or in a code-snippets plugin, not in a parent theme, or the next theme update will remove it.
add_action( 'wp_enqueue_scripts', function () {
// Don't count your own visits while logged in as an administrator.
if ( current_user_can( 'manage_options' ) ) {
return;
}
wp_enqueue_script(
'umami',
'https://cloud.umami.is/script.js', // Your script URL.
array(),
null,
array( 'strategy' => 'defer', 'in_footer' => false )
);
} );
// Add the website ID to the script tag.
add_filter( 'script_loader_tag', function ( $tag, $handle ) {
if ( 'umami' !== $handle ) {
return $tag;
}
return str_replace( '<script ', '<script data-website-id="xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx" ', $tag );
}, 10, 2 );Replace the script URL and the website ID with your own. The strategy option needs WordPress 6.3 or newer; it adds defer so the tracker never blocks the page from rendering.
Method 3: paste the tracking code into your site's head
Umami's own instructions are to copy the tracking code and insert it into the <head> of your site. In WordPress you can do that in three places:
- A header and footer scripts plugin. Paste the snippet into its "header" box.
- Your theme's own setting. Many themes have a "custom code" or "header scripts" field.
- The theme's
header.php. Works, but is lost when the theme updates unless you use a child theme.
This is the simplest method and it is enough for counting pageviews. It also counts every visit you make yourself, and it tracks nothing beyond pageviews unless you add more code. The page plugin vs embed code sets out the differences.
How to check Umami is working on WordPress
- Open your site in a private browser window, so nothing excludes you.
- View the page source and search for
data-website-id. The script tag should be there, once. - In Umami, open the website and look at Realtime. Your visit should appear within a few seconds.
If nothing shows up, the usual causes are an ad blocker in your browser, a caching plugin still serving old pages, or a wrong website ID. The troubleshooting guide walks through each one.
Frequently asked questions
Is there an official Umami plugin for WordPress?
No. Umami does not publish an official WordPress plugin. Its own setup instructions are to paste the tracking code into your site's head, and its documentation lists plugins made by the community. Connect for Umami is an independent plugin from WPUmami that adds the tracking code for you, plus event tracking, store tracking and a dashboard widget.
Where do I find my Umami website ID?
In Umami, go to Websites, click Edit next to your site and look at the Tracking code section. The website ID is the value of data-website-id.
Should the Umami script go in the header or the footer?
The header. Umami's instructions place it in the <head>, and because the tag uses defer it does not slow the page down.
Does Umami work with WordPress caching plugins?
Yes. Clear the cache after adding the script. If your optimization plugin delays JavaScript until the visitor interacts, exclude the Umami script from that setting.
Do I need a cookie banner for Umami on WordPress?
Umami does not use cookies and does not collect personal data, which is why many sites run it without a cookie banner. Whether you need a banner depends on everything else running on your site and on the law that applies to you, so check your own situation.
Does this work with self-hosted Umami?
Yes. Use your own script URL, usually https://your-umami-host/script.js. The Cloud vs self-hosted guide covers both setups.
Connect WordPress to Umami in about two minutes
One plugin: the tracking script, events, store revenue and your stats inside WordPress. Plans start at $12 a year, with a 14-day money-back guarantee.