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

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: the user’s 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  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.
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:


  • 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.

Avoid creating accidental duplicates when using the Marketo REST API

In a recent client project, we discovered duplicate records being created by a third-party system integrated via Marketo’s REST API. These duplicate records had the same email address.

While Marketo does de-duplicate leads (based on email addresses) from web forms and list imports, it does not necessarily de-dupe leads coming in via the REST API. It depends which REST operation is used.

Sending a POST request to the /rest/v1/leads.json endpoint, there are three different actions that can be sent in the syncLeadRequest parameter to create lead records: createOnlycreateDuplicate or createOrUpdate.

Most developers will probably want to use createOrUpdate in their integrations. This is a so-called “upsert” operation, as it can either update or insert a record. It first checks Marketo to see whether a lead exists. If it does exist, the query updates the existing record. If it does not exist, the query inserts a new record to the Marketo database.

The other two operations — createOnly and createDuplicate — will insert a new record each time they are called, with the exception that createOnly will fail if a matching record is found in the defined lookupField, which defaults to email if not set.

Here is some documentation on this functionality:

The client’s implementation correctly used the createOrUpdate operation, and the specified lookupField was correctly set to email. Despite the check-for-duplicates nature of this operation, however, duplicates were being created nonetheless, which left the developer scratching his head.

Here’s the gotcha: it is actually possible in some cases for createOrUpdate to create a duplicate record!

This note below from the Marketo docs explains (emphasis added):

When performing lead upsert requests concurrently or in quick succession, duplicate records may result when making multiple requests with the same key value if a subsequent call with the same value is made before the first returns.  This can be avoided either by using the createOnly, or updateOnly as appropriate, or by queuing calls and waiting for your call to return before making subsequent upsert calls with the same key.

So, basically, hold your horses. Slow your app down. Throttle the API calls in your app so that they are not sent so quickly that Marketo cannot respond before subsequent requests come in. Happy coding!

Marketo Summit 2018 Highlights

Our new teammates from RevEngine Marketing have once again released their annual Marketo Summit highlights video for 2018. Check out the recap video below.

Thanks for watching, and we look forward to seeing you at the Marketo Summit in 2019 in Las Vegas!

Centralize Your UTM Link Management for Better Tracking and Reporting in Marketo

Recently, a client told me that they use Google’s Campaign URL Builder tool, and that it works just fine for them. I have used that tool myself and found it useful. Digital Pi CEO Ryan Vong even mentioned it in one of his posts on using UTM parameters in Marketo. The tool certainly has its place; however, it falls short for regular use in real-world marketing operations, and especially as it pertains to Marketo.

This got me thinking. How many people use the Google tool and do not realize its shortcomings? More specific to this audience, how many Marketo practitioners use this tool and are inadvertently ruining their reporting on digital marketing tactics in Marketo?

There are at least two relevant key points to consider in your UTM strategy. Let’s review. (To the sticklers out there: I’m intentionally using “link” and “URL” interchangeably. I know they’re not technically the same thing. Just go with it.)

UTM links must be unique

If you’re using UTM parameters, it is vital to your reporting that each and every link created be unique. Using Google’s tool, it is quite easy to inadvertently create a duplicate link — one that matches a link previously created and used. When these duplicate links are used to create Marketo programs and smart campaigns to track the UTM parameters, they may actually mirror the UTM values configured in other pre-existing Marketo programs. As such, they result in “double dipping” for reporting purposes and accidentally assigning success credit to multiple programs for what are supposed to be distinct touch points on a customer journey. To address this issue, a centralized, authoritative repository is needed to store all UTM links created to ensure that each link is unique and that the particular set of UTM parameters has not been used before.

UTM values must be consistent

