TomWis
-
Posts
2 -
Joined
-
Last visited
Content Type
Forums
Gallery
Blogs
Events
Store
Downloads
Profiles
Posts posted by TomWis
-
-
On 10/1/2020 at 4:03 AM, creedon said:
The following will require a business plan or above.
Add the following to Settings > Advanced > Code Injection > HEADER.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js" type="text/javascript"></script>
Add the following to Page Settings > Advanced > PAGE HEADER CODE INJECTION.
<script>   $( ( ) => {     /*       based on code from    < https://www.geeksforgeeks.org/how-to-get-client-ip-address-using-javascript/ >.        Uses ipify API < https://www.ipify.org/ >.        */       /*       Add "https://api.ipify.org?format=json" statement this will communicate with    the ipify servers in order to retrieve the IP address $.getJSON will load    JSON-encoded data from the server using a GET HTTP request        */       $.getJSON ( 'https://api.ipify.org?format=json', function ( data ) {       // setting hidden ip address field with name SQF_IP_ADDRESS        $( '[name="SQF_IP_ADDRESS"]' ).val ( data.ip );        } );         } );      </script>
Add a hidden form field to your form named IP Address.
That should do the trick. I tested it out here on a v7.0 site but I think it should work on v7.1 as well.
Basically what this is doing is using Javascript/jQuery to go out and query the ipify api for the ip address of the client. Then stuff that number in the IP Address field.
Obviously you will need to test on your site.
Let us know how it goes.
Hey @creedon! Your solution works like charm, I implemented it on my website. And this hidden IP field lands nicely also in Mailchimp as a separate field.
Do you know a way to automatically extract Country+City from this IP address? I'd love to add them as separate hidden fields as well.
Thanks!
Tom
Â
Would like to include the IP address of the person filling out a form
in Customize with code
Posted
Thanks @creedon. You don't plan to post similar step-by-step with code example, do you? 🙂Querrying for country+city seems more complex. Querrying for IP address was super-simple, because URL https://api.ipify.org simply returned ID address...