sammakescode/klaviyo-api

由普通人编写的PHP Klaviyo库

2.0.0 2024-07-24 17:50 UTC

This package is auto-updated.

Last update: 2024-09-24 18:10:25 UTC


README

Klaviyo的PHP库看起来像是在没有显示器的计算机上组装的,不是吗?这里,我创建了一个基于Guzzle的基本层,以提供更合理的体验。

要求

  • PHP 8.2或更高版本
  • Composer

安装

composer require sammakescode/klaviyo-api

示例

本节将提供一个示例。有关更详细的信息,请参阅 Wiki

发送事件

我们可以这样为匿名用户发送一个事件。

    use \SamMakesCode\KlaviyoApi\KlaviyoApi;
    use \SamMakesCode\KlaviyoApi\Objects\Metric;
    use \SamMakesCode\KlaviyoApi\Objects\Profile;

    $client = new KlaviyoApi('your-api-key');
    $client->events()->create(Event::make(
        [
            'properties' => [
                'custom_property' => 'Why, yes!',
            ],
        ],
        Metric::make('Created Account'),
        Profile::make([
            'email' => 'john@example.org',
        ])
    ));

Laravel

库与Laravel配合得很好,但你需要为它设置一个服务提供者。

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use SamMakescode\KlaviyoApi\KlaviyoApi;

class KlaviyoServiceProvider extends ServiceProvider
{
    public function register(): void
    {
        $this->app->singleton(KlaviyoApi::class, function () {
            return new KlaviyoApi(
                env('KLAVIYO_API_KEY'),
            );
        });
    }
}

不要忘记将你的API密钥添加到你的 .env 文件中。

贡献

欢迎贡献和问题。