keenlabs / KeenClient-PHP

Official PHP client for the Keen IO API. Build analytics features directly into your PHP apps.
https://keen.io/docs
MIT License
133 stars 57 forks source link

Example to send Geo data? #59

Closed joetsuihk closed 10 years ago

joetsuihk commented 10 years ago

Is this the correct method to send coordinates?

     $this->keenio->addEvent('checkin', array(
        'checkin' => array(
          'shop_id' => $shop_id,
          'user_id' => $user_id,
        ),
        'shop' => $shop,
        'keen' => array('location' => array(
          'coordinates' => array($this->input->post('lng'), $this->input->post('lat'))
        ))
      ));
k-k commented 10 years ago

@joetsuihk - that looks correct. is it not working as expected?

joetsuihk commented 10 years ago
Fatal error: Uncaught exception 'Guzzle\Http\Exception\ClientErrorResponseException' with message 'Client error response [status code] 400 [reason phrase] Bad Request [url] https://api.keen.io/3.0/projects/xxxxxx/events/checkin

This is the error I got.

k-k commented 10 years ago

Have you double checked that the variables you're passing in are valid / correct?

I used your example to add an event with Geo and it succeeded.

$client->addEvent('foo', array(
    'checkin' => array(
      'shop_id' => 123,
      'user_id' => 456,
    ),
    'shop' => 'Some Shop',
    'keen' => array('location' => array(
      'coordinates' => array(-88.21337, 40.11041)
    ))
));

I see this in my collection in Keen:

{
    "shop": "Some Shop",
    "keen": {
        "timestamp": "2014-08-14T04:09:30.420Z",
        "created_at": "2014-08-14T04:09:30.420Z",
        "id": "53ec367a05cd662ff0dc5514",
        "location": {
            "coordinates": [
                -88.21337,
                40.11041
            ]
        }
    },
    "checkin": {
        "shop_id": 123,
        "user_id": 456
    }
} 
joetsuihk commented 10 years ago

Thanks! data type

     $this->keenio->addEvent('checkin', array(
        'checkin' => array(
          'shop_id' => $shop_id,
          'user_id' => $user_id,
        ),
        'shop' => $shop,
        'keen' => array('location' => array(
          'coordinates' => array((double)$this->input->post('lng'), (double)$this->input->post('lat'))
        ))
      ));