Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3793778
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T12:49:40+00:00 2026-05-19T12:49:40+00:00

I am attempting to serve different phone numbers on a site based on a

  • 0

I am attempting to serve different phone numbers on a site based on a number of factors, allowing us to track inbound phone calls based on how users arrived at the page.

  1. Check to see if user is coming from advertising by checking for “?provider=” querystring, serve advertising number if present
  2. If not, check userAgent to serve “default” number to bots
  3. If userAgent is not a bot, check referrer and serve different tracking number based on common SERP clicks

This site is unable to run server-side scripting so this has to be done with javascript (which I am fairly inexperienced with). I’ve cobbled together bits and pieces but ultimately would like to combine everything and have it work together in a single .js file that can be called on page load.

Here’s what I have so far:

<script type="text/javascript">
//Querystring to check if paid session or organic
     function providercheck() {
        var str= location.href;
            if (str.indexOf("?provider=") > -1) {
                document.write("paid phone number");
            }
            else {
                botcheck();
            }
    }

    //Check userAgent to serve organic number to bots
     function botcheck() { 
            if(navigator.userAgent.toLowerCase().indexOf("googlebot") <= -1) {
                    document.write("default phone number");
                }
            else {
                    refcheck();
                }
    }

    //Check for referrer and serve number based on last referrer
    function refcheck() {
        var last_referrer = document.referrer;
        if (last_referrer.indexOf("google") > -1) {
            document.write("google tracking number");
        }
        else if (last_referrer.indexOf("yahoo") > -1) {
            document.write("yahoo tracking number");
        }
        else {
            document.write("default number");
        }
    }
</script>

Any help or guidance is very appreciated. I also need to set a session cookie to continue to serve the same number until a user leaves the site, but wanted to get this working first

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T12:49:40+00:00Added an answer on May 19, 2026 at 12:49 pm

    You could try something like this:

    put this span somewhere on your page:

    <span id="phoneNumber">Superdefaultnumber</span>

    And then this code in a script tag in the head of your document:

    var setNumber = function(){
        var spanNode = document.getElementById("phoneNumber");
        if (!spanNode) {throw new Error("Unable to find span");}
    
        if (location.href.indexOf("?provider=") > -1) {
            spanNode.innerHTML = "paid phone number";
        }    
    
        //Check userAgent to serve organic number to bots
        if(navigator.userAgent.toLowerCase().indexOf("googlebot") <= -1) {
            spanNode.innerHTML = "default phone number";
        }
    
        //Check for referrer and serve number based on last referrer
        var last_referrer = document.referrer;
        if (last_referrer.indexOf("google") > -1) {
            spanNode.innerHTML = "google tracking number";
        }
        else if (last_referrer.indexOf("yahoo") > -1) {
            spanNode.innerHTML = "yahoo tracking number";
        }
        else {
            spanNode.innerHTML = "default number";
        }    
    };
    
    
    window.addEventListener("load", setNumber);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to track events when links are clicked on my site in
I'm attempting to add a function to my site where users can set their
so currently what I am attempting to do is, remote onto a different server,
I am currently attempting to get remote desktop server access to a different server,
I am attempting to understand how TFS 2008 (and 2010 if it's different) store
While setting up a test environment I was attempting to set up many different
I'm attempting to login to an Ubuntu server and search logs at several different
I'm attempting to track down a javascript exception I'm getting when parsing some JSON
When attempting to run IE on Windows Server 2008 under different user accounts using
So I'm attempting to setup em-websocket (or potentially Goliath ), so that users can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.