Here’s my solution for adding geolocation information to your contact’s record, from a signup web form locally hosted on your own website. I combined the technique from three other examples found via a Google search, that didn’t do exactly what I needed and modified them to this current solution.
Freegeoip.net
http://www.freegeoip.net
The open source freegeoip.net service allows you grab the IP address and lookup ISP (Internet Service Provider) locality without alerting the user, unlike Google’s geolocation service that prompts the user to give permission to provide their IP. If this is an ethical issue for you or your customers, then this isn’t the appropriate solution. Freegeoip.net has their own usage agreement and number of lookups restrictions as outlined on their website.
Here is a list of available geolocation fields offered by freegeoip.net though their true availability will vary depending on each actual lookup providing data, which won’t always happen in a full dataset.
- City
- Region / State (Abbreviation)
- Region / State (Full Name)
- Postal Code / ZIP
- Area code
- Latitude
- Longitude
- Country (Abbreviation)
- Country (Full Name)
- IP Address
Create an Infusionsoft Campaign
Create an Infusionsoft campaign with a signup web form and add the hidden fields (assigning blank values) you wish to capture.
I placed the captured geolocation information into the Optional Address fields already created in Infusionsoft to avoid overwriting the actual street or billing addresses with these temporary location values. You could of course create your own custom fields to place these geolocation data values into.
Infusionsoft Optional Street Fields
(the one’s I used in this web form capture example)
inf_field_City3
inf_field_State3
inf_field_PostalCode3
inf_field_Country3
Infusionsoft Custom Field
To capture the IP address you need to create a custom field for a Contact that I called “IP Address”. This field value then is seen as “_IPAddress” when referenced by your web form code. Note the significant underscore in front.
inf_custom_IPAddress
The Geolocation Lookup JQuery Script
Place this script on the web page where your locally hosted web form resides. I placed it at the top of the page before the rest of the form code starts so the geolocation lookup is executed first. This script is what makes everything else work.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
jQuery.ajax( {
url: '//freegeoip.net/json/',
type: 'POST',
dataType: 'jsonp',
success: function(location) {
// Update hidden form field variable values
$('#City3').val(location.city);
$('#State3').val(location.region_code);
$('#PostalCode3').val(location.zipcode);
$('#Country3').val(location.country_name);
$('#_IPAddress').val(location.ip);
}
} );
</script>
Web Form Hidden Fields
Add these hidden fields into your locally hosted web form code. If you wish to capture additional fields then add in the appropriate Infusionsoft field & ID names. You can find them by testing your web form from within Infusionsoft’s campaign and looking at the source code to see the hidden field values created.
<input name="inf_field_City3" id="City3" type="hidden" value="" />
<input name="inf_field_State3" id="State3" type="hidden" value="" />
<input name="inf_field_PostalCode3" id="PostalCode3" type="hidden" value="" />
<input name="inf_field_Country3" id="Country3" type="hidden" value="" />
<input name="inf_custom_IPAddress" id="_IPAddress" type="hidden" value="" />
Web Form Other Code
You can use the (styled or un-styled) web form code created by the Infusionsoft campaign and insert on your own website’s page but need to add the hidden fields you wish to capture data for into the form code.
Note the input ID’s match the JQuery script ID’s so when JQuery runs it updates the hidden field values (matching on ID) with the one’s found by the geolocation lookup service. Then when the form is submitted both visible and invisible field values are posted to the Contact record in Infusionsoft.
Heh presto your contact’s optional address fields now have values populated showing their approximate location based on ISP and IP Address lookup. They could of course be using a VPN but this is an imperfect collection method to help you get an idea of where your customer’s are coming from.
The IP Address is populated into your custom field, whichever tab you have placed that field into. I created one called “Geolocation” to make things separate and clear.
Things to Watch Out For
Make sure you have the campaign Published to allow the transfer of the data into the field values. Additionally, make sure you have the same hidden fields created in the campaign form as you are sending via the locally hosted web form otherwise the data does not transfer and you wonder why things aren’t working. Both mistakes that I made and Infusionsoft tech support helped me to figure out.