Show or Hide Marketo Form Fields Based on a User’s Country

Show or Hide Marketo Form Fields Based on a User’s Country

Blog Banner: Show or Hide

Our team has received many requests recently to create preference centers to help clients comply with privacy-related legislation — CASL and GDPR chief among them. Some countries’ legal requirements are quite stringent, while others are more relaxed. Requirements differ from client to client, but a similar request seems to come up in the conversation because of the difference between countries: can we show certain fields to people in certain countries, but not show those fields to people in other countries?

The challenge

Of course, Marketo’s form editor does give its marketing automation practitioners a powerful tool to conditionally show or hide elements based on field values. Conceivably, one could accomplish the requested functionality using Marketo’s built-in Visibility Rules to show a field only when the Country value is set to certain countries — say, those in the EU.

However, this only works if there is data in the Country field. If someone is filling out a form for the first time, Marketo won’t have the Country information to know whether to show or hide the conditional fields.

You could enable Marketo’s Prefill functionality, but that only works (natively) on Marketo landing pages and not on Marketo forms embedded on your main website. Again, the Country data is not available.

The approach

As it turns out, we have an important piece of information that, if used correctly, can yield the user’s country: his IP address. Using the IP address, we can look up which country the web request originated in, much like a web analytics tool like Google Analytics.

Moreover, there are a slew of free services out there that provide geographical lookup APIs based on IP address. One such service is geoiplookup.io.  All you have to do is send a user request to their server, and you get back the user’s country code, among other useful information.

If you have a defined set of country codes to compare against your newly retrieved country code, you can show or hide fields based on whether or not the detected country is in the list.

This approach works:

  • on Marketo landing pages
  • on embedded Marketo forms (on your main website)
  • for anonymous visitors

The solution

Below is a simple JavaScript file that you can use as a starting point to show or hide fields on your Marketo forms based on which country the user is in.

Download Script

To use the script, you will need to customize which fields to show or hide. You may need to have a web developer help you with this; the form fields to show or hide are specified in the code itself:

Prerequisites:

  • fields must be present on the form
  • script is configured using the SOAP API names of the fields

Post below in the comments if this helped you or if you have questions or other comments.

jbourne@digitalpi.com

Jon Bourne is a marketer with a varied background in technology, design, agency consulting and direct sales. He has been a front-end developer, account executive, technology consultant, creative director, and head of marketing as well as an owner, partner and executive in multiple design and development agencies. Jon brings his technical background together with branding and marketing savvy to deliver return-oriented strategies that drive top-line growth and create efficiencies and cost savings for client companies—turning marketing organizations from cost centers to profit centers.

LEAVE A COMMENT