Support » Plugin: CAOS | Host Google Analytics Locally » GA4 shows the wrong country

Viewing 14 replies - 16 through 29 (of 29 total)
  • Thread Starter Alessio

    (@alexmes)

    It was already set to Yes

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Well, this mystery just keeps getting weirder and weirder doesn’t it?

    Ok, I might’ve found a fix for this, could you try the following?

    In the file host-analyticsjs-local/includes/api/class-proxy.php on line 195 there’s a function called get_user_ip_address().

    Replace that entire function (from private function get_user_ip_address() { to the closing } on line 212) with this:

    private function get_user_ip_address()
    {
        if (isset($_SERVER['HTTP_CF_CONNECTING_IP'])) {
            $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
        } elseif (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];
        } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    	$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } else {
    	$ip = $_SERVER['REMOTE_ADDR'];
        }
    
        if (is_array(explode(',', $ip))) {
            $ip = explode(',', $ip);
    
            return $ip[0];
        }
    
        return $ip;
    }

    This way, it’ll first look for a CloudFlare HTTP header. If that’s not present, it’ll continue its old flow.

    Let me know how it goes!

    Thread Starter Alessio

    (@alexmes)

    It doesn’t work 🙁 It still thinks I’m from Saudi Arabia.
    But thanks for your time!

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Ok, last attempt. What if we switch it up a bit. Cause I’m seeing that CloudFlare handles the HTTP_X_FORWARDER_FOR better than HTTP_CLIENT_IP. So, change the function you pasted previously to this:

    private function get_user_ip_address()
    {
        if ($this->exists('HTTP_CF_CONNECTING_IP')) {
            $ip = $_SERVER['HTTP_CF_CONNECTING_IP'];
        } elseif ($this->exists('HTTP_X_FORWARDED_FOR')) {
    	$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        } elseif ($this->exists('HTTP_CLIENT_IP')) {
    	$ip = $_SERVER['HTTP_CLIENT_IP'];
        } else {
    	$ip = $_SERVER['REMOTE_ADDR'];
        }
    
        if (is_array(explode(',', $ip))) {
    	$ip = explode(',', $ip);
    
            return $ip[0];
        }
    
        return $ip;
    }
    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Wait! I found something!

    I’ll add the geoid parameter to requests if CloudFlare’s GeoIP function is enabled from now on.

    Thread Starter Alessio

    (@alexmes)

    Ok! Are you adding it in the next update? Or in the code I have to edit?

    • This reply was modified 10 months ago by Alessio.
    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    No, I was thinking about waiting for 3 years and then suddenly release it! 😉

    Ofcourse I will release it in the next update! I’ll do a quick patch release later today.

    Thread Starter Alessio

    (@alexmes)

    ahah! I modified my comment and maybe you didn’t see the second question. I meant if I had to wait for the edited code to be tested on my website.
    Anyway, thank you!

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    🙂 I was only kidding ofcourse. It must be the relief of finally being able to solve this issue! 😉

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Here’s hoping that v3.10.1 will resolve the issue you were having!

    Let me know how it goes!

    Thread Starter Alessio

    (@alexmes)

    No, it’s not solving the problem 🙁

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Whaaaat, how!? 🙁

    Okay. It’s nearing midnight here and I need some rest. I’ll revisit this issue early next week.

    Plugin Author Daan van den Bergh

    (@daanvandenbergh)

    Just looked at it again and there was a typo in my code :S

    So, I just created a new release. Could you try again?

    I also added a debug mode, so if it still doesn’t work, please enable debug mode (under Advanced Settings) and stealth mode, open up your website’s frontend, and then send me the contents of the wp-contents/caos-debug.log file using this form. Don’t forget to disable debug mode afterwards, because the file size will increase FAST!

    Let me know how it goes!

    Thread Starter Alessio

    (@alexmes)

    It didn’t work…
    I just sent you the log file

Viewing 14 replies - 16 through 29 (of 29 total)
  • The topic ‘GA4 shows the wrong country’ is closed to new replies.