diff --git a/README.md b/README.md index fed8c2e..dbd936f 100755 --- a/README.md +++ b/README.md @@ -1,4 +1,8 @@ -#Nette extension for Facebook Pixel. +# Nette extension for Facebook Pixel. + +TODO +* implement missing events (search, addToWishList, etc..) +* support for ajax ## Requirements @@ -8,8 +12,8 @@ The best way to install Eflyax/Facebook-pixel is using [Composer](http://getcomposer.org/): -```sh -$ composer require eflyax/facebook-pixel +```bash +$ composer require eflyax/facebook-pixel ``` ## Usage @@ -25,7 +29,7 @@ and configuration with you FB pixel ID: ``` facebookPixel: id: '111122223333444' - productIdPrefix: '42' // optional + productIdPrefix: '42' # optional ``` Be careful you add FB pixel ID as string, there was issues with integer @@ -35,29 +39,37 @@ 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. -``` +```php abstract class BaseFrontPresenter extends BasePresenter { /** @var IFacebookPixelFactory @inject */ - public $facebookPixelFactory; + public $IFacebookPixelFactory; + + /** @var FacebookPixel */ + public $facebookPixel; + - /** @var FacebookPixelService @inject */ - public $facebookPixelService; + protected function startup() + { + parent::startup(); + $this->facebookPixel = $this['facebookPixel']; + } + . . protected function createComponentFacebookPixel() { - return $this->facebookPixelFactory->create(); + return $this->IFacebookPixelFactory->create(); } } ``` #### Frontend -Now you are ready to render basic FB pixel for event PageView. Render control faceboobPixel in layout +Now you are ready to render FB pixel in layout `{control facebookPixel}` @@ -66,82 +78,57 @@ Now you are ready to render basic FB pixel for event PageView. Render control fa #### AddToCart -##### Backend In method where you add product to cart call eventStart like this: -```` - public function actionAddProduct($idProduct, $quantity = 1) - { - ... - $this->facebookPixelService->eventStart(FacebookPixelService::EVENT_ADD_TO_CART); - } +````php + $this->facebookPixel->addToCart( + $productId, + $productTitle, + $productCategory, + $productPrice, + $currencyCode + ); ```` -##### Frontend -This control is rendered only if you call eventStart addToCart on backend. When you render this control event is automatically deactivated - -``` -{control facebookPixel:addToCart, - $product->getId(), - $product->getTitle(), - $product->getDescription(), - $product->getPrice(), - $currency->getCode() -} -``` - #### Purchase -##### Backend -Before you redirect customer on thank you page call startEvent: - -`$this->facebookPixelService->eventStart(FacebookPixelService::EVENT_PURCHASE);` - -##### Frontend - ``` -{control facebookPixel:purchase, - $totalPrice, - $currency->getCode(), - $itemIds -} + $this->facebookPixel->purchase($totalPrice, $currencyCode); ``` - -`$itemIds` can contains id for one or more products - - #### ViewContent -##### Frontend + For one product: -``` -{control facebookPixel:viewContent, - $product->getId(), - $product->getTitle(), - $product->getDescription(), - $product->getPrice(), - $currency->getCode() -} +```php +$this->facebookPixel->viewContent( + $productId, + $productTitle, + $productCategory, + $productPrice, + $currencyCode +); ``` For more products (category): -``` -{control facebookPixel:viewContent, + +```php +$this->facebookPixel->viewContent( $productIds -} +); ``` ## Events validation -If you want to validate events sended to facebook I can recommend this browser plugin: +If you want to validate events which you send to facebook I can recommend this browser plugin: [Facebook Pixel Helper](https://chrome.google.com/webstore/detail/FacebookPixel-helper/fdgfkebogiimcoedlicjlajpkdmockpc) ## How to run tests -``` -$ cd tests -$ composer install -$ ./vendor/bin/codecept build -$ ./vendor/bin/codecept run +```bash +$ cd tests +$ composer install +$ mkdir temp +$ ./vendor/bin/codecept build +$ ./vendor/bin/codecept run ```