---
description: PHP SDK
---

# PHP

PHP client for interacting with the Evntaly event tracking platform. provides developers with a straightforward interface to initialize the SDK, track events, identify users, manage tracking states.

{% embed url="https://github.com/Evntaly/evntaly-php" %}

## Installation

Install the Evntaly PHP SDK:

```php
composer require evntaly/evntaly-php
```

## Initialization

Initialize the SDK with your **Developer Secret** and **Project Token -** Check [Here](https://evntaly.gitbook.io/evntaly/getting-started#create-project)

```php
use Evntaly\EvntalySDK;

$developerSecret = 'YOUR_DEVELOPER_SECRET';
$projectToken = 'YOUR_PROJECT_TOKEN';

$sdk = new EvntalySDK($developerSecret, $projectToken);
```

## Tracking Events

To track an event, use the `track` method with an associative array containing the event details.

```php
$response = $sdk->track([
    "title" => "Payment Received",
    "description" => "User completed a purchase successfully",
    "message" => "Order #12345 confirmed for user.",
    "data" => [
        "user_id" => "usr_67890",
        "order_id" => "12345",
        "amount" => 99.99,
        "currency" => "USD",
        "payment_method" => "credit_card",
        "timestamp" => date('c'),
        "referrer" => "social_media",
        "email_verified" => true
    ],
    "tags" => ["purchase", "payment", "usd", "checkout-v2"],
    "notify" => true,
    "icon" => "💰",
    "apply_rule_only" => false,
    "user" => ["id" => "usr_0f6934fd-99c0-41ca-84f4"],
    "type" => "Transaction",
    "sessionID" => "sid_20750ebc-dabf-4fd4-9498",
    "feature" => "Checkout",
    "topic" => "@Sales"
]);
```

## User Identification

To identify user details, use the `identifyUser` method. This helps link events to specific users and enriches your analytics.

```php
$response = $sdk->identifyUser([
    "id" => "usr_0f6934fd-99c0-41ca-84f4",
    "email" => "john.doe@example.com",
    "full_name" => "Johnathan Doe",
    "organization" => "ExampleCorp Inc.",
    "data" => [
        "username" => "JohnD",
        "location" => "New York, USA",
        "plan_type" => "Premium",
        "signup_date" => "2024-01-15T10:00:00Z",
        "timezone" => "America/New_York"
    ]
]);

```

## Enabling and Disabling Tracking

You can globally enable or disable event tracking for the current SDK instance. This might be useful for development/testing or respecting user consent.

```php
// Disable tracking - subsequent track/identify calls will be ignored
$sdk->disableTracking();

// Re-enable tracking
$sdk->enableTracking();
```

## Best Practices <a href="#best-practices" id="best-practices"></a>

* **Initialize early:** Always initialize the SDK as early as possible.
* **Avoid sensitive data:** Do not pass sensitive personal data directly to the SDK.
* **Monitor API limits:** Regularly check API limits to avoid missing critical events.

## Troubleshooting <a href="#troubleshooting" id="troubleshooting"></a>

* **Events not appearing:** Check if the SDK is initialized correctly and the API tokens are valid.
* **Network errors:** Ensure your network allows requests to `https://evntaly.com`.

***

## Support <a href="#support" id="support"></a>

For additional help, contact support at **support@evntaly.com**.



## ✨ **Open-source community Achievements**

**Huge shout-out and thank you for** [**Mohamed Kamal** ](https://github.com/Mohamed-Kamal-Ayad)**who developed this SDK and it has been added, reviewed and tested by the Evntaly team.**
