Search documentation...

K
ChangelogBook a demoSign up

PHP SDK

The PHP SDK makes it easy to track events from PHP applications.

Installation

The PHP SDK can be installed via Composer:

composer require ht-sdks/events-sdk-php

To initialize the PHP SDK in your application:

use Hightouch\Hightouch;

Hightouch::init('WRITE_KEY', [
  'host' => 'https://us-east-1.hightouch-events.com',
]);

API

Identify

The identify method sends an identify event.

Unlike the Browser SDK, it does not persist the user ID and traits locally, so user IDs must be explicitly added to other events. This is because server side events are usually servicing many different users at once.

Example usage:

Hightouch::identify([
    'userId' => '123',
    'traits' => [
        'location' => 'San Francisco',
    ],
]);

Method parameters:

ParameterTypeDescription
userIdstringThe user's persistent ID
anonymousIdstringThe user's anonymous ID
traitsarrayAdditional traits about the user, such as email and name.
contextarrayOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampintThe UNIX timestamp (seconds) of the message. When backfilling, this can be a time in the past. By default it uses time().

Track

The track method sends a track event.

Example usage:

Hightouch::track([
    'userId' => '123',
    'event' => 'Order Completed',
    'properties' => [
        'total' => 29.99,
    ],
]);

Method parameters:

ParameterTypeDescription
userIdstringThe user's persistent ID
anonymousIdstringThe user's anonymous ID
eventstringThe name of the event.
propertiesarrayAdditional properties about the event, such as product_id.
contextarrayOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampintThe UNIX timestamp (seconds) of the message. When backfilling, this can be a time in the past. By default it uses time().

Page

The page method sends a page event.

Example usage:

Hightouch::page([
    'anonymousId' => 'anonymous-id',
    'name'        => 'events-sdk-php',
    'category'    => 'docs',
    'properties'  => [
        'path' => '/docs/libraries/php/',
    ],
]);

Method parameters:

ParameterTypeDescription
userIdstringThe user's persistent ID
anonymousIdstringThe user's anonymous ID
namestringThe page's name. For example "Getting started"
propertiesarrayAdditional properties about the event, such as url.
contextarrayOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampintThe UNIX timestamp (seconds) of the message. When backfilling, this can be a time in the past. By default it uses time().

Screen

The screen method sends a screen event.

Example usage:

Hightouch::screen([
    'userId'     => '123',
    'name'       => 'Getting started',
    'properties' => [
        'path' => '/getting-started',
    ],
]);

Method parameters:

ParameterTypeDescription
userIdstringThe user's persistent ID
anonymousIdstringThe user's anonymous ID
namestringThe page's name. For example "Getting started"
propertiesarrayAdditional properties about the event, such as url.
contextarrayOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampintThe UNIX timestamp (seconds) of the message. When backfilling, this can be a time in the past. By default it uses time().

Group

The group method sends a group event.

Example usage:

Hightouch::group([
    'userId'  => '123',
    'groupId' => 'G-1',
    'traits'  => [
        'company_location' => 'San Francisco',
    ],
]);

Method parameters:

ParameterTypeDescription
userIdstringThe user's persistent ID
anonymousIdstringThe user's anonymous ID
groupIdstringThe id for the group.
traitsarrayAdditional traits about the group, such as company_name.
contextarrayOverrides to values in the event context. By default, context contains information autocollected by the SDK.
timestampintThe UNIX timestamp (seconds) of the message. When backfilling, this can be a time in the past. By default it uses time().

Flush

The PHP SDK buffers events locally before sending them to Hightouch's servers. This minimizes the number of requests made by the SDK and improves performance.

To force the local buffer to be sent to Hightouch immediately call the flush method. flush should be called when shutting down your app to make sure no events are lost.

Example usage:

Hightouch::flush();

Ready to get started?

Jump right in or a book a demo. Your first destination is always free.

Book a demoSign upBook a demo

Need help?

Our team is relentlessly focused on your success. Don't hesitate to reach out!

Feature requests?

We'd love to hear your suggestions for integrations and other features.

Last updated: Mar 25, 2024

On this page

InstallationAPIIdentifyTrackPageScreenGroupFlush

Was this page helpful?