Jump to content

TomWis

Member
  • Posts

    2
  • Joined

  • Last visited

Posts posted by TomWis

  1. 18 hours ago, creedon said:

    @TomWis

    The way to do it is to use a geolocation service instead of an ip address service. Geolocation is basically doing the same thing as the ip address service but adds location information.

    Ipify has one but there are several companies that provide this service.

    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...

  2. 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.

    185423979_ScreenShot2020-09-30at6_53_37PM.png.1ee301805d6573c950876008e88c47c4.png

    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

     

×
×
  • Create New...

Squarespace Webinars

Free online sessions where you’ll learn the basics and refine your Squarespace skills.

Hire a Designer

Stand out online with the help of an experienced designer or developer.