Tip
Need help? Join our Discord or email jesse@bentonow.com for personalized support.
The Bento PHP SDK makes it quick and easy to build an excellent analytics experience in your PHP application. We provide powerful and customizable APIs that can be used out-of-the-box to track your users' behavior, manage subscribers, and send emails. We also expose low-level APIs so that you can build fully custom experiences.
Get started with our 📚 integration guides, or 📘 browse the SDK reference.
❤️ Thank you @cavel (in Discord) from GuitarCreative for your contribution to the Laravel documentation (which lead to the creation of our new official Laravel SDK).
- Simple event tracking: We make it easy for you to track user events and behavior in your application.
- Subscriber management: Easily add, update, and remove subscribers from your Bento account.
- Custom fields: Track and update custom fields for your subscribers to store additional data.
- Purchase tracking: Monitor customer purchases and calculate lifetime value (LTV) for your subscribers.
- Batch operations: Perform bulk imports of subscribers and events for efficient data management.
- Email validation: Validate email addresses to ensure data quality.
The Bento PHP SDK requires PHP 7.4+ and Composer.
Bento Account for a valid SITE_UUID, BENTO_PUBLISHABLE_KEY & BENTO_SECRET_KEY.
Install the Bento SDK using Composer:
composer require bentonow/bento-php-sdk
Initialize the Bento client:
use bentonow\Bento\BentoAnalytics;
$bento = new BentoAnalytics([
'authentication' => [
'secretKey' => 'bento-secret-key',
'publishableKey' => 'bento-publishable-key'
],
'siteUuid' => 'bento-site-uuid'
]);
Track events and manage subscribers.
$bento->V1->tagSubscriber([
'email' => 'user@example.com',
'tagName' => 'New Customer',
]);
$bento->V1->addSubscriber([
'email' => 'user@example.com',
'fields' => [
'firstName' => 'John',
'lastName' => 'Doe',
],
]);
$bento->V1->removeSubscriber([
'email' => 'user@example.com',
]);
$bento->V1->updateFields([
'email' => 'user@example.com',
'fields' => [
'firstName' => 'John',
],
]);
$bento->V1->trackPurchase([
'email' => 'user@example.com',
'purchaseDetails' => [
'unique' => [
'key' => 1234,
],
'value' => [
'amount' => 100,
'currency' => 'USD',
],
],
]);
$bento->V1->track([
'email' => 'user@example.com',
'type' => '$custom.event',
'details' => [
'fromCustomEvent' => true,
],
]);
$bento->V1->Batch->importSubscribers([
'subscribers' => [
['email' => 'user1@example.com', 'age' => 25],
['email' => 'user2@example.com', 'name' => 'Jane Doe'],
]
]);
use bentonow\Bento\SDK\Batch\BentoEvents;
$bento->V1->Batch->importEvents([
'events' => [
['email' => 'user@example.com', 'type' => BentoEvents::SUBSCRIBE],
['email' => 'user@example.com', 'type' => BentoEvents::UNSUBSCRIBE],
[
'email' => 'user@example.com',
'details' => [
'customData' => 'Used internally.'
],
'type' => '$custom.myEvent'
]
]
]);
$bento->V1->Commands->addTag([
'email' => 'user@example.com',
'tagName' => 'VIP',
]);
$bento->V1->Commands->removeTag([
'email' => 'user@example.com',
'tagName' => 'VIP',
]);
$bento->V1->Commands->addField([
'email' => 'user@example.com',
'field' => [
'key' => 'favoriteColor',
'value' => 'blue',
],
]);
$bento->V1->Commands->removeField([
'email' => 'user@example.com',
'fieldName' => 'favoriteColor',
]);
$bento->V1->Commands->subscribe([
'email' => 'user@example.com',
]);
$bento->V1->Commands->unsubscribe([
'email' => 'user@example.com',
]);
$bento->V1->Events->createEvent([
'type' => '$completed_onboarding',
'email' => 'user@example.com',
]);
$bento->V1->Experimental->validateEmail([
'email' => 'user@example.com',
]);
$bento->V1->Experimental->guessGender([
'name' => 'Alex',
]);
$bento->V1->Experimental->geolocate([
'ip' => '127.0.0.1',
]);
$bento->V1->Experimental->checkBlacklist([
'domain' => 'example.com',
]);
$fields = $bento->V1->Fields->getFields();
$bento->V1->Fields->createField([
'key' => 'favoriteColor',
]);
$responses = $bento->V1->Forms->getResponses('form-id-123');
$subscriber = $bento->V1->Subscribers->getSubscribers([
'email' => 'user@example.com',
]);
$bento->V1->Subscribers->createSubscriber([
'email' => 'newuser@example.com',
]);
$tags = $bento->V1->Tags->getTags();
$bento->V1->Tags->createTag([
'name' => 'Premium',
]);
For a detailed reference of the types used in the Bento PHP SDK, please refer to the Types Reference section in the full documentation.
- All events must be identified with an email address.
- Most events are indexed within seconds in your Bento account.
- Batch operations are available for importing subscribers and events efficiently.
- The SDK provides seamless integration with Laravel applications.
- Email validation and experimental features are available for advanced use cases.
We welcome contributions! Please see our contributing guidelines for details on how to submit pull requests, report issues, and suggest improvements.
The Bento SDK for PHP is available as open source under the terms of the MIT License.