PHP code example of combindma / laravel-facebook-pixel

1. Go to this page and download the library: Download combindma/laravel-facebook-pixel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

combindma / laravel-facebook-pixel example snippets


use Combindma\FacebookPixel\Facades\MetaPixel;

MetaPixel::track('Purchase', ['currency' => 'USD', 'value' => 30.00]);

return view('thank-you');

use Combindma\FacebookPixel\Facades\MetaPixel;

MetaPixel::track('AddToCart', ['currency' => 'USD', 'value' => 30.00], 'cart-line-1');
MetaPixel::trackCustom('NewsletterSignup', ['source' => 'footer']);

use Combindma\FacebookPixel\MetaPixelMiddleware;
use Illuminate\Support\Facades\Route;

Route::middleware(MetaPixelMiddleware::class)->group(function () {
    // Your form and thank-you routes...
});

use Combindma\FacebookPixel\Facades\MetaPixel;

MetaPixel::flashEvent('Lead', ['content_name' => 'Contact form']);

return redirect('/thank-you');

use Combindma\FacebookPixel\Facades\MetaPixel;
use FacebookAds\Object\ServerSide\CustomData;

$customData = (new CustomData())
    ->setCurrency('USD')
    ->setValue(30.00);

MetaPixel::trackAndSend(
    'Purchase',
    ['currency' => 'USD', 'value' => 30.00],
    $customData,
    eventId: 'order-123',
);

MetaPixel::send('Purchase', 'order-123', $customData);

$userData = MetaPixel::userData()
    ->setEmail('[email protected]')
    ->setPhone('12345678901');

MetaPixel::send('Purchase', 'order-123', $customData, userData: $userData);

MetaPixel::macro('purchase', function ($amount) {
    MetaPixel::track('Purchase', ['currency' => 'USD', 'value' => $amount]);
});

// In your controller:
MetaPixel::purchase(30.00);
bash
php artisan vendor:publish --tag="meta-pixel-config"
php artisan vendor:publish --tag="meta-pixel-views"