Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 13 additions & 10 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,35 @@

## Unreleased

### Changed (breaking rename)
- The package is now **Rehla**, matching its repository. It was named "Rihla" during pre-release development. Composer name `elbanbydev/rehla`, namespace `Rehla\`, config `config/rehla.php`, language namespace `rehla::`, facade `Rehla`, tables `rehla_*`, models `Rehla*`, env vars `REHLA_*`, routes `rehla.*`. Nothing was ever tagged or published under the old name, so there is no upgrade path to support.

### Fixed
- History popup text follows its own direction (mixed Arabic/English messages), and the (i) button no longer wraps under the follow-up time.

### Added
- The WhatsApp modal warns when the user was followed up within `rihla.follow_up.warn_within_hours` (default 24, 0 turns it off). It never blocks sending.
- The WhatsApp modal warns when the user was followed up within `rehla.follow_up.warn_within_hours` (default 24, 0 turns it off). It never blocks sending.

## v0.4.0 - 2026-12-03

### Added
- Follow-up tracking: when the admin confirms the WhatsApp modal, Rihla records who followed up, when, the exact message sent, and the template/journey/step it was about (template title snapshotted, so history survives template edits and deletions).
- Follow-up tracking: when the admin confirms the WhatsApp modal, Rehla records who followed up, when, the exact message sent, and the template/journey/step it was about (template title snapshotted, so history survives template edits and deletions).
- "Last follow-up" column in the panel table, next to "Last visit", so no two admins message the same user twice.
- An (i) button per row opens the follow-up history popup: every recorded message to that user, newest first (up to 50), with sender, time and subject.
- Recording and history endpoints live behind the same panel Gate; `Rihla::forget($user)` now removes follow-up records too.
- Recording and history endpoints live behind the same panel Gate; `Rehla::forget($user)` now removes follow-up records too.


## v0.3.1 - 2026-12-03

### Added
- `rihla:report` artisan command: per-journey table of how many users completed, started, or never started each step.
- `rehla:report` artisan command: per-journey table of how many users completed, started, or never started each step.

## v0.3.0 - 2026-12-03

### Added
- `{name}` placeholder in template content, replaced with the user's name when the modal fills the message.
- "Last visit" column in the panel table (relative time, or "Never").
- `Rihla::forget($user)`: delete a user's progress and visit records, for account deletion cleanup.
- `Rehla::forget($user)`: delete a user's progress and visit records, for account deletion cleanup.

## v0.2.0 - 2026-12-03

Expand All @@ -36,18 +39,18 @@
- The complete transition is now won with one atomic `UPDATE ... WHERE status = 'started'`, so two concurrent completes cannot both fire `StepCompleted`.
- `touch()` (visit tracking) swallows the duplicate-key race instead of erroring a normal page view.
- Dashboard join/order by the user model's actual key name instead of a hardcoded `id`.
- Clear `ConfigurationException` when `rihla.user_model` points at a missing class.
- Clear `ConfigurationException` when `rehla.user_model` points at a missing class.
- wa.me numbers shorter than 8 digits are rejected as undialable instead of producing a broken link.

## v0.1.0 - 2026-12-03

First public build.

### Added
- Journey + step definitions in config (`rihla.journeys`), ordered; "not started" derived from that order.
- Tracking API (`Rihla::start/complete/reset/progress`), idempotent transitions, `StepStarted`/`StepCompleted` events.
- Last-visit tracking via the `rihla.activity` middleware alias, throttled writes, guests ignored.
- Admin panel at `/rihla` (Gate-closed by default): per-user table with the three journey columns, journey tabs, pagination, and the "no visit for at least N day(s)" filter (0 = everyone; never-visited users count from registration).
- Journey + step definitions in config (`rehla.journeys`), ordered; "not started" derived from that order.
- Tracking API (`Rehla::start/complete/reset/progress`), idempotent transitions, `StepStarted`/`StepCompleted` events.
- Last-visit tracking via the `rehla.activity` middleware alias, throttled writes, guests ignored.
- Admin panel at `/rehla` (Gate-closed by default): per-user table with the three journey columns, journey tabs, pagination, and the "no visit for at least N day(s)" filter (0 = everyone; never-visited users count from registration).
- WhatsApp re-engagement modal per user row: name, normalised wa.me number, template dropdown, prefilled editable message, confirm opens `wa.me` in a new tab.
- Message templates CRUD: title + content, optional journey/step binding, `encourage_continue` / `encourage_start` types.
- Smart default selection: the in-progress step's continue template, otherwise the next not-started step's start template; admin override always possible.
Expand Down
48 changes: 24 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Rihla (رحلة)
# Rehla (رحلة)

Track where every user is in your site's journey, and bring back the ones who stall.

بالعربي: [docs/ar/README.md](docs/ar/README.md)

Some sites are not a pile of pages; they are a journey. The user creates an account, completes a profile, places a first order — defined steps, one after another. Rihla records where each user stands and gives the admin one table that always answers three questions:
Some sites are not a pile of pages; they are a journey. The user creates an account, completes a profile, places a first order — defined steps, one after another. Rehla records where each user stands and gives the admin one table that always answers three questions:

1. Which steps did this user **finish**?
2. Which steps did they **start but never finish**?
Expand All @@ -22,14 +22,14 @@ On top of that table sits a re-engagement flow: a WhatsApp button per user that
## Installation

```bash
composer require elbanbydev/rihla
php artisan vendor:publish --tag=rihla-config
composer require elbanbydev/rehla
php artisan vendor:publish --tag=rehla-config
php artisan migrate
```

## Define your journey

In `config/rihla.php`:
In `config/rehla.php`:

```php
'journeys' => [
Expand All @@ -49,62 +49,62 @@ Steps are ordered. "Not started" is derived from this order: any step the user h
## Track progress

```php
use Rihla\Facades\Rihla;
use Rehla\Facades\Rehla;

Rihla::start($user, 'profile'); // user began the step
Rihla::complete($user, 'profile'); // user finished it
Rihla::reset($user, step: 'profile'); // forget one step
Rihla::reset($user); // forget the whole journey
Rehla::start($user, 'profile'); // user began the step
Rehla::complete($user, 'profile'); // user finished it
Rehla::reset($user, step: 'profile'); // forget one step
Rehla::reset($user); // forget the whole journey

$summary = Rihla::progress($user);
$summary = Rehla::progress($user);
$summary->completedSteps; // ['account']
$summary->startedSteps; // ['profile']
$summary->notStartedSteps; // ['first-order']
```

All transitions are idempotent: starting a started step (or completing a completed one) changes nothing and fires no event. Completing a step that was never started stamps both dates. Events `Rihla\Events\StepStarted` and `Rihla\Events\StepCompleted` fire on real transitions only.
All transitions are idempotent: starting a started step (or completing a completed one) changes nothing and fires no event. Completing a step that was never started stamps both dates. Events `Rehla\Events\StepStarted` and `Rehla\Events\StepCompleted` fire on real transitions only.

## Track the last visit

The "days absent" filter needs to know when each user was last seen. Add the middleware alias to your `web` (and/or `api`) group in `bootstrap/app.php`:

```php
->withMiddleware(function (Middleware $middleware) {
$middleware->appendToGroup('web', [\Rihla\Http\Middleware\RecordActivity::class]);
$middleware->appendToGroup('web', [\Rehla\Http\Middleware\RecordActivity::class]);
})
```

or by its alias `rihla.activity`. Every authenticated request refreshes the user's `last_seen_at`, throttled by `rihla.activity.throttle_seconds` (default 300) so a busy session costs at most one write per window. Guests are never tracked.
or by its alias `rehla.activity`. Every authenticated request refreshes the user's `last_seen_at`, throttled by `rehla.activity.throttle_seconds` (default 300) so a busy session costs at most one write per window. Guests are never tracked.

## Open the panel

The panel stays closed until you name a Gate ability in `rihla.panel.gate` (default `viewRihla`) and define it:
The panel stays closed until you name a Gate ability in `rehla.panel.gate` (default `viewRehla`) and define it:

```php
Gate::define('viewRihla', fn (User $user) => $user->isAdmin());
Gate::define('viewRehla', fn (User $user) => $user->isAdmin());
```

Then visit `/rihla` (path configurable). The table shows, per user: name, your configured columns (`rihla.user_columns`, e.g. email, role), and the three journey columns as badges. The filter above the table reads "no visit for at least N day(s)":
Then visit `/rehla` (path configurable). The table shows, per user: name, your configured columns (`rehla.user_columns`, e.g. email, role), and the three journey columns as badges. The filter above the table reads "no visit for at least N day(s)":

- **0** shows everyone, even someone who registered seconds ago.
- **N** shows only users with no recorded visit in the last N days. A user with no visit at all counts from their registration date.

## WhatsApp re-engagement

Each row with a phone number gets a WhatsApp button. The modal shows the user's name, the destination number (normalised to wa.me digits: local `0107…` becomes `20107…` via `rihla.whatsapp.default_country_code`), a template dropdown, and the message. Confirming opens `https://wa.me/<number>?text=<message>` in a new tab — nothing is sent without a human clicking send in WhatsApp.
Each row with a phone number gets a WhatsApp button. The modal shows the user's name, the destination number (normalised to wa.me digits: local `0107…` becomes `20107…` via `rehla.whatsapp.default_country_code`), a template dropdown, and the message. Confirming opens `https://wa.me/<number>?text=<message>` in a new tab — nothing is sent without a human clicking send in WhatsApp.

Templates are managed at `/rihla/templates`: title + content, plus an optional binding to a specific step of a journey and one of two types:
Templates are managed at `/rehla/templates`: title + content, plus an optional binding to a specific step of a journey and one of two types:

- **Encourage to continue the step** — pre-selected when the user has that step started but unfinished.
- **Encourage to start the step** — pre-selected for the next never-started step, when the user has nothing in progress.

The modal pre-selects by that rule (most recently updated matching template wins) and the admin can always pick another template or edit the text before opening WhatsApp. Templates with no step binding are never auto-selected.

Set `rihla.phone_attribute` (default `phone`) and `rihla.name_attribute` (default `name`) to match your user model. The placeholder `{name}` inside a template's content is replaced with the user's name when the modal fills the message.
Set `rehla.phone_attribute` (default `phone`) and `rehla.name_attribute` (default `name`) to match your user model. The placeholder `{name}` inside a template's content is replaced with the user's name when the modal fills the message.

## Follow-up tracking

When several people have follow-up permission, nobody should message the same user twice. So Rihla records every follow-up the moment the admin confirms the WhatsApp modal: who sent it, when, the exact message, and what it was about (the template title is snapshotted, so the record survives template edits and deletions).
When several people have follow-up permission, nobody should message the same user twice. So Rehla records every follow-up the moment the admin confirms the WhatsApp modal: who sent it, when, the exact message, and what it was about (the template title is snapshotted, so the record survives template edits and deletions).

The table's **Last follow-up** column sits next to **Last visit**, and each row's **(i)** button opens the full history popup: every message ever sent to that user, newest first. Recording is best-effort and never blocks opening WhatsApp.

Expand All @@ -113,14 +113,14 @@ The table's **Last follow-up** column sits next to **Last visit**, and each row'
When your app deletes a user, drop their journey data too:

```php
Rihla::forget($user); // removes progress rows and the visit record
Rehla::forget($user); // removes progress rows and the visit record
```

## Artisan report

```bash
php artisan rihla:report # every journey
php artisan rihla:report onboarding # one journey
php artisan rehla:report # every journey
php artisan rehla:report onboarding # one journey
```

Prints, per step: how many users completed it, started it without finishing, and never started it.
Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "elbanbydev/rihla",
"description": "Rihla (رحلة) - track where every user is in your site's journey: which steps they finished, which they started but never finished, and which they never touched, with a WhatsApp re-engagement panel. Experimental.",
"name": "elbanbydev/rehla",
"description": "Rehla (رحلة) - track where every user is in your site's journey: which steps they finished, which they started but never finished, and which they never touched, with a WhatsApp re-engagement panel. Experimental.",
"keywords": [
"laravel",
"user-journey",
Expand All @@ -9,7 +9,7 @@
"user-progress",
"whatsapp",
"egypt",
"rihla"
"rehla"
],
"license": "MIT",
"require": {
Expand All @@ -30,21 +30,21 @@
},
"autoload": {
"psr-4": {
"Rihla\\": "src/"
"Rehla\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"Rihla\\Tests\\": "tests/"
"Rehla\\Tests\\": "tests/"
}
},
"extra": {
"laravel": {
"providers": [
"Rihla\\RihlaServiceProvider"
"Rehla\\RehlaServiceProvider"
],
"aliases": {
"Rihla": "Rihla\\Facades\\Rihla"
"Rehla": "Rehla\\Facades\\Rehla"
}
}
},
Expand Down
14 changes: 7 additions & 7 deletions config/rihla.php → config/rehla.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
return [

/*
| The Eloquent model that moves through the journey. Rihla never
| The Eloquent model that moves through the journey. Rehla never
| migrates this model's table; it keeps its own tables instead.
*/
'user_model' => env('RIHLA_USER_MODEL', 'App\\Models\\User'),
'user_model' => env('REHLA_USER_MODEL', 'App\\Models\\User'),

/*
| Attributes used in the panel: the display name and the WhatsApp
Expand Down Expand Up @@ -44,7 +44,7 @@
],

/*
| Last-visit tracking. Add the `rihla.activity` middleware alias to
| Last-visit tracking. Add the `rehla.activity` middleware alias to
| your web (and/or api) middleware group. Writes are throttled so a
| busy user costs at most one write per throttle window.
*/
Expand All @@ -56,13 +56,13 @@
/*
| The admin panel. It stays closed (403) until you name a Gate
| ability in `panel.gate` and define it in your AuthServiceProvider:
| Gate::define('viewRihla', fn (User $user) => $user->isAdmin());
| Gate::define('viewRehla', fn (User $user) => $user->isAdmin());
*/
'panel' => [
'enabled' => true,
'path' => 'rihla',
'path' => 'rehla',
'middleware' => ['web'],
'gate' => 'viewRihla',
'gate' => 'viewRehla',
],

/*
Expand All @@ -79,7 +79,7 @@
| without "+". Local numbers (leading 0) get the country code.
*/
'whatsapp' => [
'default_country_code' => env('RIHLA_WHATSAPP_COUNTRY_CODE', '20'),
'default_country_code' => env('REHLA_WHATSAPP_COUNTRY_CODE', '20'),
],

];
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
public function up(): void
{
Schema::create('rihla_step_progress', function (Blueprint $table): void {
Schema::create('rehla_step_progress', function (Blueprint $table): void {
$table->id();
$table->string('trackable_type');
$table->unsignedBigInteger('trackable_id');
Expand All @@ -21,13 +21,13 @@ public function up(): void
$table->timestamp('completed_at')->nullable();
$table->timestamps();

$table->unique(['trackable_type', 'trackable_id', 'journey', 'step'], 'rihla_progress_unique');
$table->index(['journey', 'step'], 'rihla_progress_step_index');
$table->unique(['trackable_type', 'trackable_id', 'journey', 'step'], 'rehla_progress_unique');
$table->index(['journey', 'step'], 'rehla_progress_step_index');
});
}

public function down(): void
{
Schema::dropIfExists('rihla_step_progress');
Schema::dropIfExists('rehla_step_progress');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
{
public function up(): void
{
Schema::create('rihla_activity', function (Blueprint $table): void {
Schema::create('rehla_activity', function (Blueprint $table): void {
$table->id();
$table->string('trackable_type');
$table->unsignedBigInteger('trackable_id');
$table->timestamp('last_seen_at');
$table->timestamps();

$table->unique(['trackable_type', 'trackable_id'], 'rihla_activity_unique');
$table->index('last_seen_at', 'rihla_activity_last_seen_index');
$table->unique(['trackable_type', 'trackable_id'], 'rehla_activity_unique');
$table->index('last_seen_at', 'rehla_activity_last_seen_index');
});
}

public function down(): void
{
Schema::dropIfExists('rihla_activity');
Schema::dropIfExists('rehla_activity');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
public function up(): void
{
Schema::create('rihla_templates', function (Blueprint $table): void {
Schema::create('rehla_templates', function (Blueprint $table): void {
$table->id();
$table->string('title');
$table->text('content');
Expand All @@ -19,12 +19,12 @@ public function up(): void
$table->string('type', 24);
$table->timestamps();

$table->index(['journey', 'step', 'type'], 'rihla_templates_lookup');
$table->index(['journey', 'step', 'type'], 'rehla_templates_lookup');
});
}

public function down(): void
{
Schema::dropIfExists('rihla_templates');
Schema::dropIfExists('rehla_templates');
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
{
public function up(): void
{
Schema::create('rihla_follow_ups', function (Blueprint $table): void {
Schema::create('rehla_follow_ups', function (Blueprint $table): void {
$table->id();
$table->string('trackable_type');
$table->unsignedBigInteger('trackable_id');
Expand All @@ -25,12 +25,12 @@ public function up(): void
$table->string('channel', 24)->default('whatsapp');
$table->timestamps();

$table->index(['trackable_type', 'trackable_id', 'created_at'], 'rihla_followups_user_index');
$table->index(['trackable_type', 'trackable_id', 'created_at'], 'rehla_followups_user_index');
});
}

public function down(): void
{
Schema::dropIfExists('rihla_follow_ups');
Schema::dropIfExists('rehla_follow_ups');
}
};
Loading
Loading