eflyax / facebook-pixel
Nette 的 Facebook pixel
v2.1
2017-11-08 05:29 UTC
Requires
- php: >= 5.3.7
- nette/application: ~2.3.0|~2.4.0
- nette/bootstrap: ~2.3.0|~2.4.0
- nette/di: ~2.3.0|~2.4.0
Requires (Dev)
- nette/bootstrap: ^2.4@dev
- nette/robot-loader: ^3.0
- nette/tester: @dev
This package is not auto-updated.
Last update: 2024-09-20 01:33:42 UTC
README
待办事项
- ajax 支持
需求
安装
安装 Eflyax/Facebook-pixel 的最佳方式是使用 Composer
$ composer require eflyax/facebook-pixel
用法
准备
扩展注册
将其添加到 neon 配置中
extensions:
facebookPixel: Eflyax\FacebookPixel\DI\FacebookPixelExtension
并使用您的 FB pixel ID 进行配置
facebookPixel:
id: '111122223333444'
productIdPrefix: '42' # optional
请注意,您必须将 FB pixel ID 作为字符串添加,整数可能会导致问题
后端
将 FB pixel 工厂和服务注入到您想要渲染 FB pixel 的模块中。FB pixel 服务将帮助您渲染特定事件。
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(); } }
前端
现在您可以在布局中渲染 FB pixel 了
{control facebookPixel}
事件
添加到购物车
在添加产品到购物车的方法中调用 eventStart,如下所示
$this->facebookPixel->addToCart( $productId, $productTitle, $productCategory, $productPrice, $currencyCode );
购买
$this->facebookPixel->purchase($totalPrice, $currencyCode);
查看内容
针对单个产品
$this->facebookPixel->viewContent( $productId, $productTitle, $productCategory, $productPrice, $currencyCode );
针对多个产品(类别)
$this->facebookPixel->viewContent( $productIds );
事件验证
如果您想验证发送给 Facebook 的事件,我推荐这个浏览器插件:Facebook Pixel Helper
如何运行测试
$ cd tests
$ composer install
$ mkdir temp
$ ./vendor/bin/codecept build
$ ./vendor/bin/codecept run