Installing the JavaScript snippet

CallRail’s JavaScript snippet allows you to integrate call tracking on your website using dynamic number insertion (DNI). When customers navigate to your website from a marketing campaign, they’ll see the correct tracking number based on which marketing source they came from. 

The same JavaScript snippet powers both call and form tracking, so if you're using both products in CallRail, you don't have to install the same script more than once. After your company's snippet has been added to each page of your website, it gathers all the details of your customer's interactions on your website and relays their activity back to CallRail.

If you are using a WordPress or Wix website, please follow these instructions to install the WordPress plugin or the Wix plugin instead of using the JavaScript snippet. These will offer you the same functionality. 

How the JavaScript snippet works

Each company in your CallRail account has its own, unique JavaScript snippet. The installation is just like installing Google Analytics — a single JavaScript snippet added to each page of your website before the </body> tag. This script tag works for both HTTP and HTTPS pages.

To use the dynamic number insertion feature, create tracking numbers within your CallRail account to track visitors from a specific source, like Google Ads. When a visitor navigates to your website through one of the sources you’re tracking, CallRail’s JavaScript will detect the phone numbers on your web page and swap them with the correct tracking number. We’ll then store the visitor’s source in a cookie so they’ll continue to see the same tracking number each time they return to your website (unless your snippet is removed).

Getting started

There are a few important details you’ll need to know before you get started with dynamic number insertion:

  1. Once you’ve installed the JavaScript snippet on your website, be sure to test your installation before your campaign begins.
  2. Dynamic number insertion detects multiple number formats, including:
    111-222-3333, 111.222.3333, and (111) 222-3333.
  3. Special steps are necessary to swap phone numbers in images. Learn more about image swapping with this help article.
  4. Ideally, CallRail’s JavaScript snippet should be installed on every page of your website, but it must be embedded on the visitor’s landing page, as well as each page on your website that displays a phone number or a web form you'd like to track.

Installing the JavaScript snippet on your website

Each company in your account has its own unique JavaScript code for dynamic number insertion. If you have multiple companies in your CallRail account, you’ll have a different code for each.

  1. Click the Settings icon on the left navigation bar.

  2. Choose the company where you'd like to install the JavaScript code.

  3. Click Integrations at the top of the page.

  4. Choose JavaScript Snippet from the list of integrations.

  5. Copy the JavaScript provided. It should look similar to this sample JavaScript code.

  6. Paste your script into each page of your website right before the </body> tag.

Auto-test your JavaScript installation

Once you've installed the JavaScript snippet on your web page, you can use the test dynamic number insertion feature to confirm that your snippet has been installed correctly and your tracking numbers are swapping on your siteFollow the steps in this article to test your JavaScript installation.


Can I test that dynamic number insertion is working?
Yes, there are a couple of ways to test that your DNI script is working properly. You can use our auto-test feature to see live swap examples of your tracking numbers swapped on your page, or you can manually test dynamic number insertion.

I’m seeing the error: “The code snippet contains curly quotes or stylized text” when testing via the auto-test tool. What should I do?
Make sure your snippet has no stylized characters, this can include curly quotes, elongated dashes, end dashes.

If you’ve confirmed that your snippet does not have any stylized text and you’re still receiving errors, we recommend manually testing your web page(s) instead.

Why isn’t my telephone number swapping?
Have you cleared your cookies, or tried accessing the website in a private browsing session? The most important part of testing dynamic number insertion is to simulate the experience of a first-time visitor before testing. Otherwise, the swap code will detect you as a visitor to the website from a previous session.

Troubleshoot common dynamic number insertion issues with this help article.

Can I use dynamic number insertion on my GoDaddy site?
No, we are not compatible with GoDaddy due to their use of iframes.

Can I use dynamic number insertion on my Wix site?
If you are on any of Wix's premium plans, you can install CallRail's JavaScript snippet in Google Tag Manager, and add Google Tag Manager to your Wix site.

Use this article to learn how to add dynamic number insertion to Google Tag Manager.

Use these Wix instructions to learn how to add Google Tag Manager to your premium Wix site.

Do I need to remove the JavaScript after I deactivate call tracking?
If you don’t plan on creating new tracking numbers in the same company where your tracking number(s) has been deactivated, you can safely remove the CallRail JavaScript code. However, if you leave the swap script on your website, the numbers will no longer swap since those numbers have been deactivated.

Can I have a white-labeled version of my swap code?
Yes. Use the instructions above when logged into CallRail via your white label domain to access a white label version of your swap script.

I have multiple JavaScript codes for different locations of my business, can I install more than one JavaScript code on my website?
As a best practice, we recommend installing one JavaScript code on your website. While we can support installing up to three different CallRail JavaScript codes on a single website, but you may notice a reduction in number swapping speed. If you require multiple JavaScript codes installed on a single site, please reach out to our Support team for additional recommendations.

Was this article helpful?
5 out of 9 found this helpful

Articles in this section

See more
Ask the Community
Find best practices, post, and learn from CallRail users.
CallRail Support Hours
Weekdays 9:00am - 9:00pm EST