# simpleanalytics/1.92/src/TrackingPolicy.php

Simple Analytics, version 1.92. 37 lines.

- Page: https://pluginprobe.com/plugins/simpleanalytics/1.92/code/src/TrackingPolicy.php
- Raw: https://pluginprobe.com/plugins/simpleanalytics/1.92/raw/src/TrackingPolicy.php
- Modified: 2025-08-06T06:59:10+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.92/code/src/TrackingPolicy.php#L10-L20`.

```php
<?php

namespace SimpleAnalytics;

class TrackingPolicy
{
    public function shouldCollectAnalytics(): bool
    {
        if ($this->isClientIpExcluded()) {
            return false;
        }

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

        return ! $this->containsExcludedRole();
    }

    protected function isClientIpExcluded(): bool
    {
        $ip = $_SERVER['HTTP_X_FORWARDED_FOR'] ?? $_SERVER['REMOTE_ADDR'];

        if (empty($ip)) return false;

        return in_array($ip, Setting::array(SettingName::EXCLUDED_IP_ADDRESSES));
    }

    protected function containsExcludedRole(): bool
    {
        $currentRoles = wp_get_current_user()->roles;
        $excludedRoles = Setting::array(SettingName::EXCLUDED_ROLES);

        return array_intersect($excludedRoles, $currentRoles) !== [];
    }
}

```
