How to track IP Address of people who fill out a form

What you need to do is:

  1. Make a form on your page
  2. Style it however you like and give it the inputs you need
  3. Make one more input, and give it an ID of ipFormInput in the Webflow designer
  4. Set this last field to hidden so that users don’t see it
  5. Copy this code into your page’s footer code:
<script type="application/javascript ">
    const ipFormInput = document.getElementById('ipFormInput');

    fetch('https://api.ipify.org?format=json')
        .then((response) => { return response.json() })
        .then((json) => {
            const ip = json.ip;
            ipFormInput.value = ip;
        })
        .catch((err) => { console.error(`Error getting IP Address: ${err}`) })
</script>

This script makes a call to an external service that returns the client’s IP address. It then sets the IP address as the value of the form field that has the ID ipFormInput. As long as you make this field hidden from the Webflow designer, the user will never see it. When the form is submitted you will get the IP address along with the other form fields.

I just wrote this and tested it, it works fine.

Hope that helps.
Jason

3 Likes