Dynamically Change Local Phone Number using RTP

February 2, 2016 | by

Personalization is everything – we figured this out a long time ago.

With that being said, it’s still surprising to me that every time I need immediate assistance, it is so hard to find the relevant local phone numbers on a website.

Good thing we have Marketo Real-Time Personalization (RTP) installed on www.marketo.com.  We can leverage the RTP Visitor API to dynamically change the phone number that a web visitor sees in different sections of the website.

Wow!  Can you believe this?  How does this magic work?

First, you’ll need to have RTP installed on your web site as described here.

Next, follow the instructions below and implement the JavaScript code on your website:

  1. Insert your international phone number in the defaultPhone configuration
  2. Insert the HTML element id(s) in the divIds configuration
  3. If you want to make the phone number a click-to-call link for mobile browsers, then set the mobileLink configuration to true.
  4. Map the different locations with their phone numbers in the cityPhone, statePhone, and countryPhone configurations

For example, here are sample values for configuration settings:

Finally, insert an HTML anchor tag that contains an id matching one of the ids in divIds (from step 2 above). For example, if you specified “phoneId1” in divIds, then your HTML anchor tag would look like this:

The script will check if there is a match in this order: cityPhone > statePhone > countryPhone > defaultPhone You can also replace the phone numbers with text (Example: “Join our San Francisco User Group!”) or HTML code and dynamically change the content based on the geo-location. Enjoy!