Capturing IP address in memberstack

Hi,

I have created my own solution to catch the IP address of any member once he/she signs up.

  1. Create a custom field called IP and hide it in memberstack.
  2. Create a text field in Webflow and insert the custom attribute: data-ms-member = ip
  3. Insert the Javascript (JQUERY):
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>

<script>

function getIp(callback)
{
    function response(s)
    {
        callback(window.userip);

        s.onload = s.onerror = null;
        document.body.removeChild(s);
    }

    function trigger()
    {
        window.userip = false;

        var s = document.createElement("script");
        s.async = true;
        s.onload = function() {
            response(s);
        };
        s.onerror = function() {
            response(s);
        };

        s.src = "https://l2.io/ip.js?var=userip";
        document.body.appendChild(s);
    }

    if (/^(interactive|complete)$/i.test(document.readyState)) {
        trigger();
    } else {     
        document.getElementById("First-name").addEventListener("focusout", trigger);		
    }
}

getIp(function (ip) {

  document.getElementById('IP').value = ip;
  console.log(ip);
});

</script>

2 Likes

This is awesome Othon! Great job! Thank you! :smiley:

1 Like