PHP code example of 365tf / datarangers
1. Go to this page and download the library: Download 365tf/datarangers library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
365tf / datarangers example snippets
# 私有化部署场景 logagent模式
CollectorConfig::init_datarangers_collector([
"domain" => "http://domain",
"save" => true,
"headers" => [
"Host" => "host",
"Content-Type" => "application/json"
],
"http_timeout"=> 10000
]);
# 私有化部署场景 http 模式,Host 必须配置,Host 没有http://,https://
CollectorConfig::init_datarangers_collector([
"domain" => "https://xxxx",
"save" => false,
"headers" => [
"Host" => "xxxx",
"Content-Type" => "application/json"
],
"http_timeout"=> 10000
]);
# saas 云上环境
CollectorConfig::init_datarangers_collector([
"domain" => "https://xxxx",
"save" => false,
"headers" => [
"Content-Type" => "application/json"
],
"app_keys" => [
1001 => getenv("APP_KEY")
],
"openapi" => [
"domain" => "https://xxxx",
"ak" => getenv("OPENAPI_AK"),
"sk" => getenv("OPENAPI_SK")
],
"http_timeout"=> 10000
]);
$rc = new AppEventCollector();
$rc->sendEvent("uuid16980", 1001, null, [ProfileMethod::SET, "php_event"],
[["php_name" => "php", "php_version" => "5.6"], ["php_name" => "php", "php_version" => "5.6"]]);
$rc->profileSet("uuid16980", 1001,["php_name" => "php", "php_version" => "5.6"]);
$rc->profileSetOnce("uuid16980", 1001,["php_name" => "php", "php_version" => "5.6"]);
$rc->profileIncrement("uuid16980", 1001,["count" => 6]);
$rc->profileAppend("uuid16980", 1001,["php_arr" => ["index1","index2"]]);
# set item properties
$rc->itemIdSet(getenv("APP_ID"), "book", "book3", ["author" => "吴承恩", "name" => "西游记", "price" => 59.90, "category" => 1]);
$rc->itemIdSet(getenv("APP_ID"), "book", "book4", ["author" => "Guanzhong Luo", "name" => "SanGuoYanYi", "price" => 69.90, "category" => 1]);
# 在事件中上报item
$rc->sendEvent("test-uuidsdk1", getenv("APP_ID"), null, "php_single_event_with_item",
["php_name" => "php", "php_version" => "5.6"],
[["item_name" => "book", "item_id" => "book3"], ["item_name" => "book", "item_id" => "book4"]]
);