Show IP Info and User Agent on Gravity Forms Entries

Updated 11/16/2015: add IPv6 support and link user agent to StatCounter.

This snippet adds a link to geolocation and ISP data on (IPv4) / (IPv6) and the submitter’s user agent to the Entry metabox via the gform_entry_info hook.

Gravity Forms Entry metabox with new details highlighted

// 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'] . '';
		} else {
			// has less detail, but supports IPv6.
			$ip_info_url = '' . $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'] ) ) {
			'%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'] ) , '' ) ),
			esc_html( $lead['user_agent'] )

7 comments on “Show IP Info and User Agent on Gravity Forms Entries

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

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

Leave a Reply

Your email address will not be published.