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

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

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