@tech4good/angular-schematics 21.6.0 → 21.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +28 -0
- package/README.md +266 -1
- package/package.json +34 -7
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +4 -5
- package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +1 -1
- package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +14 -6
- package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +12 -6
- package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +18 -10
- package/src/entity/index.js +4 -49
- package/src/entity/index.js.map +1 -1
- package/src/guard/files/__name@dasherize__.guard.spec.ts.template +0 -1
- package/src/ng-add/files/.github/workflows/angular-github-ci.yml.template +3 -0
- package/src/ng-add/files/.gitignore.template +3 -0
- package/src/ng-add/files/analytics/datasets.js.template +206 -0
- package/src/ng-add/files/analytics/entity_sources.js.template +58 -0
- package/src/ng-add/files/analytics/entity_sources.test.js.template +57 -0
- package/src/ng-add/files/analytics/lib/api_query.js.template +87 -0
- package/src/ng-add/files/analytics/lib/api_query.test.js.template +84 -0
- package/src/ng-add/files/analytics/lib/bigquery_query_compatibility.test.js.template +53 -0
- package/src/ng-add/files/analytics/lib/dataset_schema.js.template +53 -0
- package/src/ng-add/files/analytics/lib/dataset_schema.test.js.template +34 -0
- package/src/ng-add/files/analytics/lib/entity_sync.js.template +397 -0
- package/src/ng-add/files/analytics/lib/entity_sync.test.js.template +212 -0
- package/src/ng-add/files/analytics/lib/identifier_salt.js.template +57 -0
- package/src/ng-add/files/analytics/lib/identifier_salt.test.js.template +36 -0
- package/src/ng-add/files/analytics/lib/snapshot_files.js.template +46 -0
- package/src/ng-add/files/analytics/lib/snapshot_files.test.js.template +67 -0
- package/src/ng-add/files/analytics/lib/sqlite.js.template +92 -0
- package/src/ng-add/files/analytics/lib/upload_entities.js.template +81 -0
- package/src/ng-add/files/analytics/lib/upload_entities.test.js.template +86 -0
- package/src/ng-add/files/analytics/proxy.conf.json.template +7 -0
- package/src/ng-add/files/analytics/scripts/refresh_snapshot.js.template +518 -0
- package/src/ng-add/files/analytics/scripts/start.js.template +88 -0
- package/src/ng-add/files/analytics/server/server.js.template +212 -0
- package/src/ng-add/files/angular.json.template +80 -1
- package/src/ng-add/files/bigquery/queries/active_time_by_route.sql.template +27 -8
- package/src/ng-add/files/bigquery/queries/active_user_windows.sql.template +67 -0
- package/src/ng-add/files/bigquery/queries/dashboard_route_visits.sql.template +47 -0
- package/src/ng-add/files/bigquery/queries/data_quality.sql.template +323 -0
- package/src/ng-add/files/bigquery/queries/onboarding_funnel.sql.template +512 -0
- package/src/ng-add/files/bigquery/queries/onboarding_stage_observations.sql.template +134 -0
- package/src/ng-add/files/bigquery/queries/weekly_retention_cohorts.sql.template +90 -0
- package/src/ng-add/files/bigquery/scripts/export_entities.js.template +120 -0
- package/src/ng-add/files/bigquery/scripts/init_views.js.template +57 -0
- package/src/ng-add/files/bigquery/scripts/run_query.js.template +141 -0
- package/src/ng-add/files/bigquery/views/events_flat.sql.template +27 -12
- package/src/ng-add/files/bigquery/views/logs_latest.sql.template +16 -3
- package/src/ng-add/files/docs-infra/analytics-guide.md.template +270 -25
- package/src/ng-add/files/docs-infra/analytics-workbench-guide.md.template +307 -0
- package/src/ng-add/files/docs-infra/authentication-architecture.md.template +54 -24
- package/src/ng-add/files/docs-infra/email-infrastructure.md.template +43 -0
- package/src/ng-add/files/docs-infra/firestore-index-checker.md.template +87 -0
- package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +108 -29
- package/src/ng-add/files/docs-infra/load-system-architecture.md.template +15 -1
- package/src/ng-add/files/docs-infra/querying-strategy.md.template +14 -0
- package/src/ng-add/files/docs-infra/stream-system-architecture.md.template +21 -7
- package/src/ng-add/files/eslint.config.js.template +22 -3
- package/src/ng-add/files/functions/package.json.template +1 -0
- package/src/ng-add/files/functions/src/email.ts.template +23 -0
- package/src/ng-add/files/jest.config.ts.template +3 -2
- package/src/ng-add/files/package.json.template +39 -16
- package/src/ng-add/files/projects/analytics/src/app/analytics-api.service.ts.template +130 -0
- package/src/ng-add/files/projects/analytics/src/app/app.component.html.template +77 -0
- package/src/ng-add/files/projects/analytics/src/app/app.component.scss.template +240 -0
- package/src/ng-add/files/projects/analytics/src/app/app.component.ts.template +96 -0
- package/src/ng-add/files/projects/analytics/src/app/app.routes.ts.template +11 -0
- package/src/ng-add/files/projects/analytics/src/app/dashboard-pages.spec.ts.template +151 -0
- package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.html.template +39 -0
- package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.ts.template +95 -0
- package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.html.template +47 -0
- package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.ts.template +120 -0
- package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.html.template +40 -0
- package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.ts.template +98 -0
- package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.html.template +35 -0
- package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.ts.template +84 -0
- package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.html.template +42 -0
- package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.scss.template +1 -0
- package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.ts.template +110 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/analytics-utils.ts.template +43 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/chart-theme.ts.template +42 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-layout.scss.template +239 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.html.template +76 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.scss.template +128 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.spec.ts.template +31 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.ts.template +153 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.html.template +16 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.scss.template +63 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.ts.template +52 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.html.template +5 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.scss.template +56 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.spec.ts.template +30 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.ts.template +15 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.html.template +9 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.scss.template +43 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.ts.template +62 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.html.template +9 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.scss.template +33 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.ts.template +82 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.html.template +15 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.scss.template +45 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.ts.template +55 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.html.template +18 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.scss.template +45 -0
- package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.ts.template +15 -0
- package/src/ng-add/files/projects/analytics/src/app/vega-chart/vega-chart.component.ts.template +121 -0
- package/src/ng-add/files/projects/analytics/src/index.html.template +19 -0
- package/src/ng-add/files/projects/analytics/src/main.ts.template +16 -0
- package/src/ng-add/files/projects/analytics/src/styles.scss.template +28 -0
- package/src/ng-add/files/projects/analytics/tsconfig.app.json.template +13 -0
- package/src/ng-add/files/projects/analytics/tsconfig.spec.json.template +15 -0
- package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.spec.ts.template +11 -12
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +7 -7
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.spec.ts.template +8 -10
- package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +3 -2
- package/src/ng-add/files/src/app/app.component.html.template +1 -1
- package/src/ng-add/files/src/app/app.component.scss.template +1 -1
- package/src/ng-add/files/src/app/app.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/app.component.ts.template +1 -2
- package/src/ng-add/files/src/app/app.config.ts.template +21 -15
- package/src/ng-add/files/src/app/auth-routing.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +46 -29
- package/src/ng-add/files/src/app/core/analytics/time-analytics.service.ts.template +27 -18
- package/src/ng-add/files/src/app/core/auth/auth.providers.spec.ts.template +112 -0
- package/src/ng-add/files/src/app/core/auth/auth.providers.ts.template +48 -0
- package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +9 -23
- package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +3 -14
- package/src/ng-add/files/src/app/core/firebase/data.providers.prod.ts.template +21 -0
- package/src/ng-add/files/src/app/core/firebase/data.providers.ts.template +13 -0
- package/src/ng-add/files/src/app/core/local-storage/session.service.spec.ts.template +43 -0
- package/src/ng-add/files/src/app/core/local-storage/session.service.ts.template +7 -0
- package/src/ng-add/files/src/app/core/store/app-data.spec.ts.template +76 -0
- package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +19 -67
- package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +102 -12
- package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +32 -237
- package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +17 -12
- package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +6 -7
- package/src/ng-add/files/src/app/core/store/user/user.store.ts.template +14 -10
- package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +20 -8
- package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +5 -6
- package/src/ng-add/files/src/app/core/store/user-context/user-context.store.ts.template +14 -10
- package/src/ng-add/files/src/app/core/store/user-private/user-private.mock.ts.template +20 -7
- package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +5 -6
- package/src/ng-add/files/src/app/core/store/user-private/user-private.store.ts.template +14 -10
- package/src/ng-add/files/src/app/core/testing/app-mocks.ts.template +42 -0
- package/src/ng-add/files/src/app/first-time/consent/consent.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/consent/consent.component.scss.template +7 -3
- package/src/ng-add/files/src/app/first-time/consent/consent.component.spec.ts.template +31 -11
- package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +16 -1
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +15 -15
- package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +11 -3
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.html.template +2 -1
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.scss.template +7 -3
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.spec.ts.template +20 -6
- package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.ts.template +2 -0
- package/src/ng-add/files/src/app/first-time/early-access/waitlist-view/waitlist-view.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +17 -1
- package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +15 -0
- package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +15 -0
- package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +2 -0
- package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +21 -3
- package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +26 -0
- package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.spec.ts.template +4 -2
- package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.ts.template +1 -1
- package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +4 -4
- package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +2 -2
- package/src/ng-add/files/src/app/main/home/home.component.spec.ts.template +4 -5
- package/src/ng-add/files/src/app/main/home/home.component.ts.template +1 -1
- package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +4 -4
- package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +2 -2
- package/src/ng-add/files/tsconfig.spec.json.template +3 -1
- package/src/ng-add/index.js +7 -0
- package/src/ng-add/index.js.map +1 -1
- package/src/shared/entity-registry.d.ts +8 -0
- package/src/shared/entity-registry.js +28 -0
- package/src/shared/entity-registry.js.map +1 -0
- package/.agents/skills/publish-npm/SKILL.md +0 -37
- package/.agents/skills/publish-npm/eval.yaml +0 -32
- package/.agents/skills/publish-npm/fixtures/package-v21.json.template +0 -8
- package/.husky/commit-msg +0 -1
- package/.husky/pre-commit +0 -1
- package/.t4g/agent-memory.db +0 -0
- package/src/component/index_spec.d.ts +0 -1
- package/src/component/index_spec.js +0 -68
- package/src/component/index_spec.js.map +0 -1
- package/src/entity/index_spec.d.ts +0 -1
- package/src/entity/index_spec.js +0 -153
- package/src/entity/index_spec.js.map +0 -1
- package/src/guard/index_spec.d.ts +0 -1
- package/src/guard/index_spec.js +0 -64
- package/src/guard/index_spec.js.map +0 -1
- package/src/ng-add/files/bigquery/scripts/export_entities.py.template +0 -143
- package/src/ng-add/files/bigquery/scripts/run_query.py.template +0 -167
- package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +0 -500
- package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +0 -73
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.spec.ts.template +0 -59
- package/src/ng-add/files/src/app/core/firebase/email-link-context.service.ts.template +0 -147
- package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +0 -453
- package/src/ng-add/files/src/app/core/firebase/firebase.service.spec.ts.template +0 -116
- package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +0 -639
- package/src/ng-add/files/src/app/core/firebase/simulate-load.spec.ts.template +0 -104
- package/src/ng-add/files/src/app/core/firebase/simulate-stream.spec.ts.template +0 -127
- package/src/ng-add/files/src/app/core/firebase/simulation.mock.ts.template +0 -38
- package/src/ng-add/files/src/app/core/firebase/stream-multiplexer.ts.template +0 -445
- package/src/ng-add/files/src/app/core/logging/logging.service.spec.ts.template +0 -118
- package/src/ng-add/files/src/app/core/logging/logging.service.ts.template +0 -168
- package/src/ng-add/files/src/app/core/store/app.model.ts.template +0 -21
- package/src/ng-add/files/src/app/core/store/app.store.spec.ts.template +0 -920
- package/src/ng-add/files/src/app/core/store/app.store.ts.template +0 -1320
- package/src/ng-add/files/src/app/core/store/batch-write.firebase.service.ts.template +0 -58
- package/src/ng-add/files/src/app/core/store/batch-write.mock.service.ts.template +0 -105
- package/src/ng-add/files/src/app/core/store/batch-write.service.ts.template +0 -126
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.html.template +0 -9
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.scss.template +0 -46
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.spec.ts.template +0 -69
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +0 -39
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.spec.ts.template +0 -122
- package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +0 -88
- package/src/ng-add/index_spec.d.ts +0 -1
- package/src/ng-add/index_spec.js +0 -108
- package/src/ng-add/index_spec.js.map +0 -1
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Analytics HTTP Proxy & File Server
|
|
3
|
+
*
|
|
4
|
+
* Serves static Angular frontend build files and provides read-only REST endpoints
|
|
5
|
+
* backed by offline SQLite data snapshots.
|
|
6
|
+
*
|
|
7
|
+
* Security:
|
|
8
|
+
* - Reads from SQLite databases in OPEN_READONLY mode.
|
|
9
|
+
* - Relies on `queryForDataset()` for pagination bounds and parameter validation.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import fs from 'node:fs';
|
|
13
|
+
import http from 'node:http';
|
|
14
|
+
import path from 'node:path';
|
|
15
|
+
import { fileURLToPath } from 'node:url';
|
|
16
|
+
import sqlite3 from 'sqlite3';
|
|
17
|
+
import { datasets, datasetsById } from '../datasets.js';
|
|
18
|
+
import { queryForDataset } from '../lib/api_query.js';
|
|
19
|
+
import { quoteIdentifier } from '../lib/dataset_schema.js';
|
|
20
|
+
import { all, closeDatabase, get, openDatabase } from '../lib/sqlite.js';
|
|
21
|
+
|
|
22
|
+
// Resolve local filesystem paths
|
|
23
|
+
const serverDirectory = path.dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
const repoRoot = path.resolve(serverDirectory, '..', '..');
|
|
25
|
+
const localRoot = path.join(repoRoot, '.local', 'analytics');
|
|
26
|
+
const pointerPath = path.join(localRoot, 'current.json');
|
|
27
|
+
const clientRoot = path.join(repoRoot, 'dist', 'analytics', 'browser');
|
|
28
|
+
const port = 4321;
|
|
29
|
+
const appName = '<%= classify(project) %>';
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* @param {http.ServerResponse} response
|
|
33
|
+
* @param {number} status
|
|
34
|
+
* @param {object} body
|
|
35
|
+
*/
|
|
36
|
+
function json(response, status, body) {
|
|
37
|
+
response.writeHead(status, {
|
|
38
|
+
'content-type': 'application/json; charset=utf-8',
|
|
39
|
+
'cache-control': 'no-store',
|
|
40
|
+
});
|
|
41
|
+
response.end(`${JSON.stringify(body)}\n`);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @returns {{ snapshotId: string, path: string, databasePath: string } | null}
|
|
46
|
+
*/
|
|
47
|
+
function currentSnapshot() {
|
|
48
|
+
if (!fs.existsSync(pointerPath)) return null;
|
|
49
|
+
const pointer = JSON.parse(fs.readFileSync(pointerPath, 'utf8'));
|
|
50
|
+
const databasePath = path.resolve(localRoot, pointer.path);
|
|
51
|
+
// Security check: ensure path stays within local analytics directory
|
|
52
|
+
if (!databasePath.startsWith(`${localRoot}${path.sep}`) || !fs.existsSync(databasePath)) {
|
|
53
|
+
throw new Error('The analytics snapshot pointer is invalid.');
|
|
54
|
+
}
|
|
55
|
+
return { ...pointer, databasePath };
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @template T
|
|
60
|
+
* @param {(db: sqlite3.Database) => Promise<T>} callback
|
|
61
|
+
* @returns {Promise<{ snapshot: object|null, result: T|null }>}
|
|
62
|
+
*/
|
|
63
|
+
async function withDatabase(callback) {
|
|
64
|
+
const snapshot = currentSnapshot();
|
|
65
|
+
if (!snapshot) return { snapshot: null, result: null };
|
|
66
|
+
const db = await openDatabase(snapshot.databasePath, sqlite3.OPEN_READONLY);
|
|
67
|
+
try {
|
|
68
|
+
return { snapshot, result: await callback(db) };
|
|
69
|
+
} finally {
|
|
70
|
+
await closeDatabase(db);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Constructs the response payload for `/api/status`.
|
|
76
|
+
*/
|
|
77
|
+
async function statusResponse() {
|
|
78
|
+
const { snapshot, result } = await withDatabase(async (db) => {
|
|
79
|
+
const metadata = await get(db, 'SELECT * FROM meta_snapshot LIMIT 1');
|
|
80
|
+
const datasetMetadata = await all(
|
|
81
|
+
db,
|
|
82
|
+
'SELECT * FROM meta_dataset ORDER BY dataset_id',
|
|
83
|
+
);
|
|
84
|
+
return { metadata, datasets: datasetMetadata };
|
|
85
|
+
});
|
|
86
|
+
if (!snapshot) {
|
|
87
|
+
return {
|
|
88
|
+
available: false,
|
|
89
|
+
message: 'No local analytics snapshot exists yet. Run npm run analytics:refresh.',
|
|
90
|
+
datasets: datasets.map(({ id, grain, privacy }) => ({ id, grain, privacy })),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
return {
|
|
94
|
+
available: true,
|
|
95
|
+
snapshot: result.metadata,
|
|
96
|
+
datasets: result.datasets,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Constructs the response payload for `/api/datasets/:id`.
|
|
102
|
+
* @param {object} dataset
|
|
103
|
+
* @param {URL} url
|
|
104
|
+
*/
|
|
105
|
+
async function datasetResponse(dataset, url) {
|
|
106
|
+
const query = queryForDataset(dataset, url);
|
|
107
|
+
const { snapshot, result } = await withDatabase(async (db) => {
|
|
108
|
+
const rows = await all(db, query.sql, query.params);
|
|
109
|
+
const count = await get(db, `SELECT COUNT(*) AS count FROM ${quoteIdentifier(dataset.table)}`);
|
|
110
|
+
return { rows, totalRows: count.count };
|
|
111
|
+
});
|
|
112
|
+
if (!snapshot) return null;
|
|
113
|
+
return {
|
|
114
|
+
datasetId: dataset.id,
|
|
115
|
+
snapshotId: snapshot.snapshotId,
|
|
116
|
+
grain: dataset.grain,
|
|
117
|
+
privacy: dataset.privacy,
|
|
118
|
+
rows: result.rows,
|
|
119
|
+
totalRows: result.totalRows,
|
|
120
|
+
limit: query.limit,
|
|
121
|
+
offset: query.offset,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* @param {string} filename
|
|
127
|
+
* @returns {string}
|
|
128
|
+
*/
|
|
129
|
+
function contentType(filename) {
|
|
130
|
+
const extension = path.extname(filename);
|
|
131
|
+
return {
|
|
132
|
+
'.html': 'text/html; charset=utf-8',
|
|
133
|
+
'.js': 'text/javascript; charset=utf-8',
|
|
134
|
+
'.css': 'text/css; charset=utf-8',
|
|
135
|
+
'.json': 'application/json; charset=utf-8',
|
|
136
|
+
'.png': 'image/png',
|
|
137
|
+
'.ico': 'image/x-icon',
|
|
138
|
+
'.woff2': 'font/woff2',
|
|
139
|
+
}[extension] || 'application/octet-stream';
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Serves static build assets for the Angular frontend app.
|
|
144
|
+
*/
|
|
145
|
+
function serveClient(requestPath, response) {
|
|
146
|
+
if (!fs.existsSync(clientRoot)) {
|
|
147
|
+
json(response, 404, {
|
|
148
|
+
error: 'The analytics client has not been built. Run npm run analytics:build.',
|
|
149
|
+
});
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const relativePath = requestPath === '/' ? 'index.html' : requestPath.replace(/^\/+/, '');
|
|
153
|
+
let filename = path.resolve(clientRoot, relativePath);
|
|
154
|
+
if (!filename.startsWith(`${clientRoot}${path.sep}`) || !fs.existsSync(filename)) {
|
|
155
|
+
filename = path.join(clientRoot, 'index.html');
|
|
156
|
+
}
|
|
157
|
+
response.writeHead(200, { 'content-type': contentType(filename) });
|
|
158
|
+
fs.createReadStream(filename).pipe(response);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Instantiate native Node.js HTTP server
|
|
162
|
+
const server = http.createServer(async (request, response) => {
|
|
163
|
+
const url = new URL(request.url || '/', `http://${request.headers.host || 'localhost'}`);
|
|
164
|
+
try {
|
|
165
|
+
if (request.method === 'GET' && url.pathname === '/api/status') {
|
|
166
|
+
json(response, 200, await statusResponse());
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
if (request.method === 'GET' && url.pathname.startsWith('/api/datasets/')) {
|
|
170
|
+
const id = decodeURIComponent(url.pathname.slice('/api/datasets/'.length));
|
|
171
|
+
const dataset = datasetsById.get(id);
|
|
172
|
+
if (!dataset) {
|
|
173
|
+
json(response, 404, { error: `Unknown dataset "${id}".` });
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const body = await datasetResponse(dataset, url);
|
|
177
|
+
if (!body) {
|
|
178
|
+
json(response, 503, {
|
|
179
|
+
error: 'No analytics snapshot is available. Run npm run analytics:refresh.',
|
|
180
|
+
});
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
json(response, 200, body);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (url.pathname.startsWith('/api/')) {
|
|
187
|
+
json(response, 404, { error: 'Unknown analytics API route.' });
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
serveClient(url.pathname, response);
|
|
191
|
+
} catch (error) {
|
|
192
|
+
json(response, 400, { error: error.message });
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
// Handle server startup errors (e.g. port conflicts)
|
|
197
|
+
server.on('error', (error) => {
|
|
198
|
+
if (error.code === 'EADDRINUSE') {
|
|
199
|
+
console.error(
|
|
200
|
+
`${appName} analytics data port ${port} is already in use. ` +
|
|
201
|
+
'Stop the previous analytics process and try again.',
|
|
202
|
+
);
|
|
203
|
+
process.exitCode = 1;
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
throw error;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
// Start listening on loopback interface
|
|
210
|
+
server.listen(port, '127.0.0.1', () => {
|
|
211
|
+
console.log(`Analytics data service listening on http://127.0.0.1:${port}`);
|
|
212
|
+
});
|
|
@@ -73,6 +73,10 @@
|
|
|
73
73
|
{
|
|
74
74
|
"replace": "src/environments/environment.ts",
|
|
75
75
|
"with": "src/environments/environment.prod.ts"
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
"replace": "src/app/core/firebase/data.providers.ts",
|
|
79
|
+
"with": "src/app/core/firebase/data.providers.prod.ts"
|
|
76
80
|
}
|
|
77
81
|
],
|
|
78
82
|
"outputHashing": "all"
|
|
@@ -110,7 +114,7 @@
|
|
|
110
114
|
{
|
|
111
115
|
"glob": "**/*",
|
|
112
116
|
"input": "public"
|
|
113
|
-
}
|
|
117
|
+
}
|
|
114
118
|
],
|
|
115
119
|
"styles": [
|
|
116
120
|
"@angular/material/prebuilt-themes/azure-blue.css",
|
|
@@ -129,6 +133,81 @@
|
|
|
129
133
|
}
|
|
130
134
|
}
|
|
131
135
|
}
|
|
136
|
+
},
|
|
137
|
+
"analytics": {
|
|
138
|
+
"projectType": "application",
|
|
139
|
+
"root": "projects/analytics",
|
|
140
|
+
"sourceRoot": "projects/analytics/src",
|
|
141
|
+
"prefix": "analytics",
|
|
142
|
+
"schematics": {
|
|
143
|
+
"@schematics/angular:component": {
|
|
144
|
+
"style": "scss"
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
"architect": {
|
|
148
|
+
"build": {
|
|
149
|
+
"builder": "@angular/build:application",
|
|
150
|
+
"options": {
|
|
151
|
+
"outputPath": "dist/analytics",
|
|
152
|
+
"index": "projects/analytics/src/index.html",
|
|
153
|
+
"browser": "projects/analytics/src/main.ts",
|
|
154
|
+
"polyfills": [],
|
|
155
|
+
"tsConfig": "projects/analytics/tsconfig.app.json",
|
|
156
|
+
"inlineStyleLanguage": "scss",
|
|
157
|
+
"assets": [],
|
|
158
|
+
"styles": [
|
|
159
|
+
"@angular/material/prebuilt-themes/azure-blue.css",
|
|
160
|
+
"projects/analytics/src/styles.scss"
|
|
161
|
+
]
|
|
162
|
+
},
|
|
163
|
+
"configurations": {
|
|
164
|
+
"production": {
|
|
165
|
+
"outputHashing": "all",
|
|
166
|
+
"budgets": [
|
|
167
|
+
{
|
|
168
|
+
"type": "initial",
|
|
169
|
+
"maximumWarning": "2mb",
|
|
170
|
+
"maximumError": "4mb"
|
|
171
|
+
}
|
|
172
|
+
]
|
|
173
|
+
},
|
|
174
|
+
"development": {
|
|
175
|
+
"optimization": false,
|
|
176
|
+
"extractLicenses": false,
|
|
177
|
+
"sourceMap": true
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
"defaultConfiguration": "production"
|
|
181
|
+
},
|
|
182
|
+
"serve": {
|
|
183
|
+
"builder": "@angular/build:dev-server",
|
|
184
|
+
"configurations": {
|
|
185
|
+
"production": {
|
|
186
|
+
"buildTarget": "analytics:build:production"
|
|
187
|
+
},
|
|
188
|
+
"development": {
|
|
189
|
+
"buildTarget": "analytics:build:development"
|
|
190
|
+
}
|
|
191
|
+
},
|
|
192
|
+
"defaultConfiguration": "development"
|
|
193
|
+
},
|
|
194
|
+
"test": {
|
|
195
|
+
"builder": "@angular/build:unit-test",
|
|
196
|
+
"options": {
|
|
197
|
+
"tsConfig": "projects/analytics/tsconfig.spec.json",
|
|
198
|
+
"buildTarget": "analytics:build"
|
|
199
|
+
}
|
|
200
|
+
},
|
|
201
|
+
"lint": {
|
|
202
|
+
"builder": "@angular-eslint/builder:lint",
|
|
203
|
+
"options": {
|
|
204
|
+
"lintFilePatterns": [
|
|
205
|
+
"projects/analytics/src/**/*.ts",
|
|
206
|
+
"projects/analytics/src/**/*.html"
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
132
211
|
}
|
|
133
212
|
},
|
|
134
213
|
"schematics": {
|
|
@@ -1,26 +1,45 @@
|
|
|
1
|
-
--
|
|
2
|
-
--
|
|
3
|
-
--
|
|
4
|
-
--
|
|
1
|
+
-- Metric contract: active-time distribution by normalized route.
|
|
2
|
+
-- Purpose: Show how much foreground/active time was recorded for every route
|
|
3
|
+
-- visit, including the raw visit count and the five-number active-time summary.
|
|
4
|
+
-- Grain: One output row per normalized route; each input row is one finalized
|
|
5
|
+
-- route telemetry segment, not one distinct user, device, or browser session.
|
|
6
|
+
-- Population: route_visit events with positive active time. Anonymous visits
|
|
7
|
+
-- remain eligible. When @excludeAdmin is true, only rows carrying a known admin
|
|
8
|
+
-- user_id are removed; pre-auth rows with user_id IS NULL remain raw visits.
|
|
9
|
+
-- Route handling: query strings are removed and identifier-like path segments
|
|
10
|
+
-- (Firebase IDs, UUIDs, or long hashes) are replaced with /:id.
|
|
11
|
+
-- Parameters: @excludeAdmin controls admin filtering. @idSalt must be the same
|
|
12
|
+
-- salt used to build analytics.dim_user or the pseudonymous join cannot match.
|
|
13
|
+
-- SQL approach: prepare one active_seconds value per visit, GROUP BY normalized
|
|
14
|
+
-- route, then use APPROX_QUANTILES(..., 4) for min/Q1/median/Q3/max.
|
|
5
15
|
|
|
6
16
|
WITH route_visit_times AS (
|
|
17
|
+
-- Keep visit-level observations intact so COUNT(*) remains a raw segment count.
|
|
7
18
|
SELECT
|
|
8
|
-
|
|
9
|
-
|
|
19
|
+
CASE
|
|
20
|
+
WHEN REGEXP_CONTAINS(SPLIT(route, '?')[SAFE_OFFSET(0)], r'/([a-zA-Z0-9_-]{16,}|[0-9a-fA-F-]{36})')
|
|
21
|
+
THEN REGEXP_REPLACE(SPLIT(route, '?')[SAFE_OFFSET(0)], r'/([a-zA-Z0-9_-]{16,}|[0-9a-fA-F-]{36})', '/:id')
|
|
22
|
+
ELSE SPLIT(route, '?')[SAFE_OFFSET(0)]
|
|
23
|
+
END AS route,
|
|
10
24
|
total_active_ms / 1000.0 AS active_seconds
|
|
11
25
|
FROM
|
|
12
26
|
`analytics.events_flat`
|
|
13
27
|
WHERE
|
|
14
28
|
event_type = 'route_visit'
|
|
15
29
|
AND total_active_ms > 0
|
|
30
|
+
AND (
|
|
31
|
+
NOT @excludeAdmin
|
|
32
|
+
OR user_id IS NULL
|
|
33
|
+
OR TO_HEX(SHA256(CONCAT(@idSalt, ':', user_id, ':', @idSalt))) NOT IN (
|
|
34
|
+
SELECT user_key FROM `analytics.dim_user` WHERE role = 'admin'
|
|
35
|
+
)
|
|
36
|
+
)
|
|
16
37
|
)
|
|
17
38
|
|
|
18
39
|
SELECT
|
|
19
40
|
route,
|
|
20
41
|
COUNT(*) AS total_visits,
|
|
21
42
|
ROUND(AVG(active_seconds), 2) AS mean_active_seconds,
|
|
22
|
-
|
|
23
|
-
-- APPROX_QUANTILES returns a 5-element array: [Min, 25th (Q1), 50th (Median), 75th (Q3), Max]
|
|
24
43
|
ROUND(APPROX_QUANTILES(active_seconds, 4)[OFFSET(0)], 2) AS min_active_seconds,
|
|
25
44
|
ROUND(APPROX_QUANTILES(active_seconds, 4)[OFFSET(1)], 2) AS q1_active_seconds,
|
|
26
45
|
ROUND(APPROX_QUANTILES(active_seconds, 4)[OFFSET(2)], 2) AS median_active_seconds,
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
-- Metric contract: daily, trailing-7-day, and trailing-30-day active identities.
|
|
2
|
+
-- Purpose: Count how many identities recorded positive active time on each
|
|
3
|
+
-- UTC calendar day and within the trailing windows ending on that day.
|
|
4
|
+
-- Grain: One output row per observed activity date. Dates with no active event
|
|
5
|
+
-- are not synthesized, so the result is not a gap-filled calendar series.
|
|
6
|
+
-- Identity: prefer the event user_id; otherwise attribute the event to the first
|
|
7
|
+
-- user ever observed on that device; otherwise use anonymous:<device_id>.
|
|
8
|
+
-- Session IDs are not identities. Device attribution prevents the same person
|
|
9
|
+
-- from being counted once anonymously and again after authenticating.
|
|
10
|
+
-- Population: positive-active-time route visits with device and timestamp.
|
|
11
|
+
-- When @excludeAdmin is true, both signed-in admin visits and earlier anonymous
|
|
12
|
+
-- visits on a device later associated with that admin are excluded.
|
|
13
|
+
-- Time: activity dates use America/Los_Angeles timezone.
|
|
14
|
+
-- SQL approach: collapse to distinct identity/day pairs, generate reporting
|
|
15
|
+
-- dates from observed days, and conditionally COUNT DISTINCT identities in the
|
|
16
|
+
-- 1-, 7-, and 30-day ranges ending on each reporting date.
|
|
17
|
+
|
|
18
|
+
WITH known_user_by_device AS (
|
|
19
|
+
-- Resolve an eventual account for each device so pre-auth activity can be
|
|
20
|
+
-- attributed consistently. ARRAY_AGG returns NULL for never-identified devices.
|
|
21
|
+
SELECT
|
|
22
|
+
device_id,
|
|
23
|
+
ARRAY_AGG(user_id IGNORE NULLS ORDER BY timestamp LIMIT 1)[SAFE_OFFSET(0)] AS user_id
|
|
24
|
+
FROM `analytics.events_flat`
|
|
25
|
+
WHERE device_id IS NOT NULL
|
|
26
|
+
GROUP BY device_id
|
|
27
|
+
),
|
|
28
|
+
active_days AS (
|
|
29
|
+
-- DISTINCT makes multiple visits by the same identity on one day count once.
|
|
30
|
+
SELECT DISTINCT
|
|
31
|
+
COALESCE(event.user_id, known.user_id, CONCAT('anonymous:', event.device_id)) AS identity_key,
|
|
32
|
+
DATE(TIMESTAMP_MILLIS(event.timestamp), 'America/Los_Angeles') AS active_date
|
|
33
|
+
FROM `analytics.events_flat` AS event
|
|
34
|
+
LEFT JOIN known_user_by_device AS known USING (device_id)
|
|
35
|
+
WHERE event.event_type = 'route_visit'
|
|
36
|
+
AND event.device_id IS NOT NULL
|
|
37
|
+
AND event.timestamp IS NOT NULL
|
|
38
|
+
AND event.total_active_ms > 0
|
|
39
|
+
AND (
|
|
40
|
+
NOT @excludeAdmin
|
|
41
|
+
OR COALESCE(event.user_id, known.user_id) IS NULL
|
|
42
|
+
OR TO_HEX(SHA256(CONCAT(@idSalt, ':', COALESCE(event.user_id, known.user_id), ':', @idSalt))) NOT IN (
|
|
43
|
+
SELECT user_key FROM `analytics.dim_user` WHERE role = 'admin'
|
|
44
|
+
)
|
|
45
|
+
)
|
|
46
|
+
),
|
|
47
|
+
reporting_dates AS (
|
|
48
|
+
-- Only dates represented in active_days become reporting endpoints.
|
|
49
|
+
SELECT DISTINCT active_date AS reporting_date
|
|
50
|
+
FROM active_days
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
SELECT
|
|
54
|
+
CAST(reporting_date AS STRING) AS activity_date,
|
|
55
|
+
COUNT(DISTINCT IF(active_date = reporting_date, identity_key, NULL)) AS dau,
|
|
56
|
+
COUNT(DISTINCT IF(active_date BETWEEN DATE_SUB(reporting_date, INTERVAL 6 DAY) AND reporting_date, identity_key, NULL)) AS wau,
|
|
57
|
+
COUNT(DISTINCT IF(active_date BETWEEN DATE_SUB(reporting_date, INTERVAL 29 DAY) AND reporting_date, identity_key, NULL)) AS mau
|
|
58
|
+
FROM
|
|
59
|
+
reporting_dates
|
|
60
|
+
JOIN
|
|
61
|
+
active_days
|
|
62
|
+
ON
|
|
63
|
+
active_days.active_date BETWEEN DATE_SUB(reporting_date, INTERVAL 29 DAY) AND reporting_date
|
|
64
|
+
GROUP BY
|
|
65
|
+
reporting_date
|
|
66
|
+
ORDER BY
|
|
67
|
+
reporting_date;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
-- Dataset contract: de-identified route-visit fact rows for the local snapshot.
|
|
2
|
+
-- Purpose: Preserve visit-level timing while replacing every linkable raw ID
|
|
3
|
+
-- with a stable salted SHA-256 key and normalizing dynamic route segments.
|
|
4
|
+
-- Grain: One output row per finalized route_visit telemetry document.
|
|
5
|
+
-- Required fields: device_id, session_id, and timestamp. Anonymous user_id is
|
|
6
|
+
-- allowed and produces user_key = NULL.
|
|
7
|
+
-- Keys: visit_key hashes document_id; journey_key hashes device_id; session_key
|
|
8
|
+
-- hashes session_id; user_key hashes user_id. The same @idSalt intentionally
|
|
9
|
+
-- makes keys joinable across snapshot datasets but sensitive if disclosed.
|
|
10
|
+
-- Admin semantics: @excludeAdmin removes visits whose row has an admin user_id.
|
|
11
|
+
-- Anonymous/pre-auth rows remain even if their device later signs in as admin;
|
|
12
|
+
-- this fact dataset intentionally represents raw recorded visits.
|
|
13
|
+
-- SQL approach: SELECT only the allowlisted fields, hash identifiers in BigQuery,
|
|
14
|
+
-- strip query strings, collapse identifier-like paths to /:id, and filter rows.
|
|
15
|
+
|
|
16
|
+
SELECT
|
|
17
|
+
-- TO_HEX(SHA256(...)) returns lowercase hex; entity-derived keys must use
|
|
18
|
+
-- the same casing and exact salt/input framing for equality joins.
|
|
19
|
+
TO_HEX(SHA256(CONCAT(@idSalt, ':', document_id, ':', @idSalt))) AS visit_key,
|
|
20
|
+
TO_HEX(SHA256(CONCAT(@idSalt, ':', device_id, ':', @idSalt))) AS journey_key,
|
|
21
|
+
TO_HEX(SHA256(CONCAT(@idSalt, ':', session_id, ':', @idSalt))) AS session_key,
|
|
22
|
+
CASE
|
|
23
|
+
WHEN user_id IS NULL THEN NULL
|
|
24
|
+
ELSE TO_HEX(SHA256(CONCAT(@idSalt, ':', user_id, ':', @idSalt)))
|
|
25
|
+
END AS user_key,
|
|
26
|
+
CASE
|
|
27
|
+
WHEN REGEXP_CONTAINS(SPLIT(route, '?')[SAFE_OFFSET(0)], r'/([a-zA-Z0-9_-]{16,}|[0-9a-fA-F-]{36})')
|
|
28
|
+
THEN REGEXP_REPLACE(SPLIT(route, '?')[SAFE_OFFSET(0)], r'/([a-zA-Z0-9_-]{16,}|[0-9a-fA-F-]{36})', '/:id')
|
|
29
|
+
ELSE SPLIT(route, '?')[SAFE_OFFSET(0)]
|
|
30
|
+
END AS route,
|
|
31
|
+
timestamp AS started_at_ms,
|
|
32
|
+
total_active_ms AS active_ms,
|
|
33
|
+
total_rest_ms AS rest_ms
|
|
34
|
+
FROM
|
|
35
|
+
`analytics.events_flat`
|
|
36
|
+
WHERE
|
|
37
|
+
event_type = 'route_visit'
|
|
38
|
+
AND device_id IS NOT NULL
|
|
39
|
+
AND session_id IS NOT NULL
|
|
40
|
+
AND timestamp IS NOT NULL
|
|
41
|
+
AND (
|
|
42
|
+
NOT @excludeAdmin
|
|
43
|
+
OR user_id IS NULL
|
|
44
|
+
OR TO_HEX(SHA256(CONCAT(@idSalt, ':', user_id, ':', @idSalt))) NOT IN (
|
|
45
|
+
SELECT user_key FROM `analytics.dim_user` WHERE role = 'admin'
|
|
46
|
+
)
|
|
47
|
+
);
|