klaviyo/php-sdk
最新稳定版本:2.3.6
Composer 安装命令:
composer require klaviyo/php-sdk
包简介
Klaviyo PHP SDK
README 文档
README
Deprecation Notice
This SDK and its associated pip package are set to be deprecated on 2024-01-01 and will not receive further updates.
We recommend migrating over to our newest SDK.
You can read more about our SDK release history and support here
For a comparison between our old and new APIs, check out this guide.
Migration Instructions
NOTE: this change is not backwards compatible; migrating to the new SDK requires completing the following steps:
Install New SDK
composer require klaviyo/sdk
Update Import
From:
use Klaviyo\Klaviyo as Klaviyo;
To:
use Klaviyo\Client;
Update Client Instantiation
From:
$client = new Klaviyo( 'PRIVATE_API_KEY', 'PUBLIC_API_KEY' );
To:
$client = new Client('YOUR_API_KEY');
Updating SDK Calls
The new SDK has many changes to namespace (resource and function names), parameters (names, types, and format), and error handling. Additionally, the new SDK sticks to just standard/built-in PHP types (int, string, array, etc), and does not make use of custom Models, as this legacy one does. Please reference this section of the new SDK repo for details on how to update each operation.
Multistore limitation
The new SDK currently sets API keys at a global environment level. This means that if you manage multiple stores, each store's client must be running in a different environment. We plan to update this behavior to better support multistore applications.
What is Klaviyo?
Klaviyo is a real-time service for understanding your customers by aggregating all your customer data, identifying important groups of customers and then taking action. http://www.klaviyo.com/
What does this package do?
- Track customers and events directly from your backend.
How to install?
composer require klaviyo/php-sdk
API Examples
After installing the Klaviyo package you can initiate it using your public token which is for track events or identifying profiles and/or your private api key to utilize the metrics and list apis.
use Klaviyo\Klaviyo as Klaviyo; $client = new Klaviyo( 'PRIVATE_API_KEY', 'PUBLIC_API_KEY' );
You can then easily use Klaviyo to track events or identify people. Note, track and identify requests take your public token.
Track an event
use Klaviyo\Model\EventModel as KlaviyoEvent; $event = new KlaviyoEvent( array( 'event' => 'Filled out Profile', 'customer_properties' => array( '$email' => 'someone@mailinator.com' ), 'properties' => array( 'Added Social Accounts' => False ) ) ); $client->publicAPI->track( $event, true );
You can also add profile properties to the 'customer properties' attribute in the Event model
use Klaviyo\Model\EventModel as KlaviyoEvent; $event = new KlaviyoEvent( array( 'event' => 'Filled out Profile', 'customer_properties' => array( '$email' => 'someone@mailinator.com', '$first_name' => 'Thomas', '$last_name' => 'Jefferson' ), 'properties' => array( 'Added Social Accounts' => False ) ) ); $client->publicAPI->track( $event, true );
or just add a property to someone
use Klaviyo\Model\ProfileModel as KlaviyoProfile; $profile = new KlaviyoProfile( array( '$email' => 'thomas.jefferson@mailinator.com', '$first_name' => 'Thomas', '$last_name' => 'Jefferson', 'Plan' => 'Premium' ) ); $client->publicAPI->identify( $profile, true );
You can get metrics, a timeline of events and export analytics for a metric. See here for more https://www.klaviyo.com/docs/api/metrics
#return a list of all metrics in your Klaviyo account $client->metrics->getMetrics(); #return a timeline of all metrics $client->metrics->getMetricsTimeline(); #return a specific metric timeline using its metric ID $client->metrics->getMetricTimelineById( 'METRICID' ); #export metric specific values $client->metrics->getMetricExport( 'METRICID' );
You can create, update, read, and delete lists. See here for more information https://www.klaviyo.com/docs/api/v2/lists
#create a list $client->lists->createList( 'List Name' ); #Get all lists in your Klaviyo account $client->lists->getLists(); #Get information about a list $client->lists->getListById( 'ListId' ); #update a lists properties $client->lists->updateListNameById( 'ListId', 'ListName' ); #Delete a list from account $client->lists->deleteList( 'ListId' ); #Subscribe or re-subscribe profiles to a list $client->lists->addSubscribersToList( 'ListId', array $arrayOfProfiles ); #Check if profiles are on a list and not suppressed $client->lists->checkListSubscriptions( 'ListId', array $emails, array $phoneNumbers, array $pushTokens ); #Unsubscribe and remove profiles from a list $client->lists->deleteSubscribersFromList( 'ListId', array $emails ); #Add members to list without affecting consent status $client->lists->addMembersToList( 'ListId', array $arrayOfProfiles ); #Check if profiles are on a list $client->lists->checkListMembership( 'ListId', array $emails, array $phoneNumbers, array $pushTokens ); #Remove members from a list without changing their consent status $client->lists->removeMembersFromList( 'ListId', array $emails ); #Get all exclusions on a list $client->lists->getListExclusions( 'ListId' ); #Get all of the emails, phone numbers and push tokens for profiles in a given list or segment $client->lists->getAllMembers( 'GroupId', $marker = $marker_value );
You can fetch profile information given the profile ID, See here for more information https://www.klaviyo.com/docs/api/people
#Get profile by profileId $client->profiles->getProfile( 'ProfileId' ); #Update a profile $client->profiles->updateProfile( 'ProfileId', array $properties ); #Get all metrics for a profile $client->profiles->getAllProfileMetricsTimeline( 'ProfileId' ); #Get a specific metric for a profile $client->profiles->getProfileMetricTimeline( 'ProfileId', 'MetricId' ); #Get a profile's ID by its email address $client->profiles->getProfileIdByEmail('someone@mailinator.com');
You can request a privacy-compliant profile deletion given an identifying property
#Request profile deletion by email $client->dataPrivacy->requestProfileDeletion('someone@mailinator.com'); #Request profile deletion by phone number $client->dataPrivacy->requestProfileDeletion('1-234-567-8910', 'phone_number'); #Request profile deletion by person ID $client->dataPrivacy->requestProfileDeletion('abc123', 'person_id');
Exceptions
Klaviyo\Exception\KlaviyoApiException
Thrown when there is an issue making an API request. After you catch this exception, you can use getMessage() and it will return a string containing more details about the issue that occurred.
Klaviyo\Exception\KlaviyoRateLimitException
If a rate limit happens it will throw a Klaviyo\Exception\KlaviyoRateLimitException.
After you catch this exception you can use getMessage() and it will return a JSON encoded array:
{"detail":"Request was throttled. Expected available in 26.0 seconds.","retryAfter":26}
Klaviyo\Exception\KlaviyoAuthenticationException
Thrown when there is an authentication error when making an API request, usually caused by an invalid API key.
Klaviyo\Exception\KlaviyoResourceNotFoundException
Thrown when the system attempts to update a property that doesn't exist. For example, attempting to update a list that doesn't exist on the account.
klaviyo/php-sdk 适用场景与选型建议
klaviyo/php-sdk 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.38M 次下载、GitHub Stars 达 59, 最近一次更新时间为 2026 年 01 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「sdk」 「klaviyo」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 klaviyo/php-sdk 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 klaviyo/php-sdk 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 klaviyo/php-sdk 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Low level but elegant Klaviyo full API wrapper for PHP with asynchronous track event support
Craft Commerce
A plugin for Craft CMS. Grow your ecommerce business with smarter email automations.
A Klaviyo library for PHP written by a normal person
Klaviyo intergration for CraftCMS & Commerce
A simple Symfony bundle for Klaviyo API.
统计信息
- 总下载量: 1.38M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 60
- 点击次数: 17
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: Apache-2.0
- 更新时间: 2026-01-04