bentonow/bento-php-sdk
Composer 安装命令:
composer require bentonow/bento-php-sdk
包简介
🍱 Bento PHP SDK and tracking library
README 文档
README
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).
Table of contents
Features
- 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.
Requirements
The Bento PHP SDK requires PHP 7.4+ and Composer.
Bento Account for a valid SITE_UUID, BENTO_PUBLISHABLE_KEY & BENTO_SECRET_KEY.
Getting started
Installation
Install the Bento SDK using Composer:
composer require bentonow/bento-php-sdk
Configuration
Initialize the Bento client:
use bentonow\Bento\BentoAnalytics; $bento = new BentoAnalytics([ 'authentication' => [ 'secretKey' => 'bento-secret-key', 'publishableKey' => 'bento-publishable-key' ], 'siteUuid' => 'bento-site-uuid' ]);
Modules
Analytics (Base Module)
Track events and manage subscribers.
Tag a Subscriber
$bento->V1->tagSubscriber([ 'email' => 'user@example.com', 'tagName' => 'New Customer', ]);
Add a Subscriber
$bento->V1->addSubscriber([ 'email' => 'user@example.com', 'fields' => [ 'firstName' => 'John', 'lastName' => 'Doe', ], ]);
Remove a Subscriber
$bento->V1->removeSubscriber([ 'email' => 'user@example.com', ]);
Update Fields
$bento->V1->updateFields([ 'email' => 'user@example.com', 'fields' => [ 'firstName' => 'John', ], ]);
Track Purchase
$bento->V1->trackPurchase([ 'email' => 'user@example.com', 'purchaseDetails' => [ 'unique' => [ 'key' => 1234, ], 'value' => [ 'amount' => 100, 'currency' => 'USD', ], ], ]);
Track Event
$bento->V1->track([ 'email' => 'user@example.com', 'type' => '$custom.event', 'details' => [ 'fromCustomEvent' => true, ], ]);
Batch
Import Subscribers
$bento->V1->Batch->importSubscribers([ 'subscribers' => [ ['email' => 'user1@example.com', 'age' => 25], ['email' => 'user2@example.com', 'name' => 'Jane Doe'], ] ]);
Import Events
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' ] ] ]);
Commands
Add Tag
$bento->V1->Commands->addTag([ 'email' => 'user@example.com', 'tagName' => 'VIP', ]);
Remove Tag
$bento->V1->Commands->removeTag([ 'email' => 'user@example.com', 'tagName' => 'VIP', ]);
Add Field
$bento->V1->Commands->addField([ 'email' => 'user@example.com', 'field' => [ 'key' => 'favoriteColor', 'value' => 'blue', ], ]);
Remove Field
$bento->V1->Commands->removeField([ 'email' => 'user@example.com', 'fieldName' => 'favoriteColor', ]);
Subscribe
$bento->V1->Commands->subscribe([ 'email' => 'user@example.com', ]);
Unsubscribe
$bento->V1->Commands->unsubscribe([ 'email' => 'user@example.com', ]);
Events
Create Event
$bento->V1->Events->createEvent([ 'type' => '$completed_onboarding', 'email' => 'user@example.com', ]);
Experimental
Validate Email
$bento->V1->Experimental->validateEmail([ 'email' => 'user@example.com', ]);
Guess Gender
$bento->V1->Experimental->guessGender([ 'name' => 'Alex', ]);
Geolocate
$bento->V1->Experimental->geolocate([ 'ip' => '127.0.0.1', ]);
Check Blacklist
$bento->V1->Experimental->checkBlacklist([ 'domain' => 'example.com', ]);
Fields
Get Fields
$fields = $bento->V1->Fields->getFields();
Create Field
$bento->V1->Fields->createField([ 'key' => 'favoriteColor', ]);
Forms
Get Form Responses
$responses = $bento->V1->Forms->getResponses('form-id-123');
Subscribers
Get Subscriber
$subscriber = $bento->V1->Subscribers->getSubscribers([ 'email' => 'user@example.com', ]);
Create Subscriber
$bento->V1->Subscribers->createSubscriber([ 'email' => 'newuser@example.com', ]);
Tags
Get Tags
$tags = $bento->V1->Tags->getTags();
Create Tag
$bento->V1->Tags->createTag([ 'name' => 'Premium', ]);
Types Reference
For a detailed reference of the types used in the Bento PHP SDK, please refer to the Types Reference section in the full documentation.
Things to Know
- 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.
Contributing
We welcome contributions! Please see our contributing guidelines for details on how to submit pull requests, report issues, and suggest improvements.
License
The Bento SDK for PHP is available as open source under the terms of the MIT License.
bentonow/bento-php-sdk 适用场景与选型建议
bentonow/bento-php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 127.89k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2021 年 02 月 15 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 bentonow/bento-php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 bentonow/bento-php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 127.89k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 26
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-02-15