https://github.com/userlist/userlist-php
PHP wrapper for the Userlist Push API
https://github.com/userlist/userlist-php
php userlist
Last synced: 10 months ago
JSON representation
PHP wrapper for the Userlist Push API
- Host: GitHub
- URL: https://github.com/userlist/userlist-php
- Owner: userlist
- License: mit
- Created: 2019-02-20T14:46:55.000Z (over 7 years ago)
- Default Branch: main
- Last Pushed: 2025-03-26T12:55:06.000Z (about 1 year ago)
- Last Synced: 2025-08-10T01:54:08.473Z (10 months ago)
- Topics: php, userlist
- Language: PHP
- Homepage: http://userlist.com
- Size: 64.5 KB
- Stars: 0
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# Userlist PHP [](https://github.com/userlist/userlist-php)
This library helps with integrating Userlist into PHP applications.
## Installation
This library can be installed via [Composer](https://getcomposer.org):
```bash
composer require userlist/userlist
```
## Configuration
The only required configuration is the Push API key. You can get your Push API key via the [Push API settings](https://app.userlist.com/settings/push) in your Userlist account.
Configuration values can be set when creating a new push client or via environment variables. The environment takes precedence over values provided during the initialization process.
**Configuration via environment variables**
```bash
USERLIST_PUSH_KEY=401e5c498be718c0a38b7da7f1ce5b409c56132a49246c435ee296e07bf2be39
```
**Configuration during initialization**
```php
$userlist = new \Userlist\Push(['push_key' => '401e5c498be718c0a38b7da7f1ce5b409c56132a49246c435ee296e07bf2be39']);
```
## Usage
Before tracking user or event data, create a new push client. If you configured your push key via environment variables there's nothing to add. Otherwise, see the example above.
```php
$userlist = new \Userlist\Push();
```
### Tracking Users
#### Creating & updating Users
```php
$user = [
'identifier' => 'user-1',
'email' => 'user@example.com',
'properties' => [
'first_name' => 'Jane',
'last_name' => 'Doe'
]
];
$userlist->users->push($user);
$userlist->user($user); // Alias
$userlist->users->create($user); // Alias
```
#### Deleting Users
```php
$userlist->users->delete('user-1');
$userlist->users->delete($user);
```
### Tracking Companies
#### Creating & updating Companies
```php
$company = [
'identifier' => 'company-1',
'name' => 'Example, Inc.',
'properties' => [
'industry' => 'Software Testing'
]
];
$userlist->companies->push($company);
$userlist->company($company); // Alias
$userlist->companies->create($company); // Alias
```
#### Deleting Companies
```php
$userlist->companies->delete('company-1');
$userlist->companies->delete([ 'identifier' => 'company-1' ]);
```
### Tracking Relationships
#### Creating & updating Relationships
```php
$relationship = [
'user' => 'user-1',
'company' => 'company-1',
'properties' => [
'role' => 'admin'
]
];
$userlist->relationships->push($relationship);
$userlist->relationship($relationship); // Alias
$userlist->relationships->create($relationship); // Alias
```
This is equivalent to specifying the relationship on the user model.
```php
$user = [
'identifier' => 'user-1',
'relationships' => [
[
'company' => 'company-1',
'properties' => [
'role' => 'admin'
]
]
],
];
$userlist->users->push($user);
```
It's also equivalent specifying the relationship on the company model.
```php
$company = [
'identifier' => 'company-1',
'relationships' => [
[
'user' => 'user-1',
'properties' => [
'role' => 'admin'
]
]
],
];
$userlist->companies->push($company);
```
#### Deleting Relationships
```php
$relationship = [
'user' => 'user-1',
'company' => 'company-1'
]
$userlist->relationships->delete($relationship);
```
### Tracking Events
```php
$event = [
'name' => 'project_created',
'user' => 'user-1',
'properties' => [
'name' => 'Example Project',
]
];
$userlist->events->push($event);
$userlist->event($event); // Alias
$userlist->events->create($event); // Alias
```
### Sending Transactional Messages
```php
$message = [
'user' => 'user-1',
'template' => 'welcome-email',
'properties' => [
'account_name' => 'Example, Inc.',
'billing_plan' => 'Pro',
]
];
$userlist->messages->push($message);
$userlist->message($message); // Alias
$userlist->messages->create($message); // Alias
```
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/userlist/userlist-php. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
## License
The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
## Code of Conduct
Everyone interacting in the Userlist project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/userlist/userlist-php/blob/master/CODE_OF_CONDUCT.md).
## What is Userlist?
[](https://userlist.com/)
[Userlist](https://userlist.com/) allows you to onboard and engage your SaaS users with targeted behavior-based campaigns using email or in-app messages.
Userlist was started in 2017 as an alternative to bulky enterprise messaging tools. We believe that running SaaS products should be more enjoyable. Learn more [about us](https://userlist.com/about-us/).