ripplesanalytics/ripples-php
Composer 安装命令:
composer require ripplesanalytics/ripples-php
包简介
Official PHP SDK for Ripples.sh — server-side event tracking
README 文档
README
Server-side PHP SDK for Ripples.sh analytics.
Install
composer require ripples/ripples-php
Add to your .env:
RIPPLES_SECRET_KEY=priv_your_secret_key
Usage
use Ripples\Ripples; $ripples = new Ripples(); $ripples->revenue(49.99, 'user_123'); $ripples->signup('user_123', ['email' => 'jane@example.com']); $ripples->track('created a budget', 'user_123', ['area' => 'budgets']); $ripples->identify('user_123', ['email' => 'jane@example.com']);
That's it.
Track product usage
Call track() only for significant product usage — actions that prove a user got real value (created a budget, sent a message, invited a teammate). This is not a generic event log like PostHog or Mixpanel: do not send pageviews, banner impressions, button clicks, or "viewed X" events. Every track() call feeds the Activation dashboard, so noise here pollutes your funnel. Ripples auto-detects activation (first occurrence per user), computes adoption rates, and correlates with retention and payment.
$ripples->track('created a budget', 'user_123', ['area' => 'budgets']); $ripples->track('shared a list', 'user_123', ['area' => 'sharing', 'via' => 'link']); $ripples->track('exported report', 'user_123', ['area' => 'reports', 'format' => 'csv']);
Use area to group actions into product areas. Use activated => true to mark the specific moment a user activates — it flags this occurrence, not the event type:
// User added their 10th transaction — we consider this their activation moment $ripples->track('added transaction', 'user_123', [ 'area' => 'transactions', 'activated' => true, // only on THIS occurrence ]);
Track subscriptions (MRR)
Call subscription() when a subscription is created, upgraded, downgraded, or canceled. This powers the MRR metric on your dashboard.
Stripe / Paddle users: MRR is tracked automatically via the integration. Only use this method if you use a payment provider without a native Ripples integration.
// User subscribes to Pro Monthly ($29/mo) $ripples->subscription('sub_123', 'user_456', 'active', 29.00, 'month', [ 'name' => 'Pro', 'currency' => 'EUR', ]); // User upgrades to Business Annual ($499/yr) $ripples->subscription('sub_123', 'user_456', 'active', 499.00, 'year', [ 'name' => 'Business', ]); // User cancels $ripples->subscription('sub_123', 'user_456', 'canceled', 0);
Parameters:
subscriptionId(string, required) — stable identifier for the subscriptionuserId(string, required) — your internal user IDstatus(string, required) — one of:active,canceled,past_due,trialing,pausedamount(float, required) — amount per billing cycle (e.g.29.00), pass0when cancelinginterval(string, optional) —month(default),year,week, ordayattributes(array, optional) —currency,nameorplan,interval_count
Track revenue
$ripples->revenue(49.99, 'user_123');
Any key you pass that isn't a known field becomes a custom property automatically:
$ripples->revenue(49.99, 'user_123', [ 'email' => 'jane@example.com', 'currency' => 'EUR', 'transaction_id' => 'txn_abc123', 'name' => 'Pro Plan', 'plan' => 'annual', // custom property 'coupon' => 'WELCOME20', // custom property ]);
Refunds are just negative revenue:
$ripples->revenue(-29.99, 'user_123', ['transaction_id' => 'txn_abc123']);
Track signups
$ripples->signup('user_123', [ 'email' => 'jane@example.com', 'name' => 'Jane Smith', 'referral' => 'twitter', // custom property 'plan' => 'free', // custom property ]);
Identify users
Update user traits at any time:
$ripples->identify('user_123', [ 'email' => 'jane@example.com', 'name' => 'Jane Smith', 'company' => 'Acme Inc', // custom property 'role' => 'admin', // custom property ]);
Backfill historical events
Pass a DateTimeInterface as the last argument to any tracking method to override the event's timestamp — useful when importing from a CSV, replaying from another analytics tool, or catching up after an outage.
foreach ($csvRows as $row) { $ripples->track( $row['action'], $row['user_id'], ['area' => $row['area']], new DateTimeImmutable($row['occurred_at']), // any tz — converted to UTC ); } $ripples->flush(); // guarantee delivery at end of script
Naive behavior (no timestamp passed) uses "now" in UTC. Non-UTC timezones are converted automatically.
Error handling
use Ripples\RipplesException; try { $ripples->revenue(49.99, 'user_123'); } catch (RipplesException $e) { // handle error }
Configuration
The SDK reads RIPPLES_SECRET_KEY from your environment automatically. You can override everything:
$ripples = new Ripples('priv_explicit_key', [ 'base_url' => 'https://your-domain.com/api', // self-hosted 'timeout' => 10, // seconds (default: 5) ]);
Self-hosted URL can also be set via env:
RIPPLES_URL=https://your-domain.com/api
Custom HTTP client
Extend the class and override post() to use Guzzle, Symfony HTTP, or anything else:
class MyRipples extends \Ripples\Ripples { protected function post(string $path, array $data): array { // your custom implementation } }
Requirements
- PHP 8.1+
- ext-curl
- ext-json
License
MIT
ripplesanalytics/ripples-php 适用场景与选型建议
ripplesanalytics/ripples-php 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 24 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「analytics」 「tracking」 「revenue」 「ripples」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ripplesanalytics/ripples-php 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ripplesanalytics/ripples-php 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ripplesanalytics/ripples-php 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
PHP SDK for the Parcel Monkey UK API
Analytics chooser extensions for site settings.
A Laravel Nova Card to show Fathom Analytics stats.
Audit changes of your Eloquent models in Laravel/Lumen
Alfabank REST API integration
Contao 4 Hintergrund-Tracking mit Matomo
统计信息
- 总下载量: 24
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 27
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-04-02