PHP library

You can use the Outbound PHP library with your web application to send user and event data to Outbound.

This document covers the following topics:

You can also examine the library's source code on Github.

Install the Outbound library

Install the library using one the following options.

Github
git clone https://github.com/outboundio/lib-php.git
Composer
"require": {
    ...
    "outbound/outbound-php" : "2.*"
    ...
}

For more information, see the Composer website.

Include the library in your project

require_once('lib/outbound.php');
Outbound::init('PRIVATE_KEY');

For more information on the private key, see Authentication in the introduction.

Identify a user

Use the Outbound::identify() method to send user data to Outbound. The method takes the following positional arguments:

  • a string containing the user id
  • (optional) an associative array containing the user information. Only the keys in the example below are supported. All are optional
  • (optional) an associative array containing custom user attributes. See Attributes in the Users documentation
Example
Outbound::identify(
    '4512345',
    array(
        'first_name' => 'Jane',
        'last_name' => 'Doe',
        'email => 'jdoe@example.com',
        'phone_number' => '+1 555-123-4567',
        'apns' => array('ios device token'),
        'gcm' => array('android device token'),
        'previous_id' => 'anonymous_user_123',
        'group_id' => 'group_identifier',
         'group_attributes' => array(
             'some_group_attribute_name' => 'Loren Ipsum'
         )
    ),
    array(
        'membership_level' => 'Gold'
    )
);

For more information, see Users.

Track an event

Use the Outbound::track() method to send event data to Outbound. The method takes the following positional arguments:

  • a string containing the user id
  • a string containing the event name
  • (optional) an associative array containing custom event properties. See Properties attribute in the Events documentation
Example
Outbound::track(
    '4512345',
    'renewMemberhsip',
    array(
        'membership_renewalDate' => '2018-06-12'
    )
)

For more information, see Events.

The track() method sends the data to Outbound as soon as it runs, so make sure it has access to the user and event data.