1. Go to this page and download the library: Download dregs/dregs-sdk library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
dregs / dregs-sdk example snippets
use Dregs\Client;
$client = new Client($_ENV['DREGS_SECRET_KEY']);
$result = $client->track('user.signup', identity: 'user_12345');
$result->isAccepted(); // true when Dregs recorded the event
$result->id; // the event's id
$identity = $client->identities->get('user_12345');
$identity->displayEmail; // "[email protected]"
$identity->humanityScore; // 85
$identity->badges; // [Badge(name: "Account Takeover Suspected", ...)]
$identity->data; // every attribute you have sent
$client->identities->analyze('user_12345');
use Dregs\Exception\DregsException;
use Dregs\Exception\QuotaExceededException;
use Dregs\Exception\RateLimitException;
try {
$client->track('user.signup', identity: 'user_12345');
} catch (QuotaExceededException) {
// Over the monthly event limit; the event was not queued.
} catch (RateLimitException $exception) {
// Ingesting too fast. $exception->retryAfter when the server said how long.
} catch (DregsException $exception) {
// Anything else this library throws.
}
$client = new Client(maxRetries: 5); // or 0 to handle it yourself
final class TrackSignup implements ShouldQueue
{
public function __construct(private readonly string $identity, private readonly array $attributes)
{
}
public function handle(Client $dregs): void
{
$dregs->track('user.signup', identity: $this->identity, identityData: $this->attributes);
}
}
use Dregs\Exception\WebhookVerificationException;
use Dregs\Webhooks;
try {
$event = Webhooks::verify(
$request->getContent(),
$request->headers->get(Webhooks::SIGNATURE_HEADER) ?? '',
$_ENV['DREGS_WEBHOOK_SECRET'],
);
} catch (WebhookVerificationException) {
return new Response(status: 400);
}
handle($event);
$client = new Dregs\Client(
secretKey: null, // defaults to $DREGS_SECRET_KEY
baseUrl: null, // defaults to $DREGS_BASE_URL, then https://dregs.com/api
timeout: 10.0, // seconds
maxRetries: 2,
httpClient: null, // a Dregs\Http\Transport, or your own PSR-18 client
);
// Symfony's PSR-18 client is its own PSR-17 factory, so it needs nothing alongside it.
$client = new Dregs\Client(httpClient: new Symfony\Component\HttpClient\Psr18Client());
// Guzzle needs the factories naming.
$factory = new GuzzleHttp\Psr7\HttpFactory();
$client = new Dregs\Client(
httpClient: new GuzzleHttp\Client(),
requestFactory: $factory,
streamFactory: $factory,
);
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.