Re: Pull Domain Out of Email Address

Anonymous
Not applicable

I put leads into Marketo from many different sources, so a user's website domain isn't always automatically populated by Marketo. Does anyone know a way to build a campaign or script in Marketo so that any new lead added has their email address domain populate the `Website` custom field?

Example: Ideally if I add mark@facebook.com to Marketo, then his website would automatically be set as facebook.com.

Thanks for your help!

17 REPLIES 17
Jay_Jiang
Level 10

We use webhooks to php files to transform Marketo data like standardising phone numbers and States. If you want to go down this path, you'll need a server to host the php file, which most people with a website should already have.

Basic code for what you want is:

<?php

$em  = $_POST['email'];

$em = array_filter(explode("@", $em));

$response = '{"domain":"'.$em[1].'"}';

echo $response;

?>

In Marketo you'll need create a webhook where URL is the link to the php file, Template is email={{lead.Email Address}} and response type is JSON

You'll also then need to edit response mappings for the webhook where response attribute is domain and Marketo field is Website

You can also add security by adding custom headers to your Marketo webhook like PHP_AUTH_USER and PHP_AUTH_PW but I'd recommend getting a php developer to edit the php code for you.

Jerry_Cooper1
Level 2

I put the PHP file in our design center. Why won't that work?

Jerry Cooper
SanfordWhiteman
Level 10 - Community Moderator

There's no support for running user-supplied PHP templates in Marketo.

Jay's speaking about a potential webhook implementation on your own server.  It can of course be written in any language: Java, JavaScript, PHP, Ruby, etc. (there are services that allow you pass code to them for execution, so you don't have to run the service at all).

(P.S. The proper logic is to split on the @ character, check if the count is > 1, and take the last item, not the second item.)

Jerry_Cooper1
Level 2

It works with outside server,but cannot get the response to post to Marketo. What are we doing wrong here

Untitled.jpg

Jerry Cooper
Jay_Jiang
Level 10

It doesn't look like you can write/change the field "Website". You'll need to create a custom field e.g. Domain

SanfordWhiteman
Level 10 - Community Moderator

You certainly can change Website via a webhook. It's a standard data enrichment target.

Make sure it's not set to block field updates from webhooks.

Note Website is a Company field, not a Person/Lead field, so the standard expectations apply.

Jerry_Cooper1
Level 2

Domain worked perfectly. The formatter is a great help for us. Thank you all.

Jerry Cooper
SanfordWhiteman
Level 10 - Community Moderator

You didn't need to create a new field for this, though I suppose it's harmless if you did already.

Jerry_Cooper1
Level 2

Was there one of these PHP's suggested  to format phone numbers?

Jerry Cooper
Jay_Jiang
Level 10

I've personally written one for Australian phone numbers but not sure if that's any use to you. Global numbers are too hard to manage so paying for service might the way to go if you handle data from various countries. The logic and code is a lot more full on for a phone number formatter than separating domains though...

SanfordWhiteman
Level 10 - Community Moderator

The logic and code is a lot more full on for a phone number formatter than separating domains though...

Yep, that's why there's a whole library for it (Twilio themselves uses libphonenumber, since they didn't feel like they could do better in-house).

SanfordWhiteman
Level 10 - Community Moderator

Use Twilio's Lookup API Validation and Formatting endpoint for that. Follow the same directions as in Calling the Twilio Lookup API as a Marketo webhook.

Or you can embed Google's libphonenumber SDK in any supported language.

SanfordWhiteman
Level 10 - Community Moderator

You have to show the Activity Log Detail for the Call Webhook step.

SanfordWhiteman
Level 10 - Community Moderator

If not set at lead creation, this can only be done via webhook (callout from a flow).

Erin_Van_Leer
Level 1

How do you set this at lead creation? Or do you just mean, if Marketo fails to set this at lead creation, I'll need to use a webhook?

SanfordWhiteman
Level 10 - Community Moderator

Meaning if the source (web form, outside application, etc.) doesn't put the domain in a separate field at the start, you have to call a webhook. Marketo itself won't do this internally.

On a Marketo form, you can use a little JS to populate a separate hidden field with the domain.

But it's going to be harder to get an outside app -- whose initial author might be long gone -- to add this functionality, even though it's simple in any language.

Erin_Van_Leer
Level 1

Okay that makes sense. Thanks for your help!