symfonylab/customerio-bundle

将 customer.io 集成到 Symfony

安装: 4

依赖项: 0

建议者: 0

安全: 0

星星: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2019-11-15 15:58 UTC

This package is not auto-updated.

Last update: 2024-09-29 06:02:40 UTC


README

Build Status

Latest Stable Version Total Downloads License

Symfony 集成 http://customer.io

配置

使用 composer 安装该包,并在您的 Kernel 中注册它。

然后配置您的 site_idapi_key

# app/config/config.yml

symfonylab_customer_io:
  site_id: <YOUR-SITE-ID>
  api_key: <YOUR-API-KEY>

使用方法

客户模型

在您的客户域类上实现 SymfonyLab\CustomerIOBundle\Model\CustomerInterface

事件跟踪/客户识别

use SymfonyLab\CustomerIOBundle\Event\TrackingEvent;
use SymfonyLab\CustomerIOBundle\Event\ActionEvent;

/** @var \Symfony\Component\EventDispatcher\EventDispatcher $tracker */
$dispatcher = $this->getContainer()->get('event_dispatcher');

$customer = $repo->getCustomer(); // retrieve your customer domain object

// send the customer over to customer.io for identification
$dispatcher->dispatch(new TrackingEvent($customer));

// now track a `click` event
$dispatcher->dispatch(new ActionEvent($customer, 'click'));

Webhooks

该包附带一个控制器,可以消费 customer.io webhooks

要使用它们,注册 routing.xml

# app/config/routing.yml

customerio_hooks:
    resource: "@SymfonyLabCustomerIOBundle/Resources/config/routing.yaml"

现在您的钩子 URL 将是 http://your.project.com/webhook,您需要在 customer.io 中配置。

完成后,您可以监听 webhook 事件

<service id="acme.webhooklistener" class="Acme\DemoBundle\Listener\WebhookListener">
    <tag name="kernel.event_listener" event="customer_io.email_clicked" method="onClick" />
</service>
use SymfonyLab\CustomerIOBundle\Event\WebHookEvent;

class WebhookListener
{
    public function onClick(WebHookEvent $event)
    {
        $this->logger->info('Customer clicked on email with address: ' . $event->getEmail());
    }
}