mtechraw / social-capi
Laravel package to send CAPI events
Installs: 25
Dependents: 0
Suggesters: 0
Security: 0
Stars: 8
Watchers: 0
Forks: 1
Open Issues: 0
pkg:composer/mtechraw/social-capi
Requires
- facebook/php-business-sdk: ^22.0
- illuminate/support: ^11.0
README
SocialCAPI is a Laravel 11+ compatible package that provides a wrapper for sending Facebook Conversions API (CAPI) events server-side using the official facebook/php-business-sdk. It is ideal for tracking conversions and interactions directly from your backend with support for test_event_code, dynamic data, and Laravel configuration management.
๐ Features
- Laravel 11 compatible
- Built on top of Facebook's official Business SDK
- Supports
test_event_codefor development and QA validation - Fully dynamic input mapping for user data
- Easily configurable via Laravel config and
.env - Composer-installable, auto-discovered Laravel service provider
๐ฆ Installation
Install via Composer:
composer require mtechraw/social-capi
๐ Configuration
Step 1: Publish Configuration File
php artisan vendor:publish --tag=config
This will publish config/fb-capi.php:
return [ 'pixel_id' => env('FB_PIXEL_ID'), 'access_token' => env('FB_ACCESS_TOKEN'), ];
Step 2: Set Environment Variables
Update your .env file:
FB_PIXEL_ID=your_facebook_pixel_id FB_ACCESS_TOKEN=your_fb_access_token
โ Usage Example
You can use the FacebookChannel class directly using Laravel's container:
use SocialCAPI\Facebook\FacebookChannel; $data = [ 'email' => 'john@example.com', 'ip' => '127.0.0.1', 'city' => 'local', 'state' => 'Texas', 'country' => 'US', 'event_name' => 'Purchase', 'test_event_code' => 'TEST1234ABC', // Optional: for Facebook Events Manager test tab ]; app(FacebookChannel::class)->send($data);
โ๏ธ Advanced
Supported Event Types
You can send any standard Facebook CAPI event type including:
PurchaseInitiateCheckoutLeadAddToCart- etc.
You only need to specify the event name in the event_name key.
Dynamic Data Input
The input array can contain any of the following fields (optional, only what's provided will be sent):
emailcountrycitystateipevent_nametest_event_code
๐งช Using test_event_code
To send a test event (visible in Facebook Events Manager โ Test Events):
- Go to Events Manager โ your Pixel โ Test Events
- Copy the test event code (e.g.
TEST1234ABC) - Add it in the
$dataarray like:
'test_event_code' => 'TEST1234ABC'
This event will appear in the Test Events tab for validation.
๐งฉ Folder Structure
social-capi/
โโโ config/
โ โโโ fb-capi.php
โโโ src/
โโโ Facebook/
โโโ FBServiceProvider.php
โโโ FacebookChannel.php
โโโ FacebookMessage.php
๐ License
MIT License โ see the LICENSE file for details.
๐ Author
Developed with โค๏ธ by Mukesh Rawat