嘿,如何从 laravel 中的 klaviyo php-sdk 收集 laravel 中的短信同意

2023-12-27

嘿伙计们,有谁知道如何在 klaviyo 中添加短信内容吗?laravel 中的这个包。 https://github.com/klaviyo/php-klaviyo#or-just-add-a-property-to-someone

基本上,我添加了这段代码,我可以在其中添加配置文件并看到用户电子邮件旁边的绿色勾号,但对于短信,它不会出现在那里。在阅读了其他人面临的一些类似问题后,我发现我们需要 API 的订阅端点来添加短信的同意,但我仍然找不到使用这个包来做到这一点的方法。任何帮助和建议将不胜感激。

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' => "[email protected] /cdn-cgi/l/email-protection",
                        '$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 内提交同意的捕获表单,然后该表单将使用适当的同意数据来订阅它们。您必须明确要求both电子邮件和短信同意。

$client = new Klaviyo('Your_private_key', 'public key');

$customer_properties =  [
    '$email' => "[email protected] /cdn-cgi/l/email-protection",
    '$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));

这是相对的伪代码,但目标很明确:确定他们是否允许both短信和电子邮件同意。如果是这样,我们将添加他们的同意属性。

将同意数据添加到该列表后,您可以根据客户的选择安全地向他们发送短信和/或电子邮件。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

嘿,如何从 laravel 中的 klaviyo php-sdk 收集 laravel 中的短信同意 的相关文章