WordPress
Integrate Rybbit Analytics with your WordPress site
You can integrate Rybbit into your WordPress site to track user behavior and gather analytics. There are several ways to do this depending on whether you're using a hosted WordPress.com site or a self-hosted WordPress.org installation.
We recommend using the JavaScript snippet below instead of a plain <script> tag. Some WordPress plugins and page builders strip data-* attributes from HTML, which can break tracking. The JavaScript approach avoids this issue.
Quick Start
The easiest method for most users is the WPCode plugin (formerly Insert Headers and Footers). This works on both WordPress.com (Business plan+) and self-hosted WordPress.org sites.
Install WPCode Plugin
In your WordPress dashboard, go to Plugins > Add New and search for "WPCode". Install and activate the plugin.
Alternatively, download from WordPress.org.
Add the Tracking Script
- Go to Code Snippets > Header & Footer (or Settings > Insert Headers and Footers in older versions)
- Paste this snippet into the Header section:
<script>
(function() {
var s = document.createElement('script');
s.src = 'https://app.rybbit.io/api/script.js';
s.defer = true;
s.setAttribute('data-site-id', 'YOUR_SITE_ID');
document.head.appendChild(s);
})();
</script>- Replace
YOUR_SITE_IDwith your actual Site ID from your Rybbit dashboard - Click Save Changes
Verify Installation
Visit your site in a new browser tab, then check your Rybbit dashboard to confirm data is being received.
Alternative Methods
Add via functions.php
For self-hosted WordPress, you can add the script via your theme's functions.php file.
Use a child theme! If you modify the parent theme's functions.php, your changes will be lost when the theme updates.
- Go to Appearance > Theme File Editor
- Select your child theme's
functions.php - Add this code at the end of the file:
function add_rybbit_analytics() {
?>
<script>
(function() {
var s = document.createElement('script');
s.src = 'https://app.rybbit.io/api/script.js';
s.defer = true;
s.setAttribute('data-site-id', 'YOUR_SITE_ID');
document.head.appendChild(s);
})();
</script>
<?php
}
add_action('wp_head', 'add_rybbit_analytics');- Replace
YOUR_SITE_IDwith your actual Site ID and save
Modify header.php
You can directly edit your theme's header.php file to add the script.
Use a child theme! Changes to the parent theme's header.php will be lost on theme updates.
- Go to Appearance > Theme File Editor
- Open
header.php - Find the closing
</head>tag and paste this script just before it:
<script>
(function() {
var s = document.createElement('script');
s.src = 'https://app.rybbit.io/api/script.js';
s.defer = true;
s.setAttribute('data-site-id', 'YOUR_SITE_ID');
document.head.appendChild(s);
})();
</script>
</head>- Replace
YOUR_SITE_IDwith your actual Site ID and save
Create a Simple Plugin
Creating a small plugin ensures your tracking code persists through theme changes.
- Connect to your site via FTP/SFTP or use a file manager plugin
- Navigate to
/wp-content/plugins/ - Create a new folder called
rybbit-analytics - Inside that folder, create a file called
rybbit-analytics.phpwith this content:
<?php
/**
* Plugin Name: Rybbit Analytics
* Description: Adds Rybbit Analytics tracking to your WordPress site
* Version: 1.0
*/
function rybbit_add_tracking_script() {
?>
<script>
(function() {
var s = document.createElement('script');
s.src = 'https://app.rybbit.io/api/script.js';
s.defer = true;
s.setAttribute('data-site-id', 'YOUR_SITE_ID');
document.head.appendChild(s);
})();
</script>
<?php
}
add_action('wp_head', 'rybbit_add_tracking_script');- Replace
YOUR_SITE_IDwith your actual Site ID - Go to Plugins in WordPress and activate "Rybbit Analytics"
Troubleshooting
Script not loading
Check if the script is in the page source:
- Visit your site
- Right-click and select "View Page Source"
- Search for
rybbit- you should see the script tag
If the script is missing:
- Make sure you saved your changes
- Clear any caching plugins (WP Super Cache, W3 Total Cache, LiteSpeed Cache, etc.)
- Clear your CDN cache if using one (Cloudflare, etc.)
Caching plugin conflicts
Many WordPress caching plugins aggressively cache pages. After adding Rybbit:
-
Clear all caches:
- Your caching plugin's cache
- Any CDN cache (Cloudflare, etc.)
- Browser cache (Ctrl+Shift+R or Cmd+Shift+R)
-
Exclude the script from optimization: Some optimization plugins try to defer, combine, or minify scripts. If Rybbit isn't working, check these plugins:
- Autoptimize: Add
app.rybbit.ioto the exclusion list - WP Rocket: Exclude from JavaScript optimization
- LiteSpeed Cache: Add to JS excludes
- SG Optimizer: Exclude from combine/minify
- Autoptimize: Add
Page builder issues
If you're using a page builder like Elementor, Divi, WPBakery, or Beaver Builder, use the WPCode plugin method above rather than adding code through the page builder's custom HTML blocks. Page builders often sanitize HTML and may strip attributes from script tags.
Security plugin blocking the script
Security plugins like Wordfence or Sucuri may block external scripts. Add app.rybbit.io to your allowlist if tracking isn't working.
WordPress.com limitations
- Free/Personal/Premium plans: Cannot add custom JavaScript. You'll need to upgrade to a Business or eCommerce plan.
- Business/eCommerce plans: Use the WPCode plugin method above.
Ad blockers
Some visitors use ad blockers that block analytics scripts. This is expected behavior and will result in those visits not being tracked. If you're testing and see no data, try:
- Disabling your ad blocker temporarily
- Testing in an incognito/private window
- Testing from a different device
Script Options
You can customize the tracking script with additional data-* attributes. When using the JavaScript snippet approach, add them with s.setAttribute(). For a full list of options, see the Tracking Script reference.
Skip Pages from Tracking
Use data-skip-patterns to exclude certain pages (like admin or preview pages) from being tracked. Supports * (single segment) and ** (multiple segments) wildcards.
<script>
(function() {
var s = document.createElement('script');
s.src = 'https://app.rybbit.io/api/script.js';
s.defer = true;
s.setAttribute('data-site-id', 'YOUR_SITE_ID');
s.setAttribute('data-skip-patterns', '["/wp-admin/**", "/preview/**"]');
document.head.appendChild(s);
})();
</script>Mask Sensitive URLs
Use data-mask-patterns to track pageviews on sensitive pages without recording the actual URL path. The URL is replaced with the pattern itself in your analytics data.
<script>
(function() {
var s = document.createElement('script');
s.src = 'https://app.rybbit.io/api/script.js';
s.defer = true;
s.setAttribute('data-site-id', 'YOUR_SITE_ID');
s.setAttribute('data-mask-patterns', '["/my-account/**", "/orders/*/details"]');
document.head.appendChild(s);
})();
</script>Session Replay Privacy
If you have session replay enabled, you can mask or block sensitive content from recordings:
<script>
(function() {
var s = document.createElement('script');
s.src = 'https://app.rybbit.io/api/script.js';
s.defer = true;
s.setAttribute('data-site-id', 'YOUR_SITE_ID');
s.setAttribute('data-replay-block-selector', '.sensitive-content, #payment-form');
s.setAttribute('data-replay-mask-text-selectors', '[".user-name", "#email"]');
s.setAttribute('data-replay-mask-all-inputs', 'true');
document.head.appendChild(s);
})();
</script>Tracking WooCommerce Events
If you're running a WooCommerce store, see our WooCommerce guide for tracking purchases and other e-commerce events.