Skip to content
elbanbydevPublic

About

Laravel package: track every user's journey steps (finished, started, never started), WhatsApp re-engagement panel, optional automatic WhatsApp nudges. EN + AR.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Stepwise

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

بالعربي: 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. Stepwise 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?
  3. Which steps did they never start?

On top of that table sits a re-engagement flow: a WhatsApp button per user that opens a modal (name, number, message) with a ready-made template pre-selected by where the user is stuck — "encourage to continue" when they have a half-finished step, "encourage to start" for the next step they never touched. Confirming opens the WhatsApp chat with the message prefilled, ready to send.

Optionally, Stepwise can also send nudges automatically (off by default): rules such as "started a step but not finished for 2 days", consent and STOP handling, quiet hours, cooldowns, a dry run, a panel tab, and Meta WhatsApp Cloud API, generic HTTP or log drivers. See Automatic WhatsApp sending.

Status: v0.6.0, pre-1.0. Covered by an automated suite (Pest, PHPStan level 8, Pint, CI on PHP 8.2 to 8.4 with Laravel 11 and 12). The automatic sending layer is tested against faked Meta/HTTP responses only; try it with your own number and the log provider first (see the go-live checklist below). Minor releases before 1.0 may change behavior; see the CHANGELOG.

Requirements

  • PHP 8.2 or newer
  • Laravel 11 or 12

Installation

composer require elbanbydev/stepwise
php artisan stepwise:install

stepwise:install publishes config/stepwise.php (if missing) and creates the Stepwise tables. Run it again any time; it only applies what is pending.

Stepwise registers its migrations itself, so no vendor:publish is needed for them: your normal deploy step php artisan migrate picks them up too. Composer cannot run migrations on composer require (Laravel packages have no install hook, and running database changes from a Composer script would be unsafe), so one of those two commands has to run once. If the tables are missing, the panel answers with a clear message and the tracking middleware stays quiet instead of breaking your site.

Define your journey

In config/stepwise.php:

'journeys' => [
    'default' => [
        'label' => 'Main journey',
        'steps' => [
            'account'     => 'Create the account',
            'profile'     => 'Complete the profile',
            'first-order' => 'Place the first order',
        ],
    ],
],

Steps are ordered. "Not started" is derived from this order: any step the user has no row for. You can define several journeys (buyer, seller, ...) and the panel gets a tab per journey.

Track progress

use Stepwise\Facades\Stepwise;

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

$summary = Stepwise::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 Stepwise\Events\StepStarted and Stepwise\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:

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

or by its alias stepwise.activity. Every authenticated request refreshes the user's last_seen_at, throttled by stepwise.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 stepwise.panel.gate (default viewStepwise) and define it:

Gate::define('viewStepwise', fn (User $user) => $user->isAdmin());

