嘿,如何从 laravel 中的 klaviyo php-sdk 收集 Laravel 中的短信同意 [英] Hey, How to collect sms Consent in laravel from klaviyo php-sdk in laravel

查看:31
本文介绍了嘿,如何从 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 Klaviyo\Klaviyo as Klaviyo;
use Klaviyo\Model\EventModel as KlaviyoEvent;
use Klaviyo\Model\ProfileModel 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 中的短信同意的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