定制 sitruc/keenio 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

sitruc/keenio

Composer 安装命令:

composer require sitruc/keenio

包简介

A convenient wrapper around the Keen.io API for Laravel

README 文档

README

Latest Version Software License Total Downloads

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.

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

use KeenIO;

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

Or pass a KeenEvent

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.

use Sitruc\KeenIO\KeenEvent;

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

$event->send();

Queuing events.

use Sitruc\KeenIO\KeenEvent;

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

$event->queued()->send();

Use keen.io's data enrichment.

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.

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

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.

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.

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

<?php

namespace App\Http\Controllers;

use App\KeenEvents\NewRegistration;

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

namespace App\KeenEvents;

use Sitruc\KeenIO\KeenEvent;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;

class NewRegistration extends KeenEvent implements ShouldQueue
{
    use InteractsWithQueue, Queueable, SerializesModels;
    
    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(),
        ];
    }
}

Install

This package can be installed through Composer.

composer require sitruc/keenio

You must install this service provider.

// 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.

// 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.

// 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.

Testing

Run the tests with:

vendor/bin/phpunit

or

composer test

Security

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

Credits

License

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

sitruc/keenio 适用场景与选型建议

sitruc/keenio 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.79k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2017 年 04 月 24 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「keen.io」 「keen」 「keen-io」 「keenio」 「laravel-keen」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 sitruc/keenio 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 sitruc/keenio 我们能提供哪些服务?
定制开发 / 二次开发

基于 sitruc/keenio 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 2.79k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-04-24