# simpleanalytics/1.57/src/TrackingPolicy.php

Simple Analytics, version 1.57. 30 lines.

- Page: https://pluginprobe.com/plugins/simpleanalytics/1.57/code/src/TrackingPolicy.php
- Raw: https://pluginprobe.com/plugins/simpleanalytics/1.57/raw/src/TrackingPolicy.php
- Modified: 2025-04-22T19:05:40+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/simpleanalytics/1.57/code/src/TrackingPolicy.php#L10-L20`.

```php
<?php

namespace SimpleAnalytics;

class TrackingPolicy
{
    public function shouldCollectAnalytics(): bool
    {
        if ($this->clientIpExcluded($_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'])) {
            return false;
        }

        if (! is_user_logged_in()) {
            return true;
        }

        return ! $this->containsExcludedRole(wp_get_current_user()->roles);
    }

    protected function clientIpExcluded(string $ip): bool
    {
        return in_array($ip, Setting::array(SettingName::EXCLUDED_IP_ADDRESSES));
    }

    protected function containsExcludedRole(array $roles): bool
    {
        return array_intersect(Setting::array(SettingName::EXCLUDED_ROLES), $roles) !== [];
    }
}

```
