Skip to content
Documentation menu: WordPress

WordPress integration

Add theBizness.ai analytics to your WordPress site with multiple installation methods.

Setup time

2 minutes

Difficulty

Easy

Performance

Optimized

Choose your installation method

functions.php method

Add tracking code through a child theme's functions.php file (recommended)

Basic implementation

Add this code to a child theme's functions.php file. A theme update overwrites the parent theme's copy:

// Add to your child theme's functions.php file (a parent theme update overwrites its functions.php)
function add_thebizness_analytics() {
    // Only load on frontend
    if (is_admin()) {
        return;
    }
    
    $website_id = 'your-website-id';
    // Host only: no protocol, port or subdirectory path
    $domain = wp_parse_url(home_url(), PHP_URL_HOST);
    
    echo '<script async defer data-website-id="' . esc_attr($website_id) . '" data-domain="' . esc_attr($domain) . '" src="https://thebizness.ai/js/script.js"></script>';
}
add_action('wp_head', 'add_thebizness_analytics');

Enhanced with configuration

For better security and flexibility, use this enhanced version:

// Enhanced version with environment variables
function add_thebizness_analytics() {
    if (is_admin()) {
        return;
    }
    
    // Get from wp-config.php constants or WordPress options
    $website_id = defined('THEBIZNESS_WEBSITE_ID') ? THEBIZNESS_WEBSITE_ID : get_option('thebizness_website_id');
    $domain = defined('THEBIZNESS_DOMAIN') ? THEBIZNESS_DOMAIN : wp_parse_url(home_url(), PHP_URL_HOST);
    
    if (empty($website_id)) {
        return; // Don't load if not configured
    }
    
    // Clean domain
    $domain = preg_replace('(^https?://)', '', $domain);
    
    echo '<script async defer data-website-id="' . esc_attr($website_id) . '" data-domain="' . esc_attr($domain) . '" src="https://thebizness.ai/js/script.js"></script>';
}
add_action('wp_head', 'add_thebizness_analytics');

Add to wp-config.php

// Add to wp-config.php (above the "That's all, stop editing!" line)
define('THEBIZNESS_WEBSITE_ID', 'your-website-id');
define('THEBIZNESS_DOMAIN', 'yourdomain.com');
Why functions.php?
  • • Automatically excludes admin pages
  • • Survives theme updates when it lives in a child theme's functions.php
  • • Can be configured via wp-config.php
  • • Easy to remove if needed

Custom plugin

Create a custom plugin with admin interface for easy management

Create the plugin file

Create wp-content/plugins/thebizness-analytics/thebizness-analytics.php:

<?php
/**
 * Plugin Name: theBizness Analytics
 * Description: Add theBizness.ai analytics tracking to your WordPress site
 * Version: 1.0.0
 * Author: Your Name
 */

// Prevent direct access
if (!defined('ABSPATH')) {
    exit;
}

class TheBiznessAnalytics {
    
    public function __construct() {
        add_action('init', array($this, 'init'));
    }
    
    public function init() {
        // Add admin menu
        add_action('admin_menu', array($this, 'add_admin_menu'));
        
        // Add script to frontend
        add_action('wp_head', array($this, 'add_tracking_script'));
        
        // Register settings
        add_action('admin_init', array($this, 'register_settings'));
    }
    
    public function add_admin_menu() {
        add_options_page(
            'theBizness Analytics',
            'Analytics',
            'manage_options',
            'thebizness-analytics',
            array($this, 'admin_page')
        );
    }
    
    public function register_settings() {
        register_setting('thebizness_analytics', 'thebizness_website_id');
        register_setting('thebizness_analytics', 'thebizness_domain');
    }
    
    public function add_tracking_script() {
        if (is_admin()) {
            return;
        }
        
        $website_id = get_option('thebizness_website_id');
        $domain = get_option('thebizness_domain');
        
        if (empty($website_id)) {
            return;
        }
        
        if (empty($domain)) {
            $domain = wp_parse_url(home_url(), PHP_URL_HOST);
        }
        
        echo '<script async defer data-website-id="' . esc_attr($website_id) . '" data-domain="' . esc_attr($domain) . '" src="https://thebizness.ai/js/script.js"></script>';
    }
    
    public function admin_page() {
        ?>
        <div class="wrap">
            <h1>theBizness Analytics Settings</h1>
            <form method="post" action="options.php">
                <?php
                settings_fields('thebizness_analytics');
                do_settings_sections('thebizness_analytics');
                ?>
                <table class="form-table">
                    <tr>
                        <th scope="row">Website ID</th>
                        <td>
                            <input type="text" name="thebizness_website_id" value="<?php echo esc_attr(get_option('thebizness_website_id')); ?>" class="regular-text" />
                            <p class="description">Your theBizness.ai Website ID</p>
                        </td>
                    </tr>
                    <tr>
                        <th scope="row">Domain</th>
                        <td>
                            <input type="text" name="thebizness_domain" value="<?php echo esc_attr(get_option('thebizness_domain')); ?>" class="regular-text" placeholder="<?php echo esc_attr(wp_parse_url(home_url(), PHP_URL_HOST)); ?>" />
                            <p class="description">Leave blank to auto-detect from site URL</p>
                        </td>
                    </tr>
                </table>
                <?php submit_button(); ?>
            </form>
        </div>
        <?php
    }
}

new TheBiznessAnalytics();
Plugin benefits
  • • Easy admin interface in WordPress dashboard
  • • Survives theme changes and updates
  • • Can be activated/deactivated easily
  • • Professional plugin structure

Direct header.php edit

Add script directly to your theme's header file

Add to header.php

Add this script tag to your theme's header.php file, just before the </head> tag:

<!-- Add to your theme's header.php file, before </head> -->
<script async defer data-website-id="your-website-id" data-domain="yourdomain.com" src="https://thebizness.ai/js/script.js"></script>
Important notes
  • • This method will be lost when theme updates
  • • Create a child theme to preserve changes
  • • Consider using functions.php instead

Admin panel methods

Use WordPress admin interface to add tracking code

Method 1: Theme customizer

  1. 1. Go to Appearance → Customize
  2. 2. Classic themes: look for a field such as Header Scripts or Custom HTML, and paste the full <script> tag there. Not every theme has one.
  3. 3. Do not use Additional CSS. It accepts stylesheet text only, so it will not run the script, and it shows no error
  4. 4. Block themes usually have no such field. Use Method 2 (a header and footer plugin), or add the code in functions.php as shown above

Method 2: Popular plugins

Insert Headers and Footers

Popular plugin for adding code to header/footer sections

Header Footer Code Manager

Advanced code injection with conditions

Method 3: Theme options

Many premium themes include custom fields for analytics codes:

  • • Look for "Analytics Code" or "Tracking Code" fields
  • • Check theme documentation for specific instructions
  • • Usually found in Theme Options or Theme Settings

Verify installation

Make sure analytics are working on your WordPress site

Front-end check

  1. 1. Visit your website (not admin area)
  2. 2. Right-click → Inspect Element
  3. 3. Go to Network tab in DevTools
  4. 4. Refresh and look for script.js

WordPress specific

  1. 1. Test on different post types (posts, pages)
  2. 2. Check category and archive pages
  3. 3. Verify script NOT loading in admin area
  4. 4. Test with caching plugins active
Common WordPress issues
  • • The tracker does nothing on localhost, *.local, *.test, private IP addresses or file:// pages. It logs a "Tracking disabled on localhost" warning in the console. Verify on a publicly reachable domain.
  • • Clear all caching plugins after installation
  • • Some security plugins may block external scripts
  • • If your site sends a Content-Security-Policy header, allow https://thebizness.ai in script-src and connect-src. Blocked requests show only as CSP errors in the browser console
  • • Make sure you're testing on frontend, not admin
  • • Check for theme conflicts in customizer preview

WordPress analytics active

Your WordPress site is now tracking visitor analytics. Here's what to explore next:

Revenue attribution

Connect Stripe or send a purchase event from your order-complete page

Content analytics

See which posts and pages perform best

UTM campaigns

Track marketing campaigns and referrals