Connect PHP SDK
, (*1)
, (*2)
The Connect PHP SDK allows you to push events to Connect from PHP., (*3)
If you don’t already have a Connect account, sign up here - it’s free!, (*4)
Installation
The easiest way to install the Connect SDK is to use Composer., (*5)
Add connect/connect-client
as a dependency and run composer update., (*6)
"require": {
…
"connect/connect-client" : "0.*"
…
}
Usage
Initializing a client
use Connect\Connect;
Connect::initialize('your-project-id', 'your-push-api-key');
Pushing events
Once you have initialized Connect, you can push events easily:, (*7)
$purchase = [
'customer' => [
'firstName' => 'Tom',
'lastName' => 'Smith'
],
'product' => '12 red roses',
'purchasePrice' => 34.95
];
Connect::push('purchases', $purchase);
You can also push events in batches:, (*8)
$batch = [
'purchases' => [
[
'customer' => [
'firstName' => 'Tom',
'lastName' => 'Smith'
],
'product' => '12 red roses',
'purchasePrice' => 34.95
],
[
'customer' => [
'firstName' => 'Fred',
'lastName' => 'Jones'
],
'product' => '12 pink roses',
'purchasePrice' => 38.95
]
]
];
Connect::push($batch);
Generating filtered keys
To generate a filtered key, (*9)
$masterKey = 'YOUR_MASTER_KEY';
$keyDefinition = [
'filters' => [
'type' => 'cycling'
],
'canQuery' => True,
'canPush' => True
];
$filteredKey = Connect::generateFilteredKey($keyDefinition, $masterKey);
print $filteredKey;
Exception handling
When pushing events, exceptions could be thrown, so you should either ignore or handle those exceptions gracefully., (*10)
Currently, the following exception could be thrown when pushing events:, (*11)
-
InvalidEventException
- the event being pushed is invalid (e.g. invalid event properties)
License
The SDK is released under the MIT license., (*12)
Contributing
We love open source and welcome pull requests and issues from the community!, (*13)