How To Track Geo IP Stats When Cloudflare Is Enabled

Cloudflare masks the IP address of the user and moves it to another HTTP header.

To make it compatible with ThirstyAffiliate’s stats collection module you will need to add the following snippet of code to your functions.php file or a drop in plugin.

function ta_cloudflare_ip_compatibility( $ip ) {
    if ( ! empty( $_SERVER['HTTP_CF_CONNECTING_IP'] ) )
            $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
    return $ip;
}
 
add_filter( 'ta_get_user_ip_address' , 'ta_cloudflare_ip_compatibility' , 10 , 1 );

This will be added as a feature to ThirstyAffiliates in the future.