Skip to main content

PHP SDK

The notifizz/notifizz-php package is the official PHP SDK for Notifizz. Use it to track events, trigger workflows, generate authentication tokens, and send notifications from your PHP backend.

Installation

composer require notifizz/notifizz-php

NotifizzClient

Constructor

use Notifizz\NotifizzClient;

$client = new NotifizzClient('YOUR_AUTH_SECRET_KEY', 'YOUR_SDK_SECRET_KEY');
ParameterTypeDescription
$authSecretKeystringYour Auth Secret Key from the Notifizz dashboard.
$sdkSecretKeystringYour SDK Secret Key from the Notifizz dashboard.

Methods

$client->track($props)

Creates a tracking context for an event. Returns a TrackContext that you chain workflows onto.
$context = $client->track([
    'eventName' => 'order_shipped',
    'sdkSecretKey' => 'YOUR_SDK_SECRET_KEY',
    'properties' => [
        'orderId' => 'ORD-4521',
        'carrier' => 'FedEx',
    ],
]);

$context->workflow('shipping_notification', [
    ['id' => 'user_42', 'email' => 'alice@example.com'],
]);

$context->send();
Parameters (array keys):
KeyTypeRequiredDescription
eventNamestringYesThe event slug matching a workflow in the dashboard.
sdkSecretKeystringYesYour SDK Secret Key.
propertiesarrayYesAssociative array of event data.
Returns: TrackContext

$context->workflow($campaignId, $recipients)

Attaches a workflow and its recipients. Chainable — call it multiple times before send().
$context
    ->workflow('notify_author', [
        ['id' => 'author_1', 'email' => 'author@example.com'],
    ])
    ->workflow('notify_team', [
        ['id' => 'team_1', 'email' => 'lead@example.com'],
        ['id' => 'team_2', 'email' => 'manager@example.com'],
    ]);
ParameterTypeDescription
$campaignIdstringThe workflow/campaign ID from the dashboard.
$recipientsarrayArray of recipient arrays with at least id and email.
Returns: TrackContext (chainable)

$context->send()

Sends the tracked event with all attached workflows.
$context->send();
Unlike the Node.js SDK, events are not auto-sent in PHP. You must call $context->send() explicitly.

$client->send($request)

Sends a notification directly to the Notification Center.
$response = $client->send([
    'notifId' => 'notif_template_123',
    'properties' => [
        'recipients' => [
            ['id' => 'user_42', 'email' => 'alice@example.com'],
        ],
        'title' => 'Your report is ready',
    ],
]);
KeyTypeRequiredDescription
notifIdstringYesThe notification template ID.
propertiesarrayYesMust include a recipients array.

$client->generateHashedToken($userId)

Generates an HMAC token for backend token authentication.
$token = $client->generateHashedToken('user_42');
ParameterTypeDescription
$userIdstringThe user’s unique identifier.
Returns: string — an SHA-256 HMAC hash.

$client->config($opts)

Configures SDK behavior.
$client->config(['autoSendDelayMs' => 2000]);
KeyTypeDefaultDescription
autoSendDelayMsint1000Delay in ms (used internally).

Laravel example

In a Laravel application, you might set up the client as a singleton:
// app/Providers/AppServiceProvider.php
use Notifizz\NotifizzClient;

public function register()
{
    $this->app->singleton(NotifizzClient::class, function () {
        return new NotifizzClient(
            config('services.notifizz.auth_secret'),
            config('services.notifizz.sdk_secret')
        );
    });
}
Then use it anywhere via dependency injection:
use Notifizz\NotifizzClient;

class OrderController extends Controller
{
    public function ship(Order $order, NotifizzClient $notifizz)
    {
        // ... ship the order ...

        $notifizz->track([
            'eventName' => 'order_shipped',
            'sdkSecretKey' => config('services.notifizz.sdk_secret'),
            'properties' => [
                'orderId' => $order->id,
                'carrier' => $order->carrier,
            ],
        ])->workflow('shipping_notification', [
            ['id' => (string) $order->user_id, 'email' => $order->user->email],
        ])->send();
    }
}

Next steps

Event Tracking overview

Compare all backend SDKs.

Notification Center

Set up the widget to display the notifications you’re sending.