Also essential to effective use of UTM parameters is consistency. UTM parameters are case sensitive, and any difference — in punctuation or even in capitalization — creates unique values. Many characters must also be properly encoded and accounted for in your Marketo smart campaign setup. The Google builder accounts for some of this — properly encoding reserved characters in the final URL — but does not impose hard-and-fast parameter normalization rules. This should be dictated by your own company’s business rules and internal processes, so it’s not something that Google’s generic URL builder can or even should enforce. This must be managed another way.

Digital Pi’s UTM Link Builder

So how do we handle this at Digital Pi? Well, as with the rest of our Gold Standard Marketo infrastructure setup, we have a standardized, scalable solution for creating and managing UTM-laden URLs — the Digital Pi UTM Link Builder.

Our UTM link builder tool helps to prevent duplicate URLs from being created and used by highlighting duplicates so that they can be modified to be unique from all previously created URLs.

The tool also provides predefined picklists for utm_medium and utm_source values, mitigating the possibility for typos and other human error. Further, it normalizes utm_campaign values, converting inputs to lowercase and removing spaces and all punctuation except dashes and underscores. This consistency helps to ensure seamless reporting on normalized values.

This tool is made available to all Digital Pi clients. For further information, please contact us.

How do you use UTMs with Marketo?

So what about you? Are you using UTM parameters with your Marketo instance? If so, how? And how do you create the URLs? How do you ensure that you do not have duplicate URLs? How do you ensure that your UTM values are consistent across all campaigns, team members and geos? Let me know in the comments below.

Require Business Emails on Your Marketo Forms

A work email address gives you the internet domain name of the person’s employer, which, besides allowing you to reach them with work-related offerings at their work email address, can be a key to unlocking other important data that can be appended to the Person record, including number of employees, revenue, SIC or NAICS codes, and DUNS number. So, if your organization prefers a work or business email address over personal a email address, then you can use this simple solution to add that functionality to forms.

The challenge

To get this rich demographic and firmographic data though, you need to make sure that people are not submitting their personal email addresses on your Marketo forms. We see this request often, both on the Marketo Community and from our own clients. But Marketo does not not natively support this functionality.

The approach

Luckily, Marketo’s Forms 2.0 made available a JavaScript API that we can use to extend the native form functionality — in this case, to add a filter for email addresses entered into Marketo forms.

Using JavaScript, we first define a list of common domain names that are known to provide free email addresses —,,,,, (Of course, there are thousands of other domains like these, but these few are likely the most common that most marketers encounter.)

Next, we need an error message to alert the user that they need to enter their business email address, something like: “Please enter your business email address.”

Finally, we need to create logic that determines whether the submitted email address is in the list of disallowed domains that we created, and, if so, to prevent the Marketo form submission from happening and instead alert the user to enter their business email address.

The solution

The following script does exactly that:

  • define blocked email domains
  • define error message to user
  • determine whether email address contains blocked domain
  • alert user to try again

To use the script, you will first need to download it to your computer.

[edgtf_button size=”small” type=”” text=”Download Script” custom_class=”” icon_pack=”font_awesome” fa_icon=”fa-download” link=”” target=”_self” color=”#fff” hover_color=”#ccc” background_color=”#1595a3″ hover_background_color=”#35b5c3″ border_color=”#058593″ hover_border_color=”#058593″ font_size=”24″ font_weight=”” margin=”20px”]

Then, edit the list of domains you want to block if you want something different and update the error message to match your brand voice. Be sure to wrap each domain in quotes and separate them with commas. Do not include a comma after the last domain. (This will break the script.)

var domains = ['','','','','','']

var error = 'Please enter your business email address.'

Last, simply upload it to your Design Studio and include in your Marketo landing page template(s) and in your website footer. Your <script> tag should look something like this:

<script src=""></script>

Alternatively, instead of uploading to Marketo’s Design Studio, you or your web team can add it to your tag manager tool (like Google Tag Manager or Adobe Tag Management).

If added to your pages correctly, the script will fire when needed, automatically detecting Marketo forms on any page where it is included and extending their functionality to require a business email address.