Hey, How to collect sms Consent in laravel from klaviyo php-sdk in laravel(嘿,如何从 laravel 中的 klaviyo php-sdk 在 laravel 中收集短信同意)
问题描述
大家好,有谁知道如何从 这个包在 laravel 中.
Hey guys does anyone knows the way around to add an SMS content in klaviyo from this package in laravel.
基本上我已经添加了这段代码,我可以在其中添加配置文件并看到用户电子邮件旁边的绿色复选标记,但对于 SMS,它不会出现在那里.在阅读了其他人面临的一些类似问题后,我发现我们需要一个 API 的订阅端点来添加 SMS 的同意,但我仍然找不到使用这个包的方法.任何帮助和建议将不胜感激.
Basically I've added this piece of code where I can add the profile and see that green check next to user's email but for SMS it don't appear there. After reading some similar issues faced by others, I found that we need a subscribe endpoint of API to add consent of SMS, But I still can't find a way to do it with this package. Any help and suggestions would be appreciated.
use KlaviyoKlaviyo as Klaviyo;
use KlaviyoModelEventModel as KlaviyoEvent;
use KlaviyoModelProfileModel as KlaviyoProfile;
class KlaviyoformsController extends Controller
{
public function index()
{
$client = new Klaviyo('Your_private_key', 'public key');
$event =
new KlaviyoEvent(
array(
'event' => 'Lead',
'customer_properties' => array(
'$email' => "someone@mailinator9.com",
'$consent' => ['sms', 'email'],
'sms_consent' => true,
'email_consent' => true,
'$first_name' => "Thomas9",
'$last_name' => "Jefferson",
'$phone_number' => "1234567890"
),
'properties' => array()
)
);
$client->publicAPI->track( $event, true );
return view('klaviyoform::dashboard.index');
}
}
```
推荐答案
你必须在 Laravel 中有一个用于同意提交的捕获表单,然后它将使用适当的同意数据订阅它们.您必须明确征求电子邮件和短信同意.
You must have a capture form for the consent submission within Laravel that will then subscribe them with the appropriate consent data. You must explicitly ask for both email and sms consent.
$client = new Klaviyo('Your_private_key', 'public key');
$customer_properties = [
'$email' => "someone@mailinator9.com",
'$first_name' => "Thomas9",
'$last_name' => "Jefferson",
'phone_number' => "1234567890"
];
$consents = [];
if (request()->get('sms_consent', false)) {
$consents['sms_consent'] = true;
}
if (request()->get('email_consent', false)) {
$consents['email_consent'] = true;
}
foreach ($consents as $type => $consented) {
if ($consented) {
$consents['$consent'] = array_merge(
data_get($consents, '$consent', []),
[explode('_', $type)[0]] //e.g. sms, email
);
}
}
$client->lists->addSubscribersToList('ListId', array_merge($customer_properties, $consents));
这是相对的伪代码,但目标很明确:确定他们是否允许同时短信和电子邮件同意.如果是这样,我们将添加他们的同意属性.
This is relative psuedo code but the goal is clear: Determine if they allowed both sms and email consent. If so, we'll add their consent properties.
将同意数据添加到该列表后,您可以根据客户的选择安全地向他们发送短信和/或电子邮件.
Once the consent data has been added to that list you can safely send them sms and/or email based on the customers choice.
这篇关于嘿,如何从 laravel 中的 klaviyo php-sdk 在 laravel 中收集短信同意的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:嘿,如何从 laravel 中的 klaviyo php-sdk 在 laravel 中收集短信同意
基础教程推荐
- 在 PHP 中强制下载文件 - 在 Joomla 框架内 2022-01-01
- 通过 PHP SoapClient 请求发送原始 XML 2021-01-01
- 超薄框架REST服务两次获得输出 2022-01-01
- XAMPP 服务器不加载 CSS 文件 2022-01-01
- WooCommerce 中选定产品类别的自定义产品价格后缀 2021-01-01
- Libpuzzle 索引数百万张图片? 2022-01-01
- 在多维数组中查找最大值 2021-01-01
- 如何在 PHP 中的请求之间持久化对象 2022-01-01
- mysqli_insert_id 是否有可能在高流量应用程序中返回 2021-01-01
- 在 Woocommerce 中根据运输方式和付款方式添加费用 2021-01-01