feat(analytics): port SessionJourney tracking from GardenBuddy (v1.12.0+16)

Rolls the session/journey/friction tracking module out to M8Chat app2, per
plan ancient-petting-hejlsberg.md §5 step 4. Same pattern as GardenBuddy's
same-day port: SessionJourney.init() wired after WidgetsFlutterBinding.
ensureInitialized() and after the existing FlutterError.onError /
PlatformDispatcher.instance.onError handlers, which it chains rather than
replaces. SessionJourneyNavigatorObserver registered on the GoRouter
instance; SessionJourneyGestureLayer wraps MaterialApp.router for rage-tap
detection.

This repo has no shared offline-cache module like GardenBuddy's
core/offline/, so persistence is a small scoped sj_local_store.dart using
the package:web dependency already present in the repo (localStorage on
web, in-memory fallback for the test VM), rather than adding a new package.

app_key m8chat.au-app was reserved today in track.php v2.0.1's
allowed_sites/allowed_origins for https://app2.m8chat.au, confirmed by grep
before use.

Verified live: build deployed to app2.m8chat.au (md5-matched), Playwright
navigation produced real session/visitor/screen_view rows in
admin_flutterstats with app_key=m8chat.au-app, nginx logs show no 5xx and
no real visitor served a broken build during the test window.
This commit is contained in:
2026-09-25 14:34:18 +10:00
parent e4aa5277d7
commit 729822c97e
8 changed files with 846 additions and 20 deletions
+6 -6
View File
@@ -1,12 +1,15 @@
// Version: 1.1.0 | Created: 2026-04-01 | Updated: 2026-04-05
// Version: 1.2.0 | Created: 2026-04-01 | Updated: 2026-09-25
// All route definitions in one place.
// GoRouter is created ONCE (keepAlive) and re-evaluates redirects via
// refreshListenable — avoids the GoRouter recreation bug from ref.watch.
// v1.2.0: registered SessionJourneyNavigatorObserver (session/journey
// tracking, plan ancient-petting-hejlsberg.md §3/§5).
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../core/analytics/session_journey.dart';
import '../core/auth/auth_notifier.dart';
import '../core/auth/auth_state.dart';
import '../features/auth/presentation/login_screen.dart';
@@ -40,11 +43,7 @@ class _AuthRefreshNotifier extends ChangeNotifier {
}
/// Routes that are accessible without authentication.
const _publicRoutes = {
AppRoutes.welcome,
AppRoutes.login,
AppRoutes.jitsi,
};
const _publicRoutes = {AppRoutes.welcome, AppRoutes.login, AppRoutes.jitsi};
@Riverpod(keepAlive: true)
GoRouter router(Ref ref) {
@@ -57,6 +56,7 @@ GoRouter router(Ref ref) {
initialLocation: AppRoutes.root,
refreshListenable: notifier,
debugLogDiagnostics: false,
observers: [SessionJourneyNavigatorObserver()],
redirect: (BuildContext context, GoRouterState state) {
// Read (not watch) so redirect does not itself trigger provider changes.
final authState = ref.read(authProvider);