VoidhashDocs
DevelopersHelp centerGuidesAPI reference
Dashboard
Get started
Introduction
Quickstart
How Voidhash works
Glossary
Versions and releases
Concepts
Teams, projects and environments
API keys
Products and perks
Offers
Subscription lifecycle
People and identity
Events
Features
Paywalls in your app
Feature flags and A/B tests
Paywall components
Push notifications
Ad attribution in your app
Client SDKs
React Native
Swift
Kotlin
Web
Your backend
Node.js
PHP
Go
Rust
Other languages
Payment sources
Forward store notifications
Developer tools
CLI
MCP server
Query analytics with VoidQL
PHP library
Check access
Receive webhooks
Persons and events
Custom payment providers

Persons and events

Create and update persons, capture events and send push notifications from PHP.

PHP code for persons, events and push notifications, using a configured client.

Persons

Create a person

use Voidhash\Generated\Core\Model\CreatePersonBodyJsonEncoding;

$person = $voidhash->persons->create(
    (new CreatePersonBodyJsonEncoding())
        ->setDistinctId('user_123')
        ->setEmail('ada@example.com')
        ->setName('Ada'),
);

echo $person->getId(); // person_…

getEmail() and getName() can return null.

Find a person

getByDistinctId returns null for an unknown distinct ID:

$person = $voidhash->persons->getByDistinctId('user_123');

get throws an ApiException (person_not_found) for an unknown or erased ID.

$person = $voidhash->persons->get('person_k2v9x4m8q1r3');

getEntitlements takes the same ID, and list returns every person in the project.

Update attributes

setAttributes sets attributes and creates the person when the distinct ID is new.

$voidhash->persons->setAttributes([
    'distinctId' => 'user_123',
    'traits' => ['plan' => 'team', 'seats' => 5],
    'setOnce' => ['signupSource' => 'website'],
]);

Capture events

eventCapture->capture takes timestamp as a DateTimeInterface.

Create the client with 'ingestUrl' => 'https://api.voidhash.com'; the default capture host doesn't answer yet.

$voidhash->eventCapture->capture([
    'distinctId' => 'user_123',
    'event' => 'report_exported',
    'timestamp' => new DateTimeImmutable(),
    'properties' => ['format' => 'csv', 'rows' => 1200],
]);

eventCapture->batch sends an array in one request:

$result = $voidhash->eventCapture->batch([
    ['distinctId' => 'user_123', 'event' => 'trial_reminder_sent', 'timestamp' => new DateTimeImmutable()],
    ['distinctId' => 'user_456', 'event' => 'trial_reminder_sent', 'timestamp' => new DateTimeImmutable()],
]);

echo $result['accepted'], ' accepted, ', $result['rejected'], ' rejected';

Errors throw an ApiException whose getErrorCode() is an event capture code.

Send push notifications

Early access

Push notifications are in early access. Ask us on Discord, or email support@voidhash.com on a paid plan, to turn them on for your team.

notifications->send sends no idempotency key, so a retry after a timeout can notify twice.

use Voidhash\Generated\Core\Model\CreatePushNotificationBodyJsonEncoding;

$sent = $voidhash->notifications->send(
    (new CreatePushNotificationBodyJsonEncoding())
        ->setDistinctIds(['user_123'])
        ->setTitle('Your trial ends tomorrow')
        ->setBody('Keep Pro for $9.99 a month.')
        ->setData(['screen' => 'paywall']),
);

echo $sent->getId(), ' ', $sent->getDeviceCount();

The optional setters are setSound, setBadge, setPriority, setTtlSeconds, setChannelId and setCollapseId; see Send a push.

Next steps

  • Receive webhooks
  • People and identity
  • Events

Something wrong or missing on this page? Tell us by email or on Discord.

PreviousReceive webhooksNextCustom payment providers

On this page

PersonsCreate a personFind a personUpdate attributesCapture eventsSend push notificationsNext steps