Skip to content

Live visitors without Google Analytics: Free source and hooks - #207

Open
sh03rohan wants to merge 6 commits into
devfrom
live-visitors-builtin
Open

sh03rohan wants to merge 6 commits into
devfrom
live-visitors-builtin

Conversation

@sh03rohan

Copy link
Copy Markdown
Contributor

Free part of the built-in live visitor count ("12 people are viewing this now") that works without Google Analytics. The counting logic lives in Pro (PR: ). Merge this one first.

What's added

  • A "Built-in (no Google Analytics)" source for Page Analytics, with its own Live Visitors module. Without Pro it shows locked, like other Pro sources.
  • Generic hooks for add-ons: nx_frontend_entry (supply or hold back an entry), notificationx:refresh, nx_live_viewers_available, nx_live_visitors_themes, and the NOTIFICATIONX_LIVE_API marker.
  • nx_public_rest_routes: lets an add-on make one of NotificationX's own routes public. Restricted to the NotificationX namespace; other plugins' routes and malformed names are rejected, and a request whose login check failed runs as a logged-out visitor.
  • nx_awaiting_data: an entry marked as waiting for data never renders until a filter supplies it, so a failed add-on script can't show an empty number.

Unchanged

  • No counting code in Free, and nothing runs until a site owner enables a live notification.
  • Saved notifications and every other source render exactly as before (tested).

Testing

  • JS: 144 tests pass. PHP: full Free suite, 304 tests pass.
  • Checked in the browser together with the Pro PR.

Notes

  • @since x.x.x placeholders; the version is set at release.
  • vendor/composer autoload lines for the new class were added by hand (no Composer locally).

sh03rohan and others added 2 commits November 2, 2026 16:31
…c hooks (Phase 1)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…_data)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sh03rohan
sh03rohan requested a review from ShahrearMSf November 3, 2026 12:10
@sh03rohan
sh03rohan changed the base branch from master to dev November 11, 2026 05:06
# Conflicts:
#	assets/public/js/crossSite.js
#	assets/public/js/frontend.js
The card used the bare NotificationX icon, so it had no name next to the
Google Analytics card. It now shows "Built-in Counter", like the other
source logos.

@ShahrearMSf ShahrearMSf left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Approved: Free side of the built-in live visitor count

@sh03rohan bhai, the Free hooks are tidy and do exactly what Pro #63 needs, and nothing new runs until a live notification is switched on. I merged the latest dev into the branch, rebuilt the bundles and fixed one small design gap in the source card. Details below.

What I fixed (pushed to this branch)

  • Merged dev into the branch (a4763bd). The only conflicts were the built frontend.js and crossSite.js. I rebuilt both from the merged source with the lockfile toolchain (npm ci --ignore-scripts, webpack 5.99.8); check:bundle passes (431.7 KB / 432.1 KB raw).
  • Built-in source card had no name (2d46f12). It used the bare logo-icon.svg, so next to the Google Analytics logo it was just a small bell nobody could identify. It now uses images/extensions/sources/live-visitors.png ("Built-in Counter" in the same navy wordmark style as custom.png).

What I tested

Automated

  • Jest: 233/233 (16 suites), including the new entry-filter tests.
  • PHPUnit (full Free suite, WP 7.1.4 test lib, MySQL): 323/0.
  • PHP 7.4 lint on every changed PHP file: clean, with no PHP 8-only syntax.

Live (local WP 7.1.4 + WooCommerce 11.2, PHP 8.4, together with Pro #63)

  • Builder: with both modules on, picking Page Analytics still defaults to Google Analytics, as before. Selecting Built-in hides the "connect your Google Analytics" warning, swaps the sidebar text for the new doc(), limits Design to pa-theme-three and adds the Pro content fields. Publishing saves source = live_visitors. Preview shows a sample number.
  • Frontend: the entry stays hidden while nx_awaiting_data is set, and the count appears through nx_frontend_entry. Desktop and 390px (Pro's mobile card): no horizontal overflow.

Version mixes (no fatal, no JS errors):

Combination Result
This Free alone Page Analytics locked as before; live notifications not printed; no ping script
This Free + released Pro 3.2.7 Built-in card shows "NotificationX Pro needs an update."; saved live notifications are excluded from the page (exclude_unsupported)
Released Free 3.3.8 + Pro #63 Pro stays inert without NOTIFICATIONX_LIVE_API; admin and frontend fine
  • REST: /notificationx/v1/live passes the "Enable REST API" restriction as a logged-out user. is_public_route_name() rejects other namespaces (covered by your seam tests).

Content

No content issues. "Built-in (no Google Analytics)", the upsell text and the update popup read clearly.

Design

  • Source card: fixed above.

Note (not a blocker)

  • If Free is downgraded to 3.3.8 while saved live notifications still exist, 3.3.8's ExtensionFactory::get() logs "Undefined array key live_visitors". That's old Free code meeting an unknown source, not something this PR can change.

Merge readiness

Ready to merge, together with Pro #63 (Free first, as the description says).

sh03rohan and others added 2 commits November 19, 2026 13:17
Brings Free PR #207 up to date with dev (77443de).

Conflicts: assets/public/js/frontend.js and crossSite.js only. Both were
rebuilt from the merged sources (npm run build) instead of taking a side;
every other built file is byte-identical to the fresh build.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A live visitors notice waits for its count: NotificationContainer draws
nothing while the `nx_frontend_entry` filter returns null or the entry is
still `nx_awaiting_data`. But useNotificationX added it to the list every
cycle anyway, and a notice only leaves the list through its own card's
timer. So a visitor who waited about a minute before the count arrived got
four identical cards at once.

dispatchNotification() now skips a cycle while the notice is held back
(heldBack.ts) and keeps the loop; the next cycle shows it once the count is
known. Only entries (objects) can be held back: bar, popup and GDPR content
is never touched, and without an add-on filter nothing changes.

Tests: tests/js/frontend/held-back.test.js (hidden cycles add nothing, it
shows exactly once when the count arrives, the loop keeps running, a sales
notification loops as before, plain entries without filters, isHeldBack).
Rebuilt frontend.js and crossSite.js.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@sh03rohan

sh03rohan commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor Author

@ShahrearMSf Updated since the 12 Nov approval:

  • Up to date with dev (merged 77443dec; only the two built bundles conflicted, rebuilt from the merged sources).
  • Fix 32920038: a visitor who waited alone for about a minute got several identical live cards when a second visitor arrived. Hidden cycles no longer pile up, so exactly one card shows. Only held-back entries are affected; bar, popup and GDPR content are unchanged. 5 new Jest tests; checked with two browser profiles.

Checks: Jest 1066/1066, PHP 520, build and check:bundle ok.

Could you take a quick re-review? Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants