WordPress
Add Rybbit analytics to your WordPress site
WordPress has no built-in header-code setting, so the snippet goes in through a plugin such as WPCode or through your theme's functions.php or header.php. Every method below works on self-hosted WordPress.org sites; on WordPress.com you need the Business plan or higher before you can install plugins or add custom JavaScript.
Get your tracking snippet
In your Rybbit dashboard, open Site Settings → Tracking Script and copy your snippet. It looks like this:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>YOUR_SITE_ID is the numeric ID of your site. If you self-host Rybbit, app.rybbit.io is the domain of your own instance.
Add the snippet to WordPress
If you edit theme files, edit a child theme. Changes to a parent theme's functions.php or header.php are lost on the next theme update.
WPCode (formerly Insert Headers and Footers) is the recommended method: it survives theme updates, works with page builders, and is available on WordPress.com Business plans.
- Go to Plugins > Add New, search for "WPCode", then install and activate it.
- Go to Code Snippets > Header & Footer (Settings > Insert Headers and Footers in older versions).
- Paste the snippet into the Header box and click Save Changes.
- Go to Appearance > Theme File Editor and open your child theme's
functions.php. - Add this to the end of the file, replacing
YOUR_SITE_ID:
function rybbit_add_tracking_script() {
?>
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
<?php
}
add_action( 'wp_head', 'rybbit_add_tracking_script' );- Save the file.
- Go to Appearance > Theme File Editor and open your child theme's
header.php. - Paste the snippet just before the closing
</head>tag:
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
</head>- Save the file.
A one-file plugin keeps the snippet in place through theme changes without touching theme files.
- Over FTP/SFTP or a file-manager plugin, create the folder
/wp-content/plugins/rybbit-analytics/. - Inside it, create
rybbit-analytics.phpwith this content, replacingYOUR_SITE_ID:
<?php
/**
* Plugin Name: Rybbit Analytics
* Description: Adds the Rybbit tracking script to every page
* Version: 1.0
*/
function rybbit_add_tracking_script() {
?>
<script src="https://app.rybbit.io/api/script.js?siteId=YOUR_SITE_ID" defer></script>
<?php
}
add_action( 'wp_head', 'rybbit_add_tracking_script' );- Go to Plugins and activate Rybbit Analytics.
Running WooCommerce? Once the snippet is in place, see the WooCommerce guide for purchase and add-to-cart events.
Verify installation
Open your live site in a new tab and click through a few pages. Within a few seconds the pageviews appear in the Rybbit dashboard.
If nothing shows up:
- View the page source and search for
script.js?siteId=to confirm the snippet is on the page. - Open the browser Network tab and check that
script.jsreturns200and thatPOSTrequests go to/api/track. - Disable ad blockers, or set up a proxy so the script loads from your own domain.
- See the script troubleshooting guide for other common causes.
Troubleshooting
- Caching plugins: after saving the snippet, purge WP Super Cache, W3 Total Cache, LiteSpeed Cache or whichever cache plugin you run, plus any CDN cache such as Cloudflare, before you check the page source.
- Script optimisers: "Delay JavaScript execution" features in WP Rocket, Perfmatters and FlyingPress rebuild script tags and drop
data-*attributes, which is why the snippet passes the site ID in the URL (?siteId=). If tracking still fails, excludeapp.rybbit.iofrom optimisation: Autoptimize's exclusion list, WP Rocket's JavaScript optimisation and delay-JS exclusions, Perfmatters / FlyingPress delay-JS exclusions, LiteSpeed Cache JS excludes, SG Optimizer combine/minify. - Page builders (Elementor, Divi, WPBakery, Beaver Builder): add the snippet with WPCode rather than a builder's custom HTML block. Builders sanitise HTML and can strip attributes from script tags.
- Security plugins: Wordfence, Sucuri and similar plugins can block external scripts. Add
app.rybbit.ioto the allowlist. - WordPress.com plans: Free, Personal and Premium plans cannot add custom JavaScript. Upgrade to Business or eCommerce and use the WPCode method.
Next steps
- Track custom events such as signups, purchases and button clicks.
- Identify users to connect sessions to accounts.
- Proxy the script through your own domain to bypass ad blockers.
- Script attributes let you skip or mask URLs and tag events.