Updated 11/16/2015: add IPv6 support and link user agent to StatCounter.
This snippet adds a link to geolocation and ISP data on IPaddress.com (IPv4) / ipinfo.io (IPv6) and the submitter’s user agent to the Entry metabox via the gform_entry_info hook.
<php // Add IP and UA info to Entry metabox add_action( 'gform_entry_info', 'djb_gform_entry_info', 10, 2 ); function djb_gform_entry_info( $form_id, $lead ) { // Don't show link if address is in IPv4 private or reserved range. if ( isset( $lead['ip'] ) && filter_var( $lead['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 | FILTER_FLAG_IPV6 | FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) { if ( filter_var( $lead['ip'], FILTER_VALIDATE_IP, FILTER_FLAG_IPV4 ) ) { $ip_info_url = 'http://' . $lead['ip'] . '.ipaddress.com'; } else { // ipinfo.io has less detail, but supports IPv6. $ip_info_url = 'http://ipinfo.io/' . $lead['ip']; } echo '<a href="' . esc_url( $ip_info_url ) . '" target="_blank">IP info</a>'; } if ( isset( $lead['ip'] ) && isset( $lead['user_agent'] ) ) { echo '<br><br>'; } if ( isset( $lead['user_agent'] ) ) { printf( '%1$s: <a href="%2$s" target="_blank">%3$s</a>', esc_html_e( 'User Agent', 'gravityforms' ), esc_url( add_query_arg( 'useragent', urlencode( $lead['user_agent'] ) , 'http://gs.statcounter.com/detect' ) ), esc_html( $lead['user_agent'] ) ); } }
Thanks so very much for this. Do you know the hook to capture the user agent as well? I’m using the information from form submissions to troubleshoot video playback issues, and users aren’t very good and telling me what browser and version they’re using.
oops! Never mind 🙂 Just saw it.
I’ve updated the code to support IPv6 addresses and link to a user agent decoder.
Do you know how to make the IP address and timestamp send through a notification with gravity forms?
Thanks!
Use the
{ip}
and{date_mdy}
or{date_dmy}
merge tag.So can you decode what that user agent information means? Is there some guide out there to what it means?
In the example you posted it looks like mozilla on Windows AND safari on mac AND chrome on mac. So what the heck were they using?
That’s what the StatCounter link is for, e.g. http://gs.statcounter.com/detect?useragent=Mozilla%2F5.0+%28Windows+NT+6.1%29+AppleWebKit%2F537.36+%28KHTML%2C+like+Gecko%29+Chrome%2F29.0.1547.76+Safari%2F537.36&extra_header=.