mtechraw/social-capi
最新稳定版本:v2.8
Composer 安装命令:
composer require mtechraw/social-capi
包简介
Laravel package to send CAPI events
README 文档
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
统计信息
- 总下载量: 25
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-07-01