Developer Docs

The Developer Docs for CAOS Pro contain a list of available filters and actions for WordPress developers to add and/or manipulate various functions.

caos_pro_proxy_user_ip_address

Manipulate the IP address before it’s sent to the Google Analytics API.

Since Google Analytics 4, (partially) masking the IP address will directly affect geolocation collection.

For example, to (partially) mask the IP address, you could add the following filter either in a plugin or your child theme’s functions.php :

add_filter('caos_pro_proxy_user_ip_address', 'daan_anonymize_ip');
function daan_anonymize_ip($ip) {
    $octets = explode( '.', $ip );
    if ( empty( $octets ) ) {
	return $ip;
    }
    // To anonymize the last octet use this piece of code:
    $octets = $this->anonymize_one_octet( $octets );
    $last   = array_slice( $octets, -1, 1, true );
    $last_key = array_key_first( $last );
    $last[ $last_key ] = '0';
    $octets = array_replace( $octets, $last );
    // End of last octet anonymization
    // To anonymize the last two octets use this piece of code:
    $second_to_last     = array_slice( $octets, -2, 1, true );
    $second_to_last_key = array_key_first( $second_to_last );
    $second_to_last[ $second_to_last_key ] = '0';
    $last     = array_slice( $octets, -1, 1, true );
    $last_key = array_key_first( $last );
    $last[ $last_key ] = '0';
    $octets = array_replace( $octets, $second_to_last, $last );
    // End of last two octets anonymization.
    // To anonymize all octets:
    $octets = [ '1', '0', '0', '0' ];
    // End of all octets anonymization.
    return implode( '.', $octets );
}Code language: PHP (php)