Then visit /stepwise (path configurable). The table shows, per user: name, your configured columns (stepwise.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 stepwise.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 /stepwise/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 stepwise.phone_attribute (default phone) and stepwise.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 Stepwise 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. Set stepwise.follow_up.confirm_sent to false to skip the confirm step: opening WhatsApp then records the follow-up as sent right away.

Opening WhatsApp is not the same as sending. The record starts as unconfirmed; after the admin comes back, the modal asks "Did you actually send it?" (with a chance to fix the text). Only confirmed sends count as the last follow-up and trigger the "followed up recently" warning. Abandoned drafts stay in the history labelled "Not sent".

Housekeeping

When your app deletes a user, drop their journey data too:

Stepwise::forget($user);   // removes progress rows and the visit record

Artisan report

php artisan stepwise:report            # every journey
php artisan stepwise:report onboarding # one journey

Prints, per step: how many users completed it, started it without finishing, and never started it.

Testing

composer check   # pint --test, phpstan level 8, pest

Upgrading from Rehla

Stepwise was called Rehla until v0.5.0 (v0.6.0 is the first release under the new name). If you installed elbanbydev/rehla, see the rename table in the CHANGELOG. Short version: composer remove elbanbydev/rehla && composer require elbanbydev/stepwise, rename config/rehla.php to config/stepwise.php, replace Rehla\ with Stepwise\, REHLA_* env vars with STEPWISE_*, the Gate viewRehla with viewStepwise, update the Meta webhook URL, then php artisan migrate (tables are renamed, data is kept).

License

MIT. See LICENSE.md.

Automatic WhatsApp sending (optional)

Manual follow-up stays as it is. Automation is a separate, optional layer that is off by default. Every setting lives in config/stepwise.php and env first; showing any of it in the panel is your choice.

STEPWISE_AUTOMATION_ENABLED=true
STEPWISE_AUTOMATION_PROVIDER=log      # log (dry run), meta, http, or your own
STEPWISE_META_PHONE_NUMBER_ID=...
STEPWISE_META_ACCESS_TOKEN=...
STEPWISE_META_VERIFY_TOKEN=...        # for the webhook
STEPWISE_META_APP_SECRET=...

Providers (stepwise.automation.providers):

  • log: dry run. Logs the message, sends nothing. Its rows are marked "Dry run" and never count as a real follow-up. Start here.
  • meta: WhatsApp Business Cloud API. Outside the 24-hour customer service window Meta only accepts approved templates, so automatic nudges need a template name; free text only works inside the window. Meta bills per message by category, and you pay Meta, not Stepwise.
  • http: any service that takes an HTTP request. The body is a config array with {phone}, {message}, {template}, {language}, {idempotency_key} placeholders. HTTPS only, and private or loopback addresses are refused unless you turn that off for development.
  • Your own: app(Stepwise\Automation\ProviderManager::class)->extend('acme', fn (array $config) => new AcmeProvider(...)), then 'driver' => 'acme' in config.

Sends run on your queue (stepwise.automation.queue), so run a queue worker. Temporary failures (timeouts, 429, 5xx) retry with the delays in stepwise.automation.retry.backoff_seconds (seconds: 60 = a minute, 3600 = an hour); permanent ones are marked failed with the provider's reason. Every automatic send is recorded in the same follow-up history as manual ones, labelled "Automatic".

Consent comes first. By default Stepwise only sends to users who opted in (stepwise.consent.required). Meta requires opt-in too: https://developers.facebook.com/docs/whatsapp/overview/getting-opt-in/

Stepwise::consent()->optIn($user, 'signup_form', 'ticked the box');
Stepwise::consent()->optOut($user);        // also cancels their queued automatic sends

Where consent comes from (stepwise.consent.source): table (the calls above, latest decision wins and the history is kept), attribute (a truthy column or accessor named in attribute), or resolver (an invokable class implementing Stepwise\Contracts\ConsentResolver). An opt-out recorded through Stepwise blocks sends with any source. Set required to false only if you collect consent elsewhere. Stepwise::forget($user) deletes their consent history too.

Webhook (delivery status and STOP replies). It is only registered when the meta provider has both STEPWISE_META_VERIFY_TOKEN and STEPWISE_META_APP_SECRET. Point Meta at https://your-app/stepwise/webhooks/meta (stepwise.webhooks.path, stepwise.webhooks.middleware). Requests without a valid X-Hub-Signature-256 are rejected. Delivery states only move forward (sent, delivered, read); a failure is recorded with Meta's error. A user who replies with a stop keyword (stepwise.webhooks.stop_keywords, English and Arabic by default, whole-message match, Arabic hamza forms treated alike) is opted out; start_keywords and the optional stop_reply / start_reply are config too. Matching a number to a user needs stepwise.phone_attribute to be a real column. Webhook reference: https://developers.facebook.com/documentation/business-messaging/whatsapp/webhooks/reference/messages/

In the panel, opted-out users get an "Opted out" mark and the follow-up modal asks for an explicit override before a manual message to them.

Rules and the engine

Rules say who gets which message and when. Define them in stepwise.automation.rules (code, always available) or in the stepwise_automation_rules table (managed in the panel's Automation tab). Both run together.

'rules' => [
    'stuck-profile' => [
        'journey' => 'default',
        'step' => 'profile',                          // optional; omit for "the step they are due on"
        'condition' => 'step_started_not_finished_for',
        'after_days' => 2,                            // or after_hours / after_weeks
        'message' => 'Hi {name}, finish "{step}" in {journey}',   // or 'template_id' => 3
        'max_sends_per_user' => 1,
        // Meta: approved template name; params are placeholder names filling {{1}}, {{2}}
        // 'provider_template' => ['name' => 'nudge_v1', 'language' => 'ar', 'params' => ['name', 'step']],
    ],
],

Conditions: inactive_for (no visit for the time), step_not_started_for (the step they are due on has not started, counted from their last completed step or registration), step_started_not_finished_for. Placeholders: {name}, {step}, {journey}, {days_inactive}.

Run it from the scheduler (every 5 to 15 minutes) and start with a dry run:

Schedule::command('stepwise:automate')->everyTenMinutes();
php artisan stepwise:automate --dry-run     # who would be messaged, who is skipped and why
php artisan stepwise:automate --rule=stuck-profile

Guards, in order, each skip counted with its reason: valid phone, consent (and no opt-out), quiet hours, cooldown, manual lock, already queued, max sends per user, then global limits. All are in stepwise.automation: quiet_hours (default 21:00 to 09:00, app timezone, optional per-user timezone column), cooldown_hours (72, or per rule), manual_lock_hours (2: an admin's open WhatsApp draft blocks automation), limits (per_hour, per_day, per_run; 0 turns one off). Just before sending, the job cancels the message if an admin messaged that user by hand in the meantime.

The panel has an Automation tab: rules from the database (add, edit, turn on or off, delete), config rules (read-only), a dry-run preview per rule (who would be messaged now, who is skipped and why) and the latest 50 automatic sends with delivery status. It is optional: set stepwise.panel.automation_tab to false to hide it and close its routes. Everything it does is also possible from config and stepwise:automate.

Before real users (checklist)

  1. Start with STEPWISE_AUTOMATION_PROVIDER=log and php artisan stepwise:automate --dry-run; read the preview in the Automation tab.
  2. Collect opt-in (Stepwise::consent()->optIn($user) when the user agrees), keep stepwise.consent.required on.
  3. Create and get your Meta templates approved in Meta Business Manager; map them with provider_template.
  4. Set the webhook (verify token, app secret) so STOP replies and delivery status work, and test it with a number you own.
  5. Run a queue worker and the scheduler (stepwise:automate every 5 to 15 minutes).
  6. Send to your own number first with a rule limited by limits.per_run.
  7. Optional: stepwise.automation.retention_days with Schedule::command('stepwise:prune')->daily() to delete old automatic rows. Queued sends that never ran are cancelled after stale_queued_hours (24).

About

Laravel package: track every user's journey steps (finished, started, never started), WhatsApp re-engagement panel, optional automatic WhatsApp nudges. EN + AR.

Topics

Resources

Contributing

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages