wiki/knowledge/call-tracking/callrail-number-swapping-javascript.md Layer 2 article 622 words Updated: 2026-04-05
↓ MD ↓ PDF
callrail javascript wordpress number-swapping call-tracking troubleshooting

CallRail Number Swapping via JavaScript

Overview

When implementing CallRail dynamic number swapping on WordPress sites, the CallRail WordPress plugin is unreliable and should be replaced with the direct JavaScript snippet. The plugin can silently fail or conflict with the snippet, preventing number swaps from occurring even when the CallRail account and pool configuration are correct.

The Problem

Dynamic number swapping may appear to be configured correctly in CallRail — pool defined, swap target set, numbers assigned — but the banner or header phone number never changes for new visitors. The CallRail diagnostic test returns: "The wrong code snippet was installed."

Root cause: The WordPress CallRail plugin either fails to inject the tracking script correctly or conflicts with a separately added JS snippet, causing neither to function properly.

The Fix

Replace the WordPress plugin with the direct JavaScript snippet injected via a code snippet manager (e.g., WPCode, Insert Headers and Footers, or similar).

Steps

  1. Get the JavaScript snippet from CallRail:
    - In CallRail, go to Integrations (puzzle piece icon in the left nav)
    - Find JavaScript Snippet at the top of the list
    - Click Copy to Clipboard

  2. Deactivate the CallRail WordPress plugin:
    - In WordPress admin, go to Plugins
    - Find the CallRail phone tracking plugin (e.g., "AB Call Rail Phone Tracking")
    - Click Deactivate

  3. Add the snippet directly to the site header:
    - Open your code snippet manager
    - Create a new snippet named "CallRail"
    - Paste the JavaScript
    - Set location to Header (before </head>)
    - Save and activate

  4. Clear site cache — cached pages may still serve the old (non-swapping) number. Clear all caches before testing.

  5. Verify with an incognito window — use a browser profile that has never visited the site, as CallRail sets a cookie and will not swap the number for returning visitors.

Confirming It Works

Why the Plugin Fails

The WordPress plugin is a wrapper around the same JavaScript snippet, but it can:
- Inject the script at the wrong position in the DOM
- Conflict with a separately installed snippet, causing duplicate or malformed script tags
- Fail silently without surfacing errors in the WordPress admin

Injecting the snippet directly via a header code manager bypasses all of these failure modes.

Important Notes

Evidence

Confirmed during a [1]. The CallRail plugin was deactivated, the JS snippet was added to the site header via a code snippet manager, and an incognito window test confirmed the swap was working. Cache clearing was queued as a follow-up step.