https://github.com/stape-io/stape-sgtm-php
Stape sGTM PHP SDK
https://github.com/stape-io/stape-sgtm-php
gtm gtm-server-side php sdk sdk-php stape
Last synced: 7 months ago
JSON representation
Stape sGTM PHP SDK
- Host: GitHub
- URL: https://github.com/stape-io/stape-sgtm-php
- Owner: stape-io
- License: apache-2.0
- Created: 2023-09-07T13:51:23.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-07-07T10:03:21.000Z (over 1 year ago)
- Last Synced: 2025-04-05T17:01:48.460Z (7 months ago)
- Topics: gtm, gtm-server-side, php, sdk, sdk-php, stape
- Language: PHP
- Homepage: https://stape.io
- Size: 30.3 KB
- Stars: 4
- Watchers: 6
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Stape sGTM PHP SDK
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:
```php
use Stape\Sgtm\StapeSGTM;
$sgtm = StapeSGTM::create('https://gtm.example.com', '/data');
```
| Variable | Description |
|------------------|-------------------------|
| $gtmServerDomain | Server host |
| $requestPath | Request processing path |
### Sending Event Data
```php
$sgtm->sendEventData(<$eventName>, <$eventData>);
```
| Variable | Description |
|------------|-----------------------------------------|
| $eventName | Event name |
| $eventData | Array of options for forming event data |
**$eventData**
```php
$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
```php
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));
```