WordPress Integration
Install Rehearsals on your WordPress website to start recording user sessions.
Installation Methods
Method 1: Using a Plugin (Recommended)
The easiest way to add Rehearsals to WordPress is using a header/footer plugin.
Option A: Insert Headers and Footers Plugin
- Install and activate the Insert Headers and Footers plugin
- Go to Settings → Insert Headers and Footers
- In the Scripts in Header section, add:
<script>
window.deepPredictionSettings = {
apiKey: 'dp_proj_xxxxx',
organizationId: 'dp_org_xxxxx'
};
</script>
<script src="https://app.runrehearsals.com/recorder.js" async></script>
- Click Save
Option B: WPCode Plugin
- Install and activate WPCode
- Go to Code Snippets → Header & Footer
- Add the Rehearsals script to the Header section
- Save changes
Method 2: Theme Functions (functions.php)
Add this code to your theme's functions.php
file:
// Add Rehearsals to WordPress
function add_rehearsals_script() {
?>
<script>
window.deepPredictionSettings = {
apiKey: 'dp_proj_xxxxx',
organizationId: 'dp_org_xxxxx'
};
</script>
<script src="https://app.runrehearsals.com/recorder.js" async></script>
<?php
}
add_action('wp_head', 'add_rehearsals_script', 1);
Method 3: Custom Plugin
Create a simple plugin for Rehearsals:
- Create a new file:
wp-content/plugins/rehearsals/rehearsals.php
<?php
/**
* Plugin Name: Rehearsals Session Recording
* Description: Adds Rehearsals session recording to your WordPress site
* Version: 1.0
* Author: Your Name
*/
// Prevent direct access
if (!defined('ABSPATH')) {
exit;
}
// Add Rehearsals script to head
function rehearsals_add_script() {
$api_key = get_option('rehearsals_api_key');
$org_id = get_option('rehearsals_org_id');
if ($api_key && $org_id) {
?>
<script>
window.deepPredictionSettings = {
apiKey: '<?php echo esc_js($api_key); ?>',
organizationId: '<?php echo esc_js($org_id); ?>'
};
</script>
<script src="https://app.runrehearsals.com/recorder.js" async></script>
<?php
}
}
add_action('wp_head', 'rehearsals_add_script', 1);
// Add settings page
function rehearsals_add_admin_menu() {
add_options_page(
'Rehearsals Settings',
'Rehearsals',
'manage_options',
'rehearsals',
'rehearsals_settings_page'
);
}
add_action('admin_menu', 'rehearsals_add_admin_menu');
// Settings page HTML
function rehearsals_settings_page() {
?>
<div class="wrap">
<h1>Rehearsals Settings</h1>
<form method="post" action="options.php">
<?php settings_fields('rehearsals_settings'); ?>
<table class="form-table">
<tr>
<th scope="row">API Key</th>
<td>
<input type="text" name="rehearsals_api_key"
value="<?php echo get_option('rehearsals_api_key'); ?>"
class="regular-text" />
</td>
</tr>
<tr>
<th scope="row">Organization ID</th>
<td>
<input type="text" name="rehearsals_org_id"
value="<?php echo get_option('rehearsals_org_id'); ?>"
class="regular-text" />
</td>
</tr>
</table>
<?php submit_button(); ?>
</form>
</div>
<?php
}
// Register settings
function rehearsals_register_settings() {
register_setting('rehearsals_settings', 'rehearsals_api_key');
register_setting('rehearsals_settings', 'rehearsals_org_id');
}
add_action('admin_init', 'rehearsals_register_settings');
- Activate the plugin in WordPress admin
- Go to Settings → Rehearsals to configure
Advanced Configuration
User Identification
Track logged-in WordPress users:
function rehearsals_identify_user() {
if (is_user_logged_in()) {
$current_user = wp_get_current_user();
?>
<script>
window.addEventListener('load', function() {
window.rehearsals?.identify('<?php echo $current_user->ID; ?>', {
email: '<?php echo esc_js($current_user->user_email); ?>',
name: '<?php echo esc_js($current_user->display_name); ?>',
role: '<?php echo esc_js(implode(',', $current_user->roles)); ?>',
registered: '<?php echo esc_js($current_user->user_registered); ?>'
});
});
</script>
<?php
}
}
add_action('wp_footer', 'rehearsals_identify_user');
WooCommerce Integration
Track e-commerce events with WooCommerce:
// Track product views
add_action('woocommerce_after_single_product', function() {
global $product;
?>
<script>
window.rehearsals?.trackEvent('product_viewed', {
productId: '<?php echo $product->get_id(); ?>',
productName: '<?php echo esc_js($product->get_name()); ?>',
price: <?php echo $product->get_price(); ?>,
category: '<?php echo esc_js(wc_get_product_category_list($product->get_id())); ?>'
});
</script>
<?php
});
// Track add to cart
add_action('woocommerce_add_to_cart', function($cart_item_key, $product_id, $quantity) {
?>
<script>
window.rehearsals?.trackEvent('add_to_cart', {
productId: '<?php echo $product_id; ?>',
quantity: <?php echo $quantity; ?>
});
</script>
<?php
}, 10, 3);
// Track purchases
add_action('woocommerce_thankyou', function($order_id) {
$order = wc_get_order($order_id);
?>
<script>
window.rehearsals?.trackEvent('purchase_completed', {
orderId: '<?php echo $order_id; ?>',
total: <?php echo $order->get_total(); ?>,
items: <?php echo count($order->get_items()); ?>,
currency: '<?php echo $order->get_currency(); ?>'
});
</script>
<?php
});
Exclude Admin Pages
Don't record admin area sessions:
function rehearsals_exclude_admin() {
// Don't load on admin pages
if (is_admin()) {
return;
}
// Don't load for administrators
if (current_user_can('administrator')) {
return;
}
// Add script only for front-end
add_action('wp_head', 'add_rehearsals_script', 1);
}
add_action('init', 'rehearsals_exclude_admin');
Privacy Mode for Logged-Out Users
Respect user privacy preferences:
function rehearsals_privacy_mode() {
// Check if user has accepted cookies
if (!isset($_COOKIE['cookie_consent']) || $_COOKIE['cookie_consent'] !== 'accepted') {
return; // Don't load Rehearsals
}
?>
<script>
window.deepPredictionSettings = {
apiKey: 'dp_proj_xxxxx',
organizationId: 'dp_org_xxxxx',
// Additional privacy settings
maskAllInputs: <?php echo !is_user_logged_in() ? 'true' : 'false'; ?>
};
</script>
<script src="https://app.runrehearsals.com/recorder.js" async></script>
<?php
}
add_action('wp_head', 'rehearsals_privacy_mode', 1);
Multisite Configuration
For WordPress Multisite installations:
// Network-wide configuration
function rehearsals_multisite_config() {
$blog_id = get_current_blog_id();
$api_key = get_site_option('rehearsals_api_key_' . $blog_id);
$org_id = get_site_option('rehearsals_org_id');
if ($api_key && $org_id) {
?>
<script>
window.deepPredictionSettings = {
apiKey: '<?php echo esc_js($api_key); ?>',
organizationId: '<?php echo esc_js($org_id); ?>',
// Track which site in the network
metadata: {
siteId: <?php echo $blog_id; ?>,
siteName: '<?php echo esc_js(get_bloginfo('name')); ?>',
siteUrl: '<?php echo esc_js(get_site_url()); ?>'
}
};
</script>
<script src="https://app.runrehearsals.com/recorder.js" async></script>
<?php
}
}
add_action('wp_head', 'rehearsals_multisite_config', 1);
Performance Optimization
Lazy Load for Better Performance
function rehearsals_lazy_load() {
?>
<script>
// Wait for user interaction before loading
let rehearsalsLoaded = false;
function loadRehearsals() {
if (rehearsalsLoaded) return;
rehearsalsLoaded = true;
window.deepPredictionSettings = {
apiKey: 'dp_proj_xxxxx',
organizationId: 'dp_org_xxxxx'
};
const script = document.createElement('script');
script.src = 'https://app.runrehearsals.com/recorder.js';
script.async = true;
document.head.appendChild(script);
}
// Load on first interaction
['click', 'scroll', 'mousemove'].forEach(event => {
document.addEventListener(event, loadRehearsals, { once: true });
});
// Or load after 3 seconds
setTimeout(loadRehearsals, 3000);
</script>
<?php
}
add_action('wp_footer', 'rehearsals_lazy_load');
Troubleshooting
Common Issues
-
Script not appearing in source code
- Clear WordPress cache (W3 Total Cache, WP Super Cache, etc.)
- Check theme for
wp_head()
in header.php - Verify plugin/theme conflicts
-
Sessions not recording
- Check browser console for errors
- Verify API credentials are correct
- Ensure script is loading (Network tab in DevTools)
-
Conflicts with other plugins
- Test with default WordPress theme
- Disable other plugins one by one
- Check for JavaScript errors
Debug Mode
Enable WordPress debug mode to troubleshoot:
// In wp-config.php
define('WP_DEBUG', true);
define('WP_DEBUG_LOG', true);
define('WP_DEBUG_DISPLAY', false);
Testing
Test your installation:
- Visit your site in an incognito/private window
- Navigate through several pages
- Check your Rehearsals dashboard for the session
- Verify user identification (if configured)
What Happens Next
Now that Rehearsals is installed, you'll get access to powerful AI-driven features:
- Radar - Get instantly notified when users do positive or negative behaviors that impact revenue
- Rehearsals Brief - Receive McKinsey-level reports from 1,000+ data scientists analyzing your user sessions
- Customer Simulations - Rehearse revenue outcomes from pricing, product, and marketing changes in simulated environments
- Customer Data Extraction - Turn unstructured behavioral data into structured insights (names, interests, contact info)
- Visual Product Graph - Automatically map every button and screen to see exactly how customers navigate your WordPress site
You're all set—Rehearsals is now recording user sessions. Enjoy the insights!