userscape/customerio
PHP client for the Customer.io API. Create, update, and delete customers, fire events (including historical/anonymous), and record pageviews. Returns a Response object with success() and message() for simple error handling.
Pros:
.env), and logging/monitoring tools.Cons:
siteId and apiSecret (securely stored in Laravel’s .env).createCustomer). High-volume use cases may require custom optimizations or external batching logic..env + config/services.php recommended).retry helper or custom packages like spatie/rate-limiter).siteId/apiSecret?Log facade, Sentry, or custom metrics)?spatie/customerio-api) that addresses the stale maintenance issue?customerio_id column)? Will this require custom model observers or traits?Laravel Compatibility:
array → array<string, mixed>) or runtime polyfills. Test with Laravel’s strict mode enabled.$this->app->singleton(Customerio\Api::class, function ($app) {
return new Customerio\Api(
config('services.customerio.site_id'),
config('services.customerio.api_secret'),
new Customerio\Request(new \GuzzleHttp\Client()) // Override with Laravel's Guzzle client
);
});
.env:
CUSTOMERIO_SITE_ID=your_site_id
CUSTOMERIO_API_SECRET=your_secret
'customerio' => [
'site_id' => env('CUSTOMERIO_SITE_ID'),
'api_secret' => env('CUSTOMERIO_API_SECRET'),
],
Database/Caching:
customerio_id column to relevant Laravel models (e.g., users table) for sync.Phase 1: Proof of Concept (PoC)
composer require userscape/customerio
createCustomer, fireEvent) using Laravel’s HTTP testing:
public function test_customer_creation()
{
$api = $this->app->make(Customerio\Api::class);
$response = $api->createCustomer('test123', 'test@example.com', ['test' => 'data']);
$response->success()->assertTrue();
}
Phase 2: Wrapper Layer
// app/Services/CustomerioService.php
class CustomerioService {
public function __construct(private Customerio\Api $api) {}
public function trackEvent(string $userId, string $eventName, array $data): void
{
$response = $this->api->fireEvent($userId, $eventName, $data);
if (!$response->success()) {
Log::error("Customer.io event failed: {$response->message()}");
throw new \RuntimeException("Event tracking failed");
}
}
}
// app/Jobs/FireCustomerioEvent.php
class FireCustomerioEvent implements ShouldQueue {
public function handle() {
$this->api->fireEvent($this->userId, $this->eventName, $this->data);
}
}
spatie/laravel-queue-retries).Phase 3: Deprecation Plan
laravel/framework and guzzlehttp/guzzle version constraints in composer.json to avoid conflicts:
"require": {
"laravel/framework": "^10.0",
"guzzlehttp/guzzle": "^6.5|^7.0"
},
"conflict": {
"guzzlehttp/gu
How can I help you explore Laravel packages today?