broken-titan / laravel-klaviyo-channel
Laravel 的 Klaviyo 通知通道。
v2.0.2
2021-10-16 00:56 UTC
Requires
- php: >=7.2
- illuminate/notifications: ^5.8 || ^6.0 || ^7.0 || ^8.0
- klaviyo/php-sdk: ^2.0
Requires (Dev)
- mockery/mockery: ^1.3
- phpunit/phpunit: ^9.2
README
此包简化了 Laravel 与 Klaviyo 的集成,以便通过通道发送通知。
内容
安装
使用 Composer 安装此包
composer require broken-titan/laravel-klaviyo-channel
配置
在您开始使用 Klaviyo 服务之前,您必须从您的 Klaviyo 账户设置中获取一个私有和公共 API 密钥。密钥必须分配给 .env 文件中的 KLAVIYO_API_KEY 和 KLAVIYO_API_PUBLIC_KEY。
您还应该发布一个配置文件,该文件将在您的配置文件夹中生成 klaviyo.php。
使用
安装完成后,您可以通过创建标准的 Laravel 通知来向 Klaviyo 发送事件。例如
namespace App\Notifications;
use Illuminate\Notifications\Notification;
use BrokenTitan\Klaviyo\Channels\KlaviyoChannel;
use BrokenTitan\Klaviyo\Messages\KlaviyoTrackMessage;
use DateTimeImmutable;
class UserCreated extends Notification {
/**
* Get the notification's delivery channels.
*
* @method via
* @param mixed $notifiable
* @return array
*/
public function via($notifiable) {
return [KlaviyoChannel::class];
}
/**
* Sends the notification to Klaviyo.
*
* @method toKlaviyo
* @param mixed $notifiable
* @return BrokenTitan\Klaviyo\Messages\KlaviyoTrackMessage
*/
public function toKlaviyo($notifiable) : KlaviyoTrackMessage {
$customerProperties = ['$email' => $notifiable->email];
$properties = ['user_id' => $notifiable->user_id];
return new KlaviyoTrackMessage("User Created", $customerProperties, $properties, new DateTimeImmutable);
}
}
在 toKlayivo 中,您可以返回多种通知消息类型:KlaviyoTrackMessage、KlaviyoTrackOnceMessage、KlaviyoIdentifyMessage。使用其中之一将产生 Klaviyo 适当的事件。请参阅方法参数以获取传递适当参数的相应信息。
测试
$ composer test
安全性
如果您发现任何会影响现有用户的安全问题,请通过电子邮件 contact@broken-titan.com 而不是使用问题跟踪器。
贡献
欢迎为此包做出贡献。
致谢
许可证
MIT 许可证(MIT)。有关更多信息,请参阅许可证文件。