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.

Track YouTube Videos in Marketo

[vc_row][vc_column][vc_column_text]Many of our clients host marketing videos, recorded webinars, or other video content on YouTube. It’s simplicity and dominance in the online video space make it the de facto standard for many marketers.

No Marketo integration with YouTube’s standard embed code

Despite its ease of use, however, many Marketo practitioners have been frustrated that they have no visibility from within Marketo to leads’ interactions with their YouTube video content. For this one feature, many marketers utilize video hosting solutions like VidYard to get video interaction information into Marketo.

But there is another way, and it is much easier on your budget.

Track YouTube videos in Marketo with Javascript APIs

Our team at Digital Pi has developed and refined a simple script that you can include—for free!—in your Marketo landing pages to embed a YouTube video and get key video interaction data back into Marketo. This data can then be used to change program statuses, increase leads’ behavior scores, or anything else that can be added to a workflow in Marketo.

One of the key features of the script is that you can see which leads reached self-defined video to milestones.

Example scenario: let’s say you have a product demo video and a corresponding Marketo program based on your Product Marketing channel.

  1. When a known lead views the landing page, her program status is set to Member.
  2. When she views 50% of the video, that milestone is logged and triggers a program status change to Interested.
  3. When she views 100% of the video, the program status changes to Engaged.
  4. At this point, you could have the landing page generate a modal popup with a Marketo form to request a free sample kit, because you know she is likely ready to try it out.

A simple demo

Here is an example video. Below it is a log that shows what information is sent to Marketo. Feel free to play and pause the video to watch what happens as the information is logged. As you watch the video, look for milestones to automatically show up in the log at 25%, 50% and 75% completion.

By the way, this all works on both Android and iOS mobile devices too. I recommend testing on all platforms.[/vc_column_text][vc_raw_html]JTNDZGl2JTIwaWQlM0QlMjJkaWdpdGFscGkteXQtcGxheWVyJTIyJTIwZGF0YS15b3V0dWJlLWlkJTNEJTIyamRpLXFxRnYyNEElMjIlM0UlM0MlMkZkaXYlM0UlMEElM0NwJTIwaWQlM0QlMjJkaWdpdGFscGkteXQtcGxheWVyLXJlc3VsdHMtdGl0bGUlMjIlMjBzdHlsZSUzRCUyMm1hcmdpbiUzQSUyMDEwcHglMjAwJTIwMCUzQiUyMiUzRSUzQ3N0cm9uZyUzRSUzQ2NvZGUlM0VjbGljayUzQyUyRmNvZGUlM0UlMjBhY3Rpb25zJTIwbG9nZ2VkJTIwdG8lMjBNYXJrZXRvJTIwJTI4c2Nyb2xsYWJsZSUyOSUzQSUzQyUyRnN0cm9uZyUzRSUzQyUyRnAlM0UlMEElMEElM0NkaXYlMjBpZCUzRCUyMmRpZ2l0YWxwaS15dC1wbGF5ZXItcmVzdWx0cyUyMiUyMHN0eWxlJTNEJTIyZm9udC1zaXplJTNBJTIwLjhlbSUzQiUyMGxpbmUtaGVpZ2h0JTNBJTIwMS40ZW0lM0IlMjBiYWNrZ3JvdW5kJTNBJTIwJTIzZWVlJTNCJTIwb3ZlcmZsb3clM0ElMjBzY3JvbGwlM0IlMjBtYXJnaW4lM0ElMjAwJTIwMCUyMDEwcHglM0IlMjBwYWRkaW5nJTNBJTIwMTBweCUzQiUyMG1pbi1oZWlnaHQlM0ElMjA0MHB4JTNCJTIwbWF4LWhlaWdodCUzQSUyMDgwcHglM0IlMjBib3gtc2hhZG93JTNBJTIwMCUyMDAlMjAyMHB4JTIwcmdiYSUyODAlMkMwJTJDMCUyQzAuMSUyOSUyMGluc2V0JTNCJTIyJTNFJTNDc3BhbiUyMHN0eWxlJTNEJTIyY29sb3IlM0ElMjAlMjM2NjYlM0IlMjIlM0VQbGF5JTIwdGhlJTIwdmlkZW8lMjBhYm92ZSUyMHRvJTIwc2VlJTIweW91ciUyMGludGVyYWN0aW9ucyUyMGxvZ2dlZCUyMGhlcmUuJTNDJTJGc3BhbiUzRSUzQyUyRmRpdiUzRSUwQSUwQSUzQ3NjcmlwdCUyMHNyYyUzRCUyMmh0dHBzJTNBJTJGJTJGZGlnaXRhbHBpLmNvbSUyRndwLWNvbnRlbnQlMkZ1cGxvYWRzJTJGMjAxNiUyRjA4JTJGdHJhY2steW91dHViZS12aWRlb3MtaW4tbWFya2V0by1leGFtcGxlLXNjcmlwdC1kaWdpdGFsLXBpLW1hcmtldG8tY29uc3VsdGluZy5qcyUyMiUzRSUzQyUyRnNjcmlwdCUzRQ==[/vc_raw_html][vc_column_text]

The YouTube tracking script

Here is the script: Digital Pi’s YouTube tracking script for Marketo

To use the script, you will need to make a few changes to your Marketo landing page template(s) where you want to use the video functionality:

  1. Include this script just before the closing </body> tag:<script src=””></script>(I recommend saving the script to your computer, uploading it to Marketo’s Design Studio, then changing the above URL to reflect your Marketo-hosted version.)
  2. Place this code snippet where you want the video to appear:<div id=”digitalpi-yt-player” data-youtube-id=”XXXXXXXXXX”></div>
  3. Change XXXXXXXXXX to your YouTube video ID, from the YouTube URL

Accessing video tracking info in Marketo

Okay, so the video is tracked. How can you, the savvy Marketo practitioner, access this information and use it in your marketing? There are several things you need to know.

  1. In Marketo, these YouTube video interactions are logged as click events.
  2. The page URL is always the same——regardless of which page the request originated on.
  3. This tracking works even on anonymous leads–before they submit their name or email address.

Here is how the video interactions show up as lead activities.

Activity Details for Click Link entry in test lead's Activity Log Activity Details for Click Link entry in test lead’s Activity Log

In a smart list, you could use a filter for all leads that reached the 25-percent-watched milestone.

Marketo filter for tracked YouTube video interaction Marketo filter for tracked YouTube video interaction

Or you could use the same parameters in a trigger.

Marketo trigger for tracked YouTube video interaction Marketo trigger for tracked YouTube video interaction

Finally, to trigger a status change or scoring increase when a lead finishes watching a video, you can search for a query string containing movie-action=played-to-end.

Marketo trigger for YouTube video viewed to end Marketo trigger for YouTube video viewed to end

Look at the demo video’s log above to get an idea of what parameters are available for your Marketo filters and triggers. Remember, you can use as much or as little of the query string to get as specific or general as you want depending on how much or how little of it you include. Here are some query strings from the example above and ideas on how you could possibly use them:

Query String Parameters Interpretation & Use Case
video=jdi-qqFv24A&movie-action=played-to-end Watched a specific video to the end. Use to set program status to Engaged or equivalent success step.
movie-action=played-to-end Watched any tracked YouTube video on your site to the end. Use to increase Behavior Score in your global scoring program. This may also be a good opportunity to log an Interesting Moment for Sales.
video=jdi-qqFv24A&movie-action=achieved-milestone&percent=50 Watched at least half of a specific video. Use to set program status to Interested or equivalent pre-success step. Possibly use to increase Behavior Score.
movie-action=achieved-milestone&percent=50 Watched at least half of any tracked YouTube video on your site. Use to increase Behavior Score.
movie-action=pressed-play&percent=0 Started watching any tracked YouTube video on your site. Use to increase Behavior Score.

Configure the YouTube tracking script and player settings

By default, this video player will log milestones when a known lead watches 25%, 50% or 75% of the video, but these can be changed to suit your needs.

In addition to Marketo tracking, this script also empowers you to overcome some of YouTube’s default embedded YouTube video player’s other limitations and settings:

  • The video player will scale responsively for tablet or mobile devices.
  • The player’s controls and video title are hidden by default.
  • “Related” videos will not display at the end of the video.

Any of these options can be changed in the script itself, including the percentages for the milestones.

Settings for YouTube videos tracked in Marketo Settings for YouTube videos tracked in Marketo

Have questions, suggestions for improvements or requests for specific features? Let us know in the comments below.


How To: Upload Files from a Marketo Form

Using a Javascript snippet and simple third-party service, you can allow visitors to attach files to Marketo form submissions

Marketo’s native forms provide marketers powerful tools for collecting information from people, but the framework sometimes leaves power users (like you!) wishing for a little more flexibility. A client recently asked if our team could add file upload functionality to one of their Marketo forms. This article will walk you through the process to allow your visitors to upload files from a Marketo form.

The Challenge

Handling file uploads through forms can be tricky, especially if you have to code the functionality from scratch. The solution requires server-side processing that simply isn’t part of most marketers’ repertoire. But fear not, there is a cloud-based way to quickly implement this powerful functionality in your forms–with minimal coding.

Bottom-Line Impact

You may ask, “why would I want to upload a file via a form in the first place”? There are potentially many use cases for the ability to submit files from a Marketo landing page. Here are some scenarios:

  • Attach an RFP in PDF format to a request for services
  • Submit project specs in a Word doc
  • Send a Visio process flow for a complimentary review
  • Enter crazy sock photos in a social media contest to win a free iPad

For our client, there was a need to allow a potential customer to submit a bill of materials (a list of parts for a particular project), which their sales team could later use to check parts availability. The file upload functionality allows sales to close these deals more quickly and with less hassle.

Cloud App to the Rescue

The solution was to use a third-party, cloud-based upload service called Uploadcare. There are other services, but this one was chosen. In our demonstration we used the vendor’s “free plan”, which offered plenty of horsepower for normal use, and reasonably priced paid plans if you need more.

In addition, users can upload not only from their computer, but also from Dropbox, Google Drive, Evernote, OneDrive, Box, and social media sources, so the service makes it easy for anyone to use, regardless of where their files are stored.

We integrated this service into an existing Marketo form using a hidden field and some simple jQuery wizardry.

High-Level Overview

Basically, the solution consists of these steps:

  1. Set up an uploader widget on a third-party service.
  2. Create a custom Marketo landing page template.
  3. Add some Javascript to transform the hidden form field to a file upload widget.
  4. Create a custom field in Marketo where we will store the uploaded file URL.
  5. Create a Marketo landing page from your new template and a form with a hidden field.

If you’re following along at home, here are the steps to implement this solution.

Get the Upload Widget

  1. Create an account with Uploadcare and click the verification link in your email.
  2. In your new Uploadcare account, create a new project and configure the upload widget.
    • Disable any services from which you don’t want to receive files (such as Flickr).
    • By default, users can upload only one file, but it can be any type of file—DOCX, PDF, VSDX, JPG, etc. It’s best to leave these settings as they are. (If you experiment with multiple files, I’d love to hear how it went!)
  3. Under the Integration section, we’re going to use the Javascript code from the first box, but you can ignore the others–we’re going to use custom code instead.


Create the Landing Page Template

Remember that Javascript code from Uploadcare that we looked at earlier? Now we’re going to add it to the landing page, plus one more custom Javascript snippet to make it work with a Marketo form. This is the hardest part if you’re not used to working with code, but we’ll walk through it step by step. Hang in there!

  1. In Design Studio, find the landing page template you want to use for your file upload form, then clone it, naming it something like “File Upload Form” so you remember its purpose later. Creating a new template is necessary because we need to place some Javascript code after jQuery is loaded, and it is often loaded near the bottom of the page. In case that’s a new term for you, jQuery is a Javascript framework that enables cool functionality—like adding file upload widgets!
  2. Add the Uploadcare Javascript code to your landing page template.
    1. In Design Studio, edit your new File Upload Form landing page template.
    2. Paste your Uploadcare Javascript code just above the tag at the very bottom of the landing page code.
    3. Don’t save the template just yet.
  3. Add custom Javascript code to make the Uploadcare widget work with a Marketo form.
    1. Copy the Javascript code below. It essentially transforms the hidden form field that we placed in the Marketo form to the Uploadcare file upload widget. If you chose to use a different field than the Uploaded File field that we’re using in this example, then you will need to change this code accordingly where it says “name=uploaded_file” to whatever the name of your field is.
      <script type="text/javascript">
        function showUploader() {

      Paste this code beneath the Uploadcare code that you pasted in Step 1 above but before the closing tag.

  4. Add styles to make the upload widget look a little better. You can tweak these as you see fit, but this will get you started.
    1. Copy this CSS code and paste it beneath the last Javascript block.
      <style type="text/css">
        div.uploadcare-widget-button {
          margin: 15px 0;
          width:160px !important;
          height: 35px !important;
          padding: 10px 0 0 10px;
  5. The last 20 or so lines of your template before the <body> tag should look something like this.

  6. Approve and Close this template.

Putting the Pieces Together

Okay, let’s make some magic happen. The setup in Marketo requires several things: a form (duh!); a landing page where the form lives; a string field where you can store the URL of the uploaded file.

  1. Figure out what Marketo field to use to store the URL of the file that is uploaded. In this example, we’ll use a custom String field called “Uploaded File”. You will likely need to create this field, or you could use a temporary field that we’ll overwrite later.
  2. Create a form. It can be as complex as you like, but our example only has three visible fields—First Name, Last Name and Email Address.
    1. Add the Uploaded File field to the form, and set its Field Type to Hidden.
    2. Approve and Close the form.
  3. Create a new landing page from the File Upload Form template. Add whatever copy and images make sense for your purposes.
  4. Add the form we just created to the landing page, as you normally would.
  5. Approve and Close this landing page.

Try It Out!

Now the fun part—seeing it in action! Let’s give it a shot in the browser.

  1. Select your page in Marketo and click the orange View Approved Page button.
  2. You should see your new landing page open up with your form. After a moment, you should also see a box show up in your form that says “Choose a file.” If so, your integration worked!
  3. When you click on that box, you’ll see a drag-and-drop interface for uploading a file along with any other upload options you left checked when configuring the Uploadcare widget.


Best Practices

While this is good as a proof of concept, there are a few other things to consider when using this technique in a production environment.

  1. First, when you upload files from a Marketo form, it’s probably best to move this data from the Uploaded File field and put it somewhere that it won’t be overwritten if the person uploads a new file. I recommend using {{lead.Uploaded File}} in a Flow step to write the uploaded file URL to an Interesting Moment.
  2. Next, this upload widget might not work for everyone in every browser. Post instructions for sending a file separately (probably via email) for anyone who has trouble with the form.
  3. Finally, you will probably want to involve a web developer to help customize your upload widget further to better match your brand identity.

If you put this technique into use, I would love to hear about your specific use case in the comments. If you need some help, reach out in the comments below or via our contact form. Happy uploading!