Welcome to the PHP Client documentation for Scoby Analytics. This guide will help you set up and utilize our PHP SDK to gain insightful data about your web application's user interactions.
Prerequisites
You need your License Key and Salt to use our PHP SDK.
Installation
To get started, install the package using composer:
composer require scoby/analytics
Usage
Initialization
First, instantiate the Scoby Analytics client with your License Key and salt:
use Scoby\Analytics\Client;
$client = new Client('INSERT_YOUR_API_KEY_HERE', 'INSERT_YOUR_SALT_HERE');
Logging Methods
The client supports both synchronous and asynchronous logging:
$client->logPageView();
$client->logPageViewAsync();
Note: PHP scripts are inherently blocking. The logPageViewAsync
method executes after all main tasks are completed, just before your script terminates.
Setting Data Manually
The client can automatically scan the $_SERVER
variable, but you have control over setting specific data:
$client->setIpAddress('1.2.3.4');
$client->setUserAgent('Mozilla/5.0 ... Firefox/103.0');
$client->setRequestedUrl('https://example.com/some/path?and=some&query=parameters');
$client->setReferringUrl('https://eyample.com/the/page/that?was=visited&before=yay');
Segmenting Visitors
Visitor segmentation enhances your understanding of your audience. Segment your audience by various criteria, then log their interactions:
$client
->addVisitorToSegment('Subscribers')
->addVisitorToSegment('Women')
->addVisitorToSegment('Young Adults')
->logPageView();
Note: Scoby Analytics applies k-Anonymity of 25 for visitor segments to ensure privacy.
Setting your own Visitor ID
Improve visitor counting accuracy with a custom identifier:
$client->setVisitorId('some-anonymous-identifier');
IP Blacklisting
Exclude specific IPs or ranges from your measurements:
$client
->blacklistIpRange('12.34.*.*')
->blacklistIpRange('87.65.43.21/16');
Support
Need help? Reach out at hello@scoby.io.