SOLVED

Collecting IP address once form is completed

Go to solution
Anonymous
Not applicable

Collecting IP address once form is completed

Hi,

Is there any way to collect a recipient's IP address once they have completed a Marketo form?

Thanks,
Nicole
Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
SanfordWhiteman
Level 10 - Community Moderator

Re: Collecting IP address once form is completed

  1. This post is 10 years old. Please open a new thread if you have a similar question.
  2. The code you posted will not work at all. It’s clearly not tested; at no time are you saving the IP address to Marketo.
  3. People don’t just post from a single IP address, so even in the case where you do save the IP addresses to Marketo, it needs to support multiple IPs per person.
  4. The Client IP Address is automatically a property of every Filled Out Form activity.

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Re: Collecting IP address once form is completed

Marketo silently collects the IP address when a lead fills out a form.
That information is accessible through the Activity Log.
 
Assuming the IP is relevant for GeoLocation or user-defined activities, you can either use SOAP API to retrieve that information of add a JavaScript to save the IP and GeoLocation to custom fields.
 
The SOAP API call would be getLead or getMultipleLeads
 
getLeadActivity is also a good fit
 
You can then use syncLead or syncMultipleLeads to find the IP and location to custom fields
 
 
A small JavaScript allows to read and save that information in one go when the form is saved:
function myIP() {
    if (window.XMLHttpRequest) xmlhttp = new XMLHttpRequest();
    else xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 
    xmlhttp.open("GET","http://api.hostip.info/get_html.php",false);
    xmlhttp.send();
 
    hostipInfo = xmlhttp.responseText.split("\n");
 
    for (i=0; hostipInfo.length >= i; i++) {
        ipAddress = hostipInfo[i].split(":");
        if ( ipAddress[0] == "IP" ) return ipAddress[1];
    }
 
    return false;
}
 
Anonymous
Not applicable

Re: Collecting IP address once form is completed

Good approach but the JS example won't work in every browser, plus the ActiveX requirement will fail on restricted machines. But, it shows a common way of getting IP from external provider and using it in a form.
Anonymous
Not applicable

Re: Collecting IP address once form is completed

Georgi, I totally agree with your reamrks. I am originally Unix user, happy to ambrace Linux and Mac OS X.  

The example is agnostic

$(document).ready(function () {
  $.get('http://jsonip.com', function (res) {
  // assign the IP to a hidden field using res.ip
  });
});

Anonymous
Not applicable

Re: Collecting IP address once form is completed

Thanks Georgi, helped me out there too!
Anonymous
Not applicable

Re: Collecting IP address once form is completed

I need to save IP Address to a field in Salesforce for CASL compliance. How can we do this? I dont know Javascript or know where to put this and dont have developer resource or budget to hire Marketo. 
Anonymous
Not applicable

Re: Collecting IP address once form is completed

We have the same need for a legal requirement in Germany. Where would I put the JS code and how would that populate the hidden field?

Thanks! 
KariH
Level 1

Re: Collecting IP address once form is completed

You would place the code either in a snippet, html, or rich text on the landing page. Place <script type="text/javascript"> at the start and </script> at the end so that it is hidden, Like: 

<script type="text/javascript">
MktoForms2.whenReady(function(form){
form.onSuccess(function(values, followUpUrl){
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => {
var ipAddress = data.ip;
// Update the custom field with the IP address
form.addHiddenFields({
"{{YOUR FIELD NAME}}": ipAddress
});
})
.catch(error => console.error('Error fetching IP:', error));
});
});
</script>

 

In your form add the field {{YOUR FIELD NAME}} to the bottom of your form, field type=hidden. 

Save and approve form, approve LP, and test by filling out form.

SanfordWhiteman
Level 10 - Community Moderator

Re: Collecting IP address once form is completed

  1. This post is 10 years old. Please open a new thread if you have a similar question.
  2. The code you posted will not work at all. It’s clearly not tested; at no time are you saving the IP address to Marketo.
  3. People don’t just post from a single IP address, so even in the case where you do save the IP addresses to Marketo, it needs to support multiple IPs per person.
  4. The Client IP Address is automatically a property of every Filled Out Form activity.