2017 © Pedro Peláez
 

library keenio

A convenient wrapper around the Keen.io API for Laravel

image

sitruc/keenio

A convenient wrapper around the Keen.io API for Laravel

  • Wednesday, May 2, 2018
  • by cthorne
  • Repository
  • 2 Watchers
  • 1 Stars
  • 715 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 12 Versions
  • 5 % Grown

The README.md

Latest Version Software License Total Downloads, (*1)

A convenient wrapper around the Keen.io PHP SDK for Laravel

Using this package you can send events to keen.io in laravel elegance. Here are a few examples from basic to elegant., (*2)

The most basic example, using the facade which accepts both a KeenEvent or the name and data directly., (*3)

use KeenIO;

KeenIO::addEvent('New Event', ['key' => 'value']);

Or pass a KeenEvent, (*4)

use KeenIO;
use Sitruc\KeenIO\KeenEvent

$event = new KeenEvent('New Event', ['key' => 'value']);

KeenIO::addEvent($event);

If you prefer, you can send the event directly., (*5)


use Sitruc\KeenIO\KeenEvent; $event = new KeenEvent('New Event', ['key' => 'value']); $event->send();

Queuing events., (*6)


use Sitruc\KeenIO\KeenEvent; $event = new KeenEvent('New Queued Event', ['key' => 'value']); $event->queued()->send();

Use keen.io's data enrichment., (*7)


use Sitruc\KeenIO\KeenEvent; $event = new KeenEvent('New Event', ['key' => 'value']); //Enriches keen's default keen.timestamp value into enriched_timestamp $event->enrichDatetime(); $event->enrichDatetime('some.other.timestamp.source', 'new.enriched.location'); $event->send();

Methods are fluent so the above example can become., (*8)


use Sitruc\KeenIO\KeenEvent; $event = new KeenEvent('Keen Event', ['key' => 'value']); $event->enrichDatetime() ->enrichDatetime('some.other.timestamp.source', 'new.enriched.location') ->send();

The following enrichment values are accepted. You can read more about data enrichment, also known as 'Add Ons' in the keen.io documentation, (*9)

public function enrichDatetime($source = 'keen.timestamp', $destination = 'enriched_timestamp')

public function enrichIPAddress($source, $destination = 'ip_geo_info')

public function enrichUserAgent($source, $destination = 'parsed_user_agent')

public function enrichURL($source, $destination)

public function enrichReferrer($referrer_url_input, $page_url_input, $destination)

Subclassing KeenEvent can be even more powerful., (*10)

Behind the scenes this packages uses laravel's dispatch handler. This means you can implement the ShouldQueue interface and dispatch onto specific queues just like you would any other job., (*11)

Here is an example of reporting a registration event on a keenio queue with enriched created_at and upgrade_date. Simple and elegant!, (*12)

<?php

namespace App\Http\Controllers;

use App\KeenEvents\NewRegistration;

class UserController
{
    public function registerUser()
    {
        //Register the user.
        NewRegistration::from($user)->send();
    }
}

```php <?php, (*13)

namespace App\KeenEvents;, (*14)

use Sitruc\KeenIO\KeenEvent; use Illuminate\Bus\Queueable; use Illuminate\Queue\SerializesModels; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue;, (*15)

class NewRegistration extends KeenEvent implements ShouldQueue { use InteractsWithQueue, Queueable, SerializesModels;, (*16)

protected $keenTitle = 'New Registration';

protected $user;

public function __construct($user)
{
    $this->user = $user;

    $this->onQueue('keenio')
         ->enrichDatetime()
         ->enrichDatetime('upgrade_date', 'enriched_upgrade_date');
}

public static function from($user)
{
    return new static($user);
}

public function keenData()
{
    return [
        'account_type' => $this->user->accountType,
        'upgrade_date' => $this->user->upgradeDate->toAtomString(),
    ];
}

}, (*17)


## Install This package can be installed through Composer. ``` bash composer require sitruc/keenio

You must install this service provider., (*18)

// config/app.php
'providers' => [
    ...
    Sitruc\KeenIO\KeenServiceProvider::class,
    ...
];

This package also comes with a facade, which provides an easy way to call the the class., (*19)

// config/app.php
'aliases' => [
    ...
    'KeenIO' => Sitruc\KeenIO\Facades\KeenIO::class,
    ...
];

This package requires a you to add your project_id write_key read_key and enabled to the services config file., (*20)

// config/services.php
<?php
return [
    ...
    'keenio' => [
        'project_id' => env('KEENIO_PROJECT_ID'),
        'write_key'  => env('KEENIO_WRITE_KEY'),
        'read_key'   => env('KEENIO_READ_KEY'),
        'enabled'    => env('KEENIO_ENABLED'),
    ],
    ...
]

the enabled flag is useful if you want to shut off keen reporting in certain environments., (*21)

Testing

Run the tests with:, (*22)

``` bash vendor/bin/phpunit, (*23)

or
```bash
composer test

Security

If you discover any security related issues, please email cthorne@me.com instead of using the issue tracker., (*24)

Credits

License

The MIT License (MIT). Please see License File for more information., (*25)

The Versions

02/05 2018

dev-master

9999999-dev

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

02/05 2018
10/02 2018

v1.0.7

1.0.7.0

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

15/09 2017

v1.0.6

1.0.6.0

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

10/05 2017

v1.0.5

1.0.5.0

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

26/04 2017

dev-add-readme

dev-add-readme

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

25/04 2017

v1.0.4

1.0.4.0

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

24/04 2017

v1.0.3

1.0.3.0

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

24/04 2017

v1.0.2

1.0.2.0

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

24/04 2017

v1.0.1

1.0.1.0

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

24/04 2017

0.1.0

0.1.0.0

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen

24/04 2017

v1.0.0

1.0.0.0

A convenient wrapper around the Keen.io API for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

by Curtis Thorne

keen.io keen keen-io keenio laravel-keen