-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
37 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,20 +5,20 @@ The Keen IO API lets developers build analytics features directly into their app | |
[](https://travis-ci.org/keenlabs/KeenClient-PHP) | ||
|
||
Installation with Composer | ||
------------ | ||
-------------------------- | ||
1. Install composer via via `curl -s http://getcomposer.org/installer | php` (on windows, download | ||
http://getcomposer.org/installer and execute it with PHP) | ||
1. Edit your `composer.json` file with following contents: | ||
2. Edit your `composer.json` file with following contents: | ||
|
||
```json | ||
"require": { | ||
"keen-io/keen-io": "dev-master" | ||
"keen-io/keen-io": "~1.1" | ||
} | ||
``` | ||
3. Run `php composer.phar install` | ||
|
||
Usage | ||
--- | ||
----- | ||
|
||
This client was built using [Guzzle](http://guzzlephp.org/), a PHP HTTP client & framework for building RESTful web service clients. | ||
|
||
|
@@ -35,7 +35,7 @@ For a list of required and available parameters for the different API Endpoints, | |
[API Reference Docs](https://keen.io/docs/api/reference/). | ||
|
||
|
||
####Configuring the Client | ||
#### Configuring the Client | ||
|
||
The factory method accepts an array of configuration settings for the Keen IO Webservice Client. | ||
|
||
|
@@ -52,36 +52,36 @@ that matches that version. That Service Description defines the operations avail | |
|
||
Currently the Keen IO Webservice Client only supports - and automatically defaults - to the current version (`3.0`) of the API. | ||
|
||
######Example | ||
###### Example | ||
```php | ||
use KeenIO\Client\KeenIOClient; | ||
|
||
$client = KeenIOClient::factory([ | ||
'projectId' => $projectId, | ||
'writeKey' => $writeKey, | ||
'readKey' => $readKey | ||
'writeKey' => $writeKey, | ||
'readKey' => $readKey | ||
]); | ||
``` | ||
|
||
####Configuration can be updated to reuse the same Client: | ||
#### Configuration can be updated to reuse the same Client: | ||
You can reconfigure the Keen IO Client configuration options through available getters and setters. You can get and set the following options: | ||
`projectId`, `readKey`, `writeKey`, `masterKey`, & `version`. | ||
|
||
######Example | ||
###### Example | ||
```php | ||
|
||
//Get the current Project Id | ||
$client->getProjectId(); | ||
|
||
//Set a new Project Id | ||
$client->setProjectId( $someNewProjectId ); | ||
$client->setProjectId($someNewProjectId); | ||
|
||
//Get the current Read Key | ||
$client->getReadKey(); | ||
|
||
//Set a new Read Key | ||
$newReadKey = $client->getScopedKey( $masterKey, $filters, $allowed_operations ); | ||
$client->setReadKey( $newReadKey ); | ||
$newReadKey = $client->getScopedKey($masterKey, $filters, $allowedOperations); | ||
$client->setReadKey($newReadKey); | ||
|
||
``` | ||
|
||
|
@@ -90,58 +90,58 @@ Once you've created a `KeenIOClient`, sending events is simple: | |
|
||
######Example | ||
```php | ||
$event = [ 'purchase' => [ 'item' => 'Golden Elephant' ] ]; | ||
$event = ['purchase' => ['item' => 'Golden Elephant']]; | ||
|
||
$client->addEvent( 'purchases', [ 'data' => $event ] ); | ||
$client->addEvent('purchases', ['data' => $event]); | ||
``` | ||
|
||
####Send batched events to Keen | ||
#### Send batched events to Keen | ||
You can upload multiple Events to multiple Event Collections at once! | ||
|
||
In the example below, we will create two new purchase events in the `purchases` event collection and a single | ||
new event in the `sign_ups` event collection. Note that the keys of the `data` array specify the `event_collection` | ||
where those events should be stored. | ||
|
||
######Example | ||
###### Example | ||
```php | ||
$purchases = [ | ||
[ 'purchase' => [ 'item' => 'Golden Elephant' ] ], | ||
[ 'purchase' => [ 'item' => 'Magenta Elephant' ] ] | ||
['purchase' => ['item' => 'Golden Elephant']], | ||
['purchase' => ['item' => 'Magenta Elephant']] | ||
]; | ||
$signUps = [ | ||
[ 'name' => 'foo', 'email' => '[email protected]' ] | ||
['name' => 'foo', 'email' => '[email protected]'] | ||
]; | ||
|
||
$client->addEvents([ 'data' => [ 'purchases' => $purchases, 'sign_ups' => $signUps ] ]); | ||
$client->addEvents(['data' => ['purchases' => $purchases, 'sign_ups' => $signUps]]); | ||
``` | ||
|
||
####Get Analysis on Events | ||
#### Get Analysis on Events | ||
All Analysis Endpoints should be supported. See the [API Reference Docs](https://keen.io/docs/api/reference/) for required parameters. | ||
You can also check the [Service Description](/src/KeenIO/Resources/config/keen-io-3_0.json) for configured API Endpoints. | ||
|
||
Below are a few example calls to some of the Analysis methods available. | ||
|
||
######Example | ||
```php | ||
###### Example | ||
|
||
```php | ||
//Count | ||
$totalPurchases = $client->count( 'purchases' ); | ||
$totalPurchases = $client->count('purchases'); | ||
|
||
//Count Unqiue | ||
$totalItems = $client->countUnique( 'purchases', [ 'target_property' => 'purchase.item' ]); | ||
$totalItems = $client->countUnique('purchases', ['target_property' => 'purchase.item']); | ||
|
||
//Select Unique | ||
$items = $client->selectUnique( 'purchases', [ 'target_property' => 'purchase.item' ]); | ||
$items = $client->selectUnique('purchases', ['target_property' => 'purchase.item']); | ||
|
||
//Multi Analysis | ||
$analyses = [ | ||
'clicks' => [ "analysis_type" => "count" ], | ||
'average price' => [ "analysis_type" => "average", "target_property" => "purchase.price" ] | ||
'clicks' => ['analysis_type' => 'count'], | ||
'average price' => ['analysis_type' => 'average', 'target_property' => 'purchase.price'] | ||
]; | ||
$stats = $client->multiAnalysis( 'purchases', [ 'analyses' => $analyses ]); | ||
$stats = $client->multiAnalysis('purchases', ['analyses' => $analyses]); | ||
``` | ||
|
||
###Create a Scoped Key | ||
### Create a Scoped Key | ||
|
||
Scoped keys allow you to secure the requests to the API Endpoints and are especially useful when you are providing | ||
access to multiple clients or applications. You should read the Keen IO docs concerning [Scoped Keys](https://keen.io/docs/security/#scoped-key) | ||
|
@@ -150,14 +150,14 @@ for more details. | |
######Example | ||
```php | ||
$filter = [ | ||
'property_name' => 'user_id', | ||
'operator' => 'eq', | ||
'property_value' => '123' | ||
'property_name' => 'user_id', | ||
'operator' => 'eq', | ||
'property_value' => '123' | ||
]; | ||
|
||
$filters = [ $filter ]; | ||
$allowed_operations = [ 'read' ]; | ||
$filters = [$filter]; | ||
$allowed_operations = ['read']; | ||
|
||
$scopedKey = $client->getScopedKey( $masterKey, $filters, $allowed_operations ); | ||
$scopedKey = $client->getScopedKey($masterKey, $filters, $allowedOperations); | ||
``` | ||
|