PHPackages                             scoby/analytics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. scoby/analytics

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

scoby/analytics
===============

Client to measure web traffic in scoby

1.2.1(3y ago)01.5kMITPHP

Since Mar 10Pushed 1y ago1 watchersCompare

[ Source](https://github.com/scoby-io/analytics-php)[ Packagist](https://packagist.org/packages/scoby/analytics)[ RSS](/packages/scoby-analytics/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (7)Dependencies (6)Versions (8)Used By (0)

Scoby Analytics: PHP Client
===========================

[](#scoby-analytics-php-client)

[scoby](https://www.scoby.io) is an ethical analytics tool that helps you protect your visitors' privacy without sacrificing meaningful metrics. The data is sourced directly from your web server, no cookies are used and no GDPR, ePrivacy and Schrems II consent is required.

Start your free trial today on

#### Did you know?

[](#did-you-know)

Scoby is available for free for non-profit open-source projects.
[Request your free account now](mailto:hello@scoby.io?subject=giving%20back)

Installation
------------

[](#installation)

```
composer require scoby/analytics

```

Requirements
------------

[](#requirements)

The Scoby Analytics client uses the `php-http/discovery` package to automatically find and use installed PSR-18 compliant HTTP clients. This change allows for greater flexibility and interoperability with various HTTP client implementations.

To use Scoby Analytics, you need to have a PSR-18 compliant HTTP client installed in your project. If you don't have a specific client, the package will fallback to using Guzzle if it's available.

**Important**: If no PSR-18 compatible adapter is found, an error will be logged, typically stating `No PSR-18 clients found. Make sure to install a package providing "psr/http-client-implementation". Example: "php-http/guzzle7-adapter"`. In such cases, you should manually install a PSR-18 compliant client. As a convenient fallback, you can install Guzzle by running:

```
composer require guzzlehttp/guzzle

```

Prerequisites
-------------

[](#prerequisites)

You need two values to instantiate your scoby analytics client: your API key and a salt. The salt is used to anonymize your traffic before it is sent to our servers. You can generate a cryptographically secure using the following command:

```
openssl rand -base64 32
```

Please find your API key in your [workspace's settings](https://app.scoby.io) - don't have a workspace yet? Create one for free [here](https://app.scoby.io)

Usage
-----

[](#usage)

Instantiate your scoby analytics client using your API key and salt.

```
use Scoby\Analytics\Client;
$client = new Client('INSERT_YOUR_API_KEY_HERE', 'INSERT_YOUR_SALT_HERE');
```

After that the client supports synchronous and asynchronous logging of page views

```
// count page view synchronously ...
$client->logPageView();

// ... count page view asynchronously
$client->logPageViewAsync();
```

Disclaimer: PHP scripts are always blocking. The `logPageViewAsync` executes after all the main work is done right before your script exits.

The client will automatically scan the super global `$_SERVER` variable for all data it needs to work properly. All values can be overridden with fluent setters:

### Enabling Debugging with a PSR-3 Logger

[](#enabling-debugging-with-a-psr-3-logger)

To facilitate debugging and gain more insights into the operations of the Scoby Analytics client, you can use the `$client->setLogger` method. This method accepts a PSR-3 compliant logger instance, allowing you to integrate your preferred logging solution.

PSR-3 is a standard that defines a common interface for logging libraries in PHP, ensuring compatibility and flexibility. By using a PSR-3 logger, you can easily log messages of various severity levels, such as debug, info, warning, and error.

To enable logging, simply pass a PSR-3 compliant logger instance to the `setLogger` method. Here's an example using Monolog, a popular logging library:

```
use Scoby\Analytics\Client;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

// Create a logger instance
$logger = new Logger('name');
$logger->pushHandler(new StreamHandler('path/to/your.log', Logger::WARNING));

// Instantiate your Scoby Analytics client
$client = new Client('INSERT_YOUR_API_KEY_HERE', 'INSERT_YOUR_SALT_HERE');

// Set the logger
$client->setLogger($logger);

// Now you can use your client as usual
```

With the logger set, you will receive log messages that can help you debug issues or understand the client's behavior better.

### IP Address

[](#ip-address)

```
// set IP address manually
$client->setIpAddress('1.2.3.4');
```

### User-Agent

[](#user-agent)

```
// set User Agent manually
$client->setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0');
```

### Requested URL

[](#requested-url)

```
// set requested URL manually
$client->setRequestedUrl('https://example.com/some/path?and=some&query=parameters');
```

### Referring URL

[](#referring-url)

```
// set referrer manually
$client->setReferringUrl('https://eyample.com/the/page/that?was=visited&before=yay');
```

### Visitor Segments

[](#visitor-segments)

Visitor segmentation is a powerful tool for improving your website's performance and user engagement. By dividing your audience into different segments based on their common characteristics or behaviors, you can better understand their needs and tailor your website content, marketing messages, and user experience to meet their specific preferences.

To use visitor segments, you need to define the characteristics or behaviors that you want to segment your audience by, such as age, gender, location, interests, or purchase history. Once you have defined your segments, you can assign them to your website visitors based on the data you collect from their interactions with your website. It's important to note that segments should always be used in plural, as this makes the most sense in the Scoby Analytics dashboard, where you can view and analyze your visitor segments data. Additionally, all future interactions of a visitor are associated with the segment they belong to at the time of the interaction.

To log visitor segments using the Scoby Analytics library in your PHP code, you can use the addVisitorToSegment method to assign a visitor to a specific segment, and the logPageView method to log a page view event with the assigned segments. Here's an example:

```
use Scoby\Analytics\Client;
$client = new Client('INSERT_YOUR_API_KEY_HERE', 'INSERT_YOUR_SALT_HERE');
$client
    ->addVisitorToSegment('Subscribers')
    ->addVisitorToSegment('Women')
    ->addVisitorToSegment('Young Adults')
    ->logPageView();
```

In this example, we are logging a page view event and assigning the visitor segments Subscribers, Women, and Young Adults to the visitor who triggered the event. You can replace these segments with your own segment names based on your segmentation strategy.

Scoby Analytics is designed to be privacy-preserving, and applies a k-Anonymity of 25 to visitor segments. This means that each segment must have at least 25 unique visitors before it is included in the analytics report, in order to protect the anonymity of individual visitors.

### Visitor ID

[](#visitor-id)

To enhance the accuracy of visitor counting, you have the option to supply a custom identifier, such as an account ID or similar value. Before being transmitted to our servers, this identifier is hashed to prevent the sharing of personally identifiable information. Nonetheless, it is crucial to consult your data protection officer to ensure that using this feature aligns with your organization's legal and privacy requirements.

```
$client->setVisitorId('some-anonymous-identifier');
```

Complete example:

```
use Scoby\Analytics\Client;
$client = new Client('INSERT_YOUR_API_KEY_HERE', 'INSERT_YOUR_SALT_HERE');
$client
    ->setIpAddress('1.2.3.4')
    ->setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:103.0) Gecko/20100101 Firefox/103.0')
    ->setVisitorId('some-anonymous-identifier')
    ->setRequestedUrl('https://example.com/some/path?and=some&query=parameters')
    ->setReferringUrl('https://eyample.com/the/page/that?was=visited&before=yay')
    ->logPageViewAsync();
```

### IP Blacklisting

[](#ip-blacklisting)

By default, Scoby does not exclude any traffic from your measurements. However, we understand that you may need to filter out traffic from specific IP addresses or ranges. The `blacklistIpRange` method allows you to do this, supporting both wildcard patterns and CIDR subnet notation for your convenience. You can add multiple IPs, patterns, and ranges as needed.

```
$client
    ->blacklistIpRange('12.34.*.*')
    ->blacklistIpRange('87.65.43.21/16')
    ->blacklistIpRange('1.2.3.4')
    ->blacklistIpRange('::1');
```

Complete example:

```
use Scoby\Analytics\Client;
$client = new Client('INSERT_YOUR_API_KEY_HERE', 'INSERT_YOUR_SALT_HERE');
$client
    ->blacklistIpRange('12.34.*.*')
    ->setIpAddress('12.34.56.78') // pattern '12.34.*.*' includes '12.34.56.78'
    ->logPageView(); // returns: false
```

Testing
-------

[](#testing)

```
./vendor/bin/phpunit tests

```

Support
-------

[](#support)

Something's hard? We're here to help at

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance29

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~95 days

Recently: every ~141 days

Total

7

Last Release

592d ago

Major Versions

1.2.1 → 2.0.0-alpha2023-11-27

### Community

Maintainers

![](https://www.gravatar.com/avatar/a06af556a7de42b8710422cd5dd066e8194eba18669e4106fb055333ef307363?d=identicon)[scoby](/maintainers/scoby)

---

Top Contributors

[![peterviergutz](https://avatars.githubusercontent.com/u/568682?v=4)](https://github.com/peterviergutz "peterviergutz (20 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/scoby-analytics/health.svg)

```
[![Health](https://phpackages.com/badges/scoby-analytics/health.svg)](https://phpackages.com/packages/scoby-analytics)
```

###  Alternatives

[grumpydictator/firefly-iii

Firefly III: a personal finances manager.

22.8k69.3k](/packages/grumpydictator-firefly-iii)[civicrm/civicrm-core

Open source constituent relationship management for non-profits, NGOs and advocacy organizations.

728272.9k20](/packages/civicrm-civicrm-core)[shlinkio/shlink

A self-hosted and PHP-based URL shortener application with CLI and REST interfaces

4.8k4.3k](/packages/shlinkio-shlink)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
