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

2023-10-30php开发问题
2

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

The End

相关推荐

PHP实现DeepL翻译API调用
DeepL的翻译效果还是很强大的,如果我们要用php实现DeepL翻译调用,该怎么办呢?以下是代码示例,希望能够帮到需要的朋友。 在这里需要注意,这个DeepL的账户和api申请比较难,不支持中国大陆申请,需要拥有香港或者海外信用卡才行,没账号的话,目前某宝可以...
2025-08-20 php开发问题
168

PHP通过phpspreadsheet导入Excel日期数据处理方法
PHP通过phpspreadsheet导入Excel日期,导入系统后,全部变为了4开头的几位数字,这是为什么呢?原因很简单,将Excel的时间设置问文本,我们就能看到该日期本来的数值,上图对应的数值为: 要怎么解决呢?进行数据转换就行,这里可以封装方法,或者用第三方的...
2024-10-23 php开发问题
287

mediatemple - 无法使用 codeigniter 发送电子邮件
mediatemple - can#39;t send email using codeigniter(mediatemple - 无法使用 codeigniter 发送电子邮件)...
2024-08-23 php开发问题
11

Laravel Gmail 配置错误
Laravel Gmail Configuration Error(Laravel Gmail 配置错误)...
2024-08-23 php开发问题
16

将 PHPMailer 用于 SMTP 的问题
Problem with using PHPMailer for SMTP(将 PHPMailer 用于 SMTP 的问题)...
2024-08-23 php开发问题
4

关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题
Issue on how to setup SMTP using PHPMailer in GoDaddy server(关于如何在 GoDaddy 服务器中使用 PHPMailer 设置 SMTP 的问题)...
2024-08-23 php开发问题
17