jobinja/threads-io-php-plug

将 Threads.io 连接到您的 PHP 应用程序,并开始收集用户的事件数据。

v1.0.1 2016-02-08 08:02 UTC

This package is not auto-updated.

Last update: 2024-09-20 10:12:29 UTC


README

Scrutinizer Code Quality Build Status Coverage Status

Jobinja 的 Threads.io PHP 插件

这是什么?

该项目是一个 PHP 连接器,用于连接到 Threads.io,最初是从 wabel/threads-io-php-plug 分支出来的。使用此插件来识别用户、跟踪事件和页面访问或从您的 Threads.io 账户中删除它们。初始化

以下是一个基本示例,说明如何使用 Wabel 的 Threads.io PHP 插件

use \Jobinja\ThreadsIo\ThreadsIoClient;
use \Jobinja\ThreadsIo\ThreadsIoService;

// The ThreadsIoClient class is the low level class used to make the API calls.
// It takes your eventKey in parameter, which is provided to you by Threads.io
$client = new ThreadsIoClient(YOUR_EVENT_KEY);

// The ThreadsIoService class is the high level class that you will use with the Entities to make your API Calls
// It takes your fresh new ThreadsIoClient object in argument to be instantiate
$service = new ThreadsIoService($client);

该包的两个主要组件是 ThreadsIoClientThreadsIoService

ThreadsIoClient 是 Threads.io API 的程序实现。它确保数据以 API 期望的格式发送。 ThreadsIoService 是主要的类实例化和使用。它的目的是使用包的实体系统,这意味着轻松操作 UsersEventPage 对象。每个调用方法都期望一个实现 ThreadableInterface 或该包提供的实体之一的对象。

接口和实体

如前所述,ThreadsIoService 操作实体。用户实体、事件实体或页面实体是您的 PHP 应用程序中现有类的实例化,分别实现了 UserThreadableInterfaceEventThreadableInterfacePageThreadableInterface。例如,用于在应用程序中操作用户的 Member 类是实现 UserThreadable 接口的好候选者。如果您没有可以实施 ThreadableInterfaces 的类,您可以手动实例化该包中提供的 Wabel\Entities(用户、事件或页面)之一。

use \Jobinja\ThreadsIo\Entities\User;
use \Jobinja\ThreadsIo\Entities\Event;
use \Jobinja\ThreadsIo\Entities\Page;

// Whether you retrieve an object implementing the UserThreadableInterface from your DB...
$yourUser = $dao->getMemberById(2103);

// ...or that you create one using the provided entity class User...
$threadsIoUser = new User("ID254632", [
    "name" => "Jesus Christ",
    "company" => "Christian Church",
    "date_of_birth" => "24/12/0001",
]);

...

// ... you'll be able to use them both with the ThreadsIoService
$service->identify($yourUser);
$service->identify($threadsIoUser);

如何使用 ThreadsIoService

在版本 1.0.0 中,我们引入了基本函数 "identify"、"track"、"page" 和 "remove" 的首次使用。以下是对该服务的简单使用示例

use \Jobinja\ThreadsIo\Entities\User;
use \Jobinja\ThreadsIo\Entities\Event;
use \Jobinja\ThreadsIo\Entities\Page;
use \Jobinja\ThreadsIo\ThreadsIoClient;
use \Jobinja\ThreadsIo\ThreadsIoService;

// Instantiate an object that implements one of the Wabel\ThreadsIo\Interfaces
// (one of the provided classes in this case)
$user = new User("4815162342", [
     "name" => "Hugo Reyes",
     "status" => "Lost",
     "other" => "Lottery winner"
 ]);

$event = new Event("New Lost Person Report", [
     "plane" => "Oceanic 815",
     "crash_location" => "Pacific Ocean"
 ]);

$page = new Page("New plane crash: Oceanic 815 on fire in the Pacific Ocean", [
     "url" => "http://www.bignews.com/New-plane-crash-Oceanic-815-on-fire-in-the-Pacific-Ocean",
     "referer" => "http://www.bignews.com",
     "time_spent_on_page" => "18s"
 ]);

// Then grab or create a ThreadsIoService object
$client = new ThreadsIoClient($eventKey);
$service = new ThreadsIoService($client);

// Your now able to :

// Identify a user
$service->identify($user);

// Track an event
$service->track($user, $event);

// Track a page view
$service->page($user, $page);

// Remove a user
$service->remove($user);

待办功能

  • 添加在 PHP 关闭事件上发送请求的能力。
  • 添加使用 Guzzle6 的异步请求发送多个异步请求的能力。

关于 Threads.io

Threads.io 提供了一种基于用户活动和账户管理员设置的工作流程规则发送 "自动行为驱动电子邮件" 的服务。您可以在这里查看原始 API。如果您注意到任何 API 升级,请随时提交任何拉取请求。

关于 Jobinja

Jobinja 是一个在线求职和人力资源平台。

关于 Wabel

Wabel 是欧洲食品行业的在线市场。在我们努力将我们的网络平台与更多的网络服务集成的过程中,我们(Wabel 的开发团队!)很高兴与 Threads.io 的社区分享我们的工作。