TODO
- support for ajax
The best way to install Eflyax/Facebook-pixel is using Composer:
$ composer require eflyax/facebook-pixel
Add to your neon config:
extensions:
facebookPixel: Eflyax\FacebookPixel\DI\FacebookPixelExtension
and configuration with you FB pixel ID:
facebookPixel:
id: '111122223333444'
productIdPrefix: '42' # optional
Be careful you add FB pixel ID as string, there was issues with integer
Inject FB pixel factory and service to your module where you want to render FB pixel. FB pixel service will help you to render specific events.
abstract class BaseFrontPresenter extends BasePresenter
{
/** @var IFacebookPixelFactory @inject */
public $IFacebookPixelFactory;
/** @var FacebookPixel */
public $facebookPixel;
protected function startup()
{
parent::startup();
$this->facebookPixel = $this['facebookPixel'];
}
.
.
protected function createComponentFacebookPixel()
{
return $this->IFacebookPixelFactory->create();
}
}
Now you are ready to render FB pixel in layout
{control facebookPixel}
In method where you add product to cart call eventStart like this:
$this->facebookPixel->addToCart(
$productId,
$productTitle,
$productCategory,
$productPrice,
$currencyCode
);
$this->facebookPixel->purchase($totalPrice, $currencyCode);
For one product:
$this->facebookPixel->viewContent(
$productId,
$productTitle,
$productCategory,
$productPrice,
$currencyCode
);
For more products (category):
$this->facebookPixel->viewContent(
$productIds
);
If you want to validate events which you send to facebook I can recommend this browser plugin: Facebook Pixel Helper
$ cd tests
$ composer install
$ mkdir temp
$ ./vendor/bin/codecept build
$ ./vendor/bin/codecept run