PHP library

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

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 Connect. 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',
        'attributes' => array(
            'membership_level' => 'Gold'
        )
    )
);

For more information, see Users.

Track an event

Use the Outbound::track() method to send event data to Connect. 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 Connect as soon as it runs, so make sure it has access to the user and event data.

Provide a device token

If you have a mobile app and want to use push notifications in your Connect campaigns, you must provide the user's APNs (iOS) or GCM (Android) token to Connect. You can provide the token in one of two ways:

  • Send the user's token when you identify the user, using the apns or gcm arguments in the Outbound::identify() method. See Identify a user above.

  • Use the Outbound::register_token() method, which takes the following arguments:

Outbound::register_token(
    Outbound::GCM,
    '4512345',
    'device token'
);

The first argument must be either Outbound::APNS or Outbound::GCM.

Disable a device token

Use the Outbound::disable_token() method if you no longer want to send notifications to the user's device. The method takes the following arguments:

Outbound::disable_token(
    Outbound::GCM,
    '4512345',
    'device token'
);

The first argument must be either Outbound::APNS or Outbound::GCM.

To enable the token again, specify it again in the Outbound::identify() or Outbound::register_token() method.

If you use register_token() and disable_token(), Connect recommends not sending any tokens in identify(). This lets you more easily control the state of your tokens.

Alias two users

Use the Outbound::alias() method to alias two users in Connect. The method takes the following positional arguments:

  • a string containing the user id
  • a string containing the previous user id
Example
Outbound::alias(
    '4512345',
    '0101010'
);

For more information on, see Aliasing Users.