Skip to content

🍱 Bento PHP SDK and tracking library

License

Notifications You must be signed in to change notification settings

ziptied/bento-php-sdk

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

79 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Bento PHP SDK

Tip

Need help? Join our Discord or email [email protected] 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).

Build Status

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' => '[email protected]',
  'tagName' => 'New Customer',
]);

Add a Subscriber

$bento->V1->addSubscriber([
  'email' => '[email protected]',
  'fields' => [
    'firstName' => 'John',
    'lastName' => 'Doe',
  ],
]);

Remove a Subscriber

$bento->V1->removeSubscriber([
  'email' => '[email protected]',
]);

Update Fields

$bento->V1->updateFields([
  'email' => '[email protected]',
  'fields' => [
    'firstName' => 'John',
  ],
]);

Track Purchase

$bento->V1->trackPurchase([
  'email' => '[email protected]',
  'purchaseDetails' => [
    'unique' => [
      'key' => 1234,
    ],
    'value' => [
      'amount' => 100,
      'currency' => 'USD',
    ],
  ],
]);

Track Event

$bento->V1->track([
  'email' => '[email protected]',
  'type' => '$custom.event',
  'details' => [
    'fromCustomEvent' => true,
  ],
]);

Batch

Import Subscribers

$bento->V1->Batch->importSubscribers([
  'subscribers' => [
    ['email' => '[email protected]', 'age' => 25],
    ['email' => '[email protected]', 'name' => 'Jane Doe'],
  ]
]);

Import Events

use bentonow\Bento\SDK\Batch\BentoEvents;

$bento->V1->Batch->importEvents([
  'events' => [
    ['email' => '[email protected]', 'type' => BentoEvents::SUBSCRIBE],
    ['email' => '[email protected]', 'type' => BentoEvents::UNSUBSCRIBE],
    [
      'email' => '[email protected]',
      'details' => [
        'customData' => 'Used internally.'
      ],
      'type' => '$custom.myEvent'
    ]
  ]
]);

Commands

Add Tag

$bento->V1->Commands->addTag([
  'email' => '[email protected]',
  'tagName' => 'VIP',
]);

Remove Tag

$bento->V1->Commands->removeTag([
  'email' => '[email protected]',
  'tagName' => 'VIP',
]);

Add Field

$bento->V1->Commands->addField([
  'email' => '[email protected]',
  'field' => [
    'key' => 'favoriteColor',
    'value' => 'blue',
  ],
]);

Remove Field

$bento->V1->Commands->removeField([
  'email' => '[email protected]',
  'fieldName' => 'favoriteColor',
]);

Subscribe

$bento->V1->Commands->subscribe([
  'email' => '[email protected]',
]);

Unsubscribe

$bento->V1->Commands->unsubscribe([
  'email' => '[email protected]',
]);

Events

Create Event

$bento->V1->Events->createEvent([
  'type' => '$completed_onboarding',
  'email' => '[email protected]',
]);

Experimental

Validate Email

$bento->V1->Experimental->validateEmail([
  'email' => '[email protected]',
]);

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' => '[email protected]',
]);

Create Subscriber

$bento->V1->Subscribers->createSubscriber([
  'email' => '[email protected]',
]);

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

  1. All events must be identified with an email address.
  2. Most events are indexed within seconds in your Bento account.
  3. Batch operations are available for importing subscribers and events efficiently.
  4. The SDK provides seamless integration with Laravel applications.
  5. 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.

About

🍱 Bento PHP SDK and tracking library

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%