PHP code example of aghfatehi / laravel-meta-conversions
1. Go to this page and download the library: Download aghfatehi/laravel-meta-conversions 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/ */
aghfatehi / laravel-meta-conversions example snippets
// When a visitor lands on a product page — triggers Laravel Ecommerce Tracking
FacebookConversion::viewContent(
productId: $product->id,
productName: $product->name,
category: $product->category->name,
value: $product->price,
currency: 'SAR'
);
// When a visitor adds a product to cart
FacebookConversion::addToCart(
productId: $product->id,
productName: $product->name,
quantity: $request->quantity,
value: $price,
currency: 'SAR'
);
// When a visitor adds a product to wishlist
FacebookConversion::addToWishlist(
productId: $product->id,
productName: $product->name,
value: $product->price,
currency: 'SAR'
);
// When a visitor completes a purchase — the Meta Purchase Event
FacebookConversion::purchase(
value: $order->grand_total,
currency: 'SAR',
productIds: $order->orderDetails->pluck('product_id')->toArray()
);
// Auto-collected data for better Server Side Tracking Laravel
// 1. From auth()->user() → email, phone, name, last_name
// 2. From request() → ip, user_agent
// 3. From cookies → _fbp, _fbc