engageso/engage-php

Engage(http://engage.so/)的PHP SDK

1.2.0 2023-08-30 11:21 UTC

This package is not auto-updated.

Last update: 2024-09-25 16:29:39 UTC


README

Engage PHP SDK 允许您捕获网站上的用户属性和事件。您可以在 Engage 上使用这些信息创建用户细分,进行数据分析、广播消息和自动化消息。

入门

创建 Engage 账户 以获取您的API密钥

安装

composer require "engageso/engage-php"

配置

使用您的公钥和私钥初始化SDK。您的密钥可在 Engage 控制台的设置页面找到。

$engage = new \Engage\EngageClient($_SERVER['pub_key'], $_SERVER['pri_key']);

识别用户

您只需要一个唯一标识符来代表您平台上用户,以便在 Engage 上跟踪其事件和属性。为了将这些跟踪的属性和事件与适当的配置文件相关联,您可以向 Engage 发送唯一标识符和其他属性。您可能只需在用户注册时为此用户执行此操作一次。

$engage->users->identify([
  'id' => 'u13345',
  'email' => 'dan@mail.app',
  'created_at' => '2020-05-30T09:30:10Z'
]);

id 代表您平台上的用户唯一标识符。它是唯一必需的参数。您可以发送任何其他您想要的属性,例如 ageplan。以下是我们内部在用户配置文件中使用的标准属性

  • first_name
  • last_name
  • email
  • is_account(如果用户是账户或客户)
  • number(带国际拨打电话号码,不带+号)
  • created_at(代表用户在您的平台上的注册时间。如果不添加,Engage 将它设置为当前时间戳。)

将用户识别为 账户

$engage->users->identify([
  'id' => 'u13345',
  'is_account' => true,
  'email' => 'hello@mail.app',
  'created_at' => '2020-05-30T09:30:10Z'
]);

将客户转换为账户

$engage->users->convertToAccount('u13345');

将账户转换为客户

$engage->users->convertToCustomer('u15645');

更新/添加用户属性

如果您需要添加新属性或更新现有属性,您可以使用 addAttribute 方法。

$engage->users->addAttribute($userId, [
  'first_name' => 'Dan',
  'plan' => 'Premium'
]);

(您也可以使用 identify 来更新或添加新属性。)

跟踪用户事件和行为

您可以通过几种方式跟踪用户事件和行为。

跟踪无值的事件

$engage->users->track($userId, 'Delinquent');

跟踪有值的事件

$engage->users->track($userId, [
  'event' => 'New badge',
  'value' => 'gold',
  'timestamp' => '2020-05-30T09:30:10Z'
]);

event 是您想要跟踪的事件。 value 是事件的值。这可以是一个字符串、数字或布尔值。有一个可选的 timestamp 参数。如果不包括,Engage 将使用当前时间戳。时间戳值必须是有效的日期时间字符串。

如果您需要跟踪与事件相关的更多属性,您可以这样跟踪

$engage->users->track($userId, [
  'event' => 'Add to cart',
  'properties' => [
    'product' => 'T123',
    'currency' => 'USD',
    'amount' => 12.99
  ]
]);

将客户添加到账户中

$engage->users->addToAccount($userId, $accountId, $role);

角色是可选的。

更新账户角色

$engage->users->changeAccountRole($userId, $accountId, $newRole);

从账户中删除客户

$engage->users->removeFromAccount($userId, $accountId);

许可

MIT