eflyax/facebook-pixel

Facebook pixel for Nette

v2.1 2017-11-08 05:29 UTC

This package is not auto-updated.

Last update: 2024-12-13 02:35:58 UTC


README

TODO

  • support for ajax

Requirements

Installation

The best way to install Eflyax/Facebook-pixel is using Composer:

$   composer require eflyax/facebook-pixel

Usage

Preparation

Extension registration

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

Backend

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();
    }
    
}

Frontend

Now you are ready to render FB pixel in layout

{control facebookPixel}

Events

AddToCart

In method where you add product to cart call eventStart like this:

    $this->facebookPixel->addToCart(
        $productId,
        $productTitle,
        $productCategory,
        $productPrice,
        $currencyCode
    );

Purchase

  $this->facebookPixel->purchase($totalPrice, $currencyCode);

ViewContent

For one product:

$this->facebookPixel->viewContent(
    $productId,
    $productTitle,
    $productCategory,
    $productPrice,
    $currencyCode
);

For more products (category):

$this->facebookPixel->viewContent(
    $productIds
);

Events validation

If you want to validate events which you send to facebook I can recommend this browser plugin: Facebook Pixel Helper

How to run tests

$   cd tests
$   composer install
$   mkdir temp
$   ./vendor/bin/codecept build
$   ./vendor/bin/codecept run