1. Go to this page and download the library: Download snipform/php-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/ */
snipform / php-sdk example snippets
use SnipForm\SnipForm;
$snipform = SnipForm::client('snipform_pat_xxx');
// List sessions matching a query — auto-paginated
foreach ($snipform->signals()
->last28Days()
->where('country', 'US')
->whereStartsWith('entry_path', '/blog')
->sessions() as $session
) {
echo $session->entryPath.' from '.$session->source.PHP_EOL;
}
// Headline metrics for the same query
$metrics = $snipform->signals()
->last7Days()
->where('utm_content', 'pub_12345') // an affiliate
->metrics();
echo "Sessions: {$metrics->sessions}, bounce: {$metrics->bounceRate}%";
$dto->toArray(); // public fields as an associative array
json_encode($dto); // implements JsonSerializable — same as toArray()
public function dashboard(SnipForm $snipform)
{
return $snipform->signals()->last7Days()->metrics(); // serializes to JSON
}
public function sessions(SnipForm $snipform)
{
return $snipform->signals()->last7Days()->sessions(); // page 1 of Laravel paginator JSON
}
public function property(SnipForm $snipform)
{
return $snipform->properties()->overview(); // PropertyOverview → typed JSON
}
$property = $snipform->properties()->overview();
$property->id; // string
$property->name; // string
$property->domain; // string
$property->hasSignals; // bool — tracking has fired at least once
$property->state; // string|null — raw state value
$property->stateName; // string|null — human label
$property->counts; // array — e.g. ['sessions' => 188862, 'forms' => 4, 'pages' => 2]
use SnipForm\Query\SessionField;
$snipform->signals()
->where(SessionField::COUNTRY, 'US')
->whereBetween(SessionField::TIME_ON_SITE, 60, 300)
->whereStartsWith(SessionField::ENTRY_PATH, '/blog')
->sessions();
// Strings still work — the SDK doesn't know the field's type without an
// enum case, so op/field mismatches won't be caught client-side:
$snipform->signals()->where('country', 'US')->sessions();
$snipform->signals()->whereBetween(SessionField::COUNTRY, 0, 10);
// → IncompatibleFieldOperator: Operator `between` is not valid for field
// `country` (type: keyword). Valid ops: equals, contains, starts_with,
// regex, exists.
->today()
->yesterday()
->last7Days()
->last28Days()
->monthToDate()
->yearToDate()
->last12Months()
// Custom date ranges — pick whichever form reads best
->between('2026-01-01', '2026-01-31') // both at once
->customPeriod('2026-01-01', '2026-01-31') // same
->customPeriod()
->fromDate('2026-01-01')
->toDate('2026-01-31') // piecemeal
// Or via the enum:
use SnipForm\Query\Period;
->period(Period::LAST_28)
->period('last_28') // string also fine; validated upfront
// Every click for one link, walking pages
foreach ($client->clicks()->forLink($linkId)->all() as $click) {
echo $click->city.' on '.$click->device.PHP_EOL;
}
// Last 30 days of human clicks on a whole campaign
foreach ($client->clicks()
->forGroup($groupId)
->between(strtotime('-30 days'), time())
->usersOnly()
->all() as $click
) { ... }
// Just bot traffic
$bots = $client->clicks()->botsOnly()->all()->count();
// Single click
$click = $client->clicks()->find($clickId);
use Illuminate\Foundation\Auth\User as Authenticatable;
use SnipForm\Laravel\Concerns\Identifiable;
class User extends Authenticatable
{
use Identifiable;
}
class User extends Authenticatable
{
use Identifiable;
// Custom external id — defaults to $this->getKey()
protected function snipformExternalId(): string
{
return 'usr_'.$this->uuid;
}
// Merged on top of the auto-derived traits
protected function snipformTraits(): array
{
return [
'company' => $this->team?->name,
'meta' => [
['key' => 'plan', 'value' => $this->subscription_plan],
],
];
}
}
use SnipForm\Laravel\Facades\Snipform;
Snipform::auth(); // identify auth()->user(), no-op for guests
Snipform::user($someOtherUser); // identify any model with the Identifiable trait
Snipform::payload([ // raw passthrough — bypass the trait
'email' => '[email protected]',
'traits' => ['first_name' => 'Jane'],
]);
Snipform::contacts()->find($id); // SDK Contacts resource — find/update/delete/all
Snipform::contacts()->update($id, [
'lifecycle_stage' => 'customer',
]);
Snipform::client(); // escape hatch — full SDK Client
public function checkout(Request $request, \SnipForm\Client $snipform)
{
$sessionId = $request->attributes->get(
\SnipForm\Laravel\Middleware\SnipFormSessionMiddleware::ATTRIBUTE,
);
if ($sessionId) {
$snipform->session()->event([
'session_id' => $sessionId,
'name' => 'checkout_started',
]);
}
}
use SnipForm\Exceptions\AuthenticationException;
use SnipForm\Exceptions\ApiException;
use SnipForm\Exceptions\InvalidPeriodException;
use SnipForm\Exceptions\MissingSessionIdException;
use SnipForm\Exceptions\SnipFormException;
try {
$sessions = $snipform->signals()->last7Days()->sessions()->all();
} catch (InvalidPeriodException $e) {
// SDK-side — invalid string passed to period(). Caught before any HTTP call.
} catch (MissingSessionIdException $e) {
// SDK-side — session_id couldn't be resolved from the Request.
} catch (AuthenticationException $e) {
// 401 / 403 — token bad or out of scope.
} catch (ApiException $e) {
// 4xx / 5xx with a structured body — see $e->status, $e->errors, $e->body.
// Validation errors are expanded into the message inline:
// "The given data was invalid. — period: must be one of ..."
} catch (SnipFormException $e) {
// any other SDK-side failure (transport, JSON decode, etc.)
}
SnipForm::client('snipform_pat_xxx', [
'base_url' => 'https://api.snipform.io', // default
'path_prefix' => '/v2/', // default; older deployments may serve under '/api/v2/'
'timeout' => 30, // seconds, request timeout
'verify_ssl' => true, // default; set false for local self-signed certs
]);