moesif / moesifapi-php
将HTTP API请求/响应记录到Moesif
v1.1.10
2020-06-15 02:41 UTC
Requires
- php: >=5.4.0
- ext-curl: *
- ext-json: *
- ext-mbstring: *
- apimatic/jsonmapper: ~1.0.0
- mashape/unirest-php: ~3.0.1
Requires (Dev)
- phpunit/phpunit: 4.8.*
This package is auto-updated.
Last update: 2024-09-23 09:01:40 UTC
README
查看Moesif的开发者文档和PHP API参考以了解更多信息
如何安装
通过Composer安装
composer require moesif/moesifapi-php
如何使用
要使用此SDK,请执行以下操作
-
使用Composer安装依赖项。请参阅“如何构建”部分。
-
确保您已正确配置SDK。请参阅“如何配置”部分。
-
根据您的项目设置,您可能需要在PHP代码中包含Composer的自动加载器,以启用类的自动加载。
require_once "vendor/autoload.php";
-
在您的项目中导入SDK客户端
use Moesif\Sender\MoesifApi;
-
实例化客户端。之后,您现在可以访问Moesif API并调用相应的方法
$client = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]);
您的Moesif应用程序ID可在Moesif门户中找到。注册Moesif账户后,您的Moesif应用程序ID将在入门步骤中显示。
您可以通过登录到Moesif门户,点击右上角菜单,然后点击“安装”来随时找到您的Moesif应用程序ID。
创建单个API事件
use Moesif\Sender\MoesifApi; $reqdate = new DateTime(); $rspdate = new DateTime(); $event= array( "request" => array( "time" => $reqdate->format(DateTime::ISO8601), "uri" => "https://api.acmeinc.com/items/reviews/", "verb" => "PATCH", "api_version" => "1.1.0", "ip_address" => "61.48.220.123", "headers" => array( "Host" => "api.acmeinc.com", "Accept" => "_/_", "Connection" => "Keep-Alive", "User-Agent" => "moesifapi-php/1.1.0", "Content-Type" => "application/json", "Content-Length" => "126", "Accept-Encoding" => "gzip"), "body" => array( "review_id" => 132232, "item_id" => "ewdcpoijc0", "liked" => false ) ), "response" => array( "time" => $rspdate->format(DateTime::ISO8601), "status" => 500, "headers" => array( "Date" => "Tue, 12 June 2020 23:46:49 GMT", "Vary" => "Accept-Encoding", "Pragma" => "no-cache", "Expires" => "-1", "Content-Type" => "application/json; charset=utf-8", "X-Powered-By" => "ARR/3.0", "Cache-Control" => "no-cache", "Arr-Disable-Session-Affinity" => "true"), "body" => array( "item_id" => "13221", "title" => "Red Brown Chair", "description" => "Red brown chair for sale", "price" => 22.23 ) ), "metadata" => array( "foo" => "bar" ), "user_id" => "12345", "company_id" => "67890", "session_token" => "23jdf0owekfmcn4u3qypxg09w4d8ayrcdx8nu2ngs98y18cx98q3yhwmnhcfx43f" ); $apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]); $apiClient->createEvent($event);
更新单个用户
在Moesif中创建或更新用户资料。元数据字段可以是任何客户人口统计信息或其他您想存储的信息。只需要user_id
字段。
use Moesif\Sender\MoesifApi; // Only userId is required. // Campaign object is optional, but useful if you want to track ROI of acquisition channels // See https://www.moesif.com/docs/api#users for campaign schema // metadata can be any custom object $user = array( "user_id" => "12345", "company_id" => "67890", // If set, associate user with a company object "campaign" => array( "utm_source" => "google", "utm_medium" => "cpc", "utm_campaign" => "adwords", "utm_term" => "api+tooling", "utm_content" => "landing" ), "metadata" => array( "email" => "john@acmeinc.com", "first_name" => "John", "last_name" => "Doe", "title" => "Software Engineer", "sales_info" => array( "stage" => "Customer", "lifetime_value" => 24000, "account_owner" => "mary@contoso.com" ) ) ); $apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]); $apiClient->updateUser($user);
批量更新用户
类似于更新用户,但用于在单个批次中更新用户列表。只需要user_id
字段。
use Moesif\Sender\MoesifApi; $userA = array( "user_id" => "12345", "company_id" => "67890", // If set, associate user with a company object "campaign" => array( "utm_source" => "google", "utm_medium" => "cpc", "utm_campaign" => "adwords", "utm_term" => "api+tooling", "utm_content" => "landing" ), "metadata" => array( "email" => "john@acmeinc.com", "first_name" => "John", "last_name" => "Doe", "title" => "Software Engineer", "sales_info" => array( "stage" => "Customer", "lifetime_value" => 24000, "account_owner" => "mary@contoso.com" ) ) ); $userB = array( "user_id" => "1234", "company_id" => "6789", // If set, associate user with a company object "campaign" => array( "utm_source" => "google", "utm_medium" => "cpc", "utm_campaign" => "adwords", "utm_term" => "api+tooling", "utm_content" => "landing" ), "metadata" => array( "email" => "john@acmeinc.com", "first_name" => "John", "last_name" => "Doe", "title" => "Software Engineer", "sales_info" => array( "stage" => "Customer", "lifetime_value" => 24000, "account_owner" => "mary@contoso.com" ) ) ); $users = array($userA, $userB); $apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]); $apiClient->updateUsersBatch($users);
更新单个公司
在Moesif中创建或更新公司资料。元数据字段可以是任何公司人口统计信息或其他您想存储的信息。只需要company_id
字段。
use Moesif\Sender\MoesifApi; // Only companyId is required. // Campaign object is optional, but useful if you want to track ROI of acquisition channels // See https://www.moesif.com/docs/api#update-a-company for campaign schema // metadata can be any custom object $company = array( "company_id" => "67890", "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info "campaign" => array( "utm_source" => "google", "utm_medium" => "cpc", "utm_campaign" => "adwords", "utm_term" => "api+tooling", "utm_content" => "landing" ), "metadata" => array( "org_name" => "Acme, Inc", "plan_name" => "Free", "deal_stage" => "Lead", "mrr" => 24000, "demographics" => array( "alexa_ranking" => 500000, "employee_count" => 47 ) ) ); $apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]); $apiClient->updateCompany($company);
批量更新公司
类似于更新公司,但用于在单个批次中更新公司列表。只需要company_id
字段。
use Moesif\Sender\MoesifApi; $companyA = array( "company_id" => "67890", "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info "campaign" => array( "utm_source" => "google", "utm_medium" => "cpc", "utm_campaign" => "adwords", "utm_term" => "api+tooling", "utm_content" => "landing" ), "metadata" => array( "org_name" => "Acme, Inc", "plan_name" => "Free", "deal_stage" => "Lead", "mrr" => 24000, "demographics" => array( "alexa_ranking" => 500000, "employee_count" => 47 ) ) ); $companyB = array( "company_id" => "6789", "company_domain" => "acmeinc.com", // If domain is set, Moesif will enrich your profiles with publicly available info "campaign" => array( "utm_source" => "google", "utm_medium" => "cpc", "utm_campaign" => "adwords", "utm_term" => "api+tooling", "utm_content" => "landing" ), "metadata" => array( "org_name" => "Acme, Inc", "plan_name" => "Free", "deal_stage" => "Lead", "mrr" => 24000, "demographics" => array( "alexa_ranking" => 500000, "employee_count" => 47 ) ) ); $companies = array($companyA, $companyB); $apiClient = MoesifApi::getInstance("Your Moesif Application Id", ['fork'=>true, 'debug'=>false]); $apiClient->updateCompaniesBatch($companies);