stape / stape-sgtm-php
Stape sGTM PHP SDK
Installs: 6 987
Dependents: 0
Suggesters: 0
Security: 0
Stars: 3
Watchers: 5
Forks: 2
Open Issues: 0
pkg:composer/stape/stape-sgtm-php
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: 2025-11-07 12:49:37 UTC
README
A PHP SDK to send tracking events to server-side GTM containers. Works in conjunction with Data Client.
Getting Started
Configuration
Fill in the basic parameters:
use Stape\Sgtm\StapeSGTM; $sgtm = StapeSGTM::create('https://gtm.example.com', '/data');
| Variable | Description |
|---|---|
| $gtmServerDomain | Server host |
| $requestPath | Request processing path |
Sending Event Data
$sgtm->sendEventData(<$eventName>, <$eventData>);
| Variable | Description |
|---|---|
| $eventName | Event name |
| $eventData | Array of options for forming event data |
$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', ], ], ];
Transforms
| Option | Description |
|---|---|
| trim | Removes whitespace from the beginning and end of the value |
| base64 | Encodes the string in Base64 format |
| md5 | Encodes the string in MD5 format |
| sha256base64 | Encodes the string in SHA256 Base64 format |
| sha256hex | Encodes the string in SHA256 HEX format |
Full Example
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));