stape / stape-sgtm-php
Stape sGTM PHP SDK
1.0.0
2024-07-07 10:00 UTC
Requires
- php: >=8.0
- symfony/http-client: ^7.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^10.0
This package is auto-updated.
Last update: 2024-09-07 10:21:32 UTC
README
一个用于将跟踪事件发送到服务器端 GTM 容器的 PHP SDK。与数据客户端协同工作。
入门
配置
填写基本参数
use Stape\Sgtm\StapeSGTM; $sgtm = StapeSGTM::create('https://gtm.example.com', '/data');
发送事件数据
$sgtm->sendEventData(<$eventName>, <$eventData>);
$eventData
$eventData = [ 'page_hostname' => 'Stape', 'page_location' => 'http://stape.io', 'page_path' => '/', 'user_data' => [ 'sha256_email_address' => Transforms::sha256hex('jhonn@doe.com'), 'address' => [ 'first_name' => 'Jhon', ], ], ];
转换
完整示例
namespace Stape\Sgtm\Example; use Stape\Sgtm\StapeSGTM; use Stape\Sgtm\Transforms; require_once __DIR__ . '/../vendor/autoload.php'; $start = StapeSGTM::create('https://gtm.stape.io', '/data?dhjdf=123'); $eventData = [ 'client_id' => '123456', 'currency' => 'USD', 'ip_override' => '79.144.123.69', 'language' => 'en', 'page_encoding' => 'UTF-8', 'page_hostname' => 'Stape', 'page_location' => 'http://stape.io', 'page_path' => '/', 'user_data' => [ 'sha256_email_address' => Transforms::sha256hex('jhonn@doe.com'), 'phone_number' => '123456769', 'address' => [ 'first_name' => 'Jhon', ], ], ]; var_dump($start->sendEventData('page_view', $eventData));