@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.
Files changed (229) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +266 -1
  3. package/package.json +34 -7
  4. package/src/component/files/__name@dasherize__/__name@dasherize__.component.spec.ts.template +4 -5
  5. package/src/component/files/__name@dasherize__/__name@dasherize__.component.ts.template +1 -1
  6. package/src/entity/files/__name@dasherize__/__name@dasherize__.mock.ts.template +14 -6
  7. package/src/entity/files/__name@dasherize__/__name@dasherize__.model.ts.template +12 -6
  8. package/src/entity/files/__name@dasherize__/__name@dasherize__.store.ts.template +18 -10
  9. package/src/entity/index.js +4 -49
  10. package/src/entity/index.js.map +1 -1
  11. package/src/guard/files/__name@dasherize__.guard.spec.ts.template +0 -1
  12. package/src/ng-add/files/.github/workflows/angular-github-ci.yml.template +3 -0
  13. package/src/ng-add/files/.gitignore.template +3 -0
  14. package/src/ng-add/files/analytics/datasets.js.template +206 -0
  15. package/src/ng-add/files/analytics/entity_sources.js.template +58 -0
  16. package/src/ng-add/files/analytics/entity_sources.test.js.template +57 -0
  17. package/src/ng-add/files/analytics/lib/api_query.js.template +87 -0
  18. package/src/ng-add/files/analytics/lib/api_query.test.js.template +84 -0
  19. package/src/ng-add/files/analytics/lib/bigquery_query_compatibility.test.js.template +53 -0
  20. package/src/ng-add/files/analytics/lib/dataset_schema.js.template +53 -0
  21. package/src/ng-add/files/analytics/lib/dataset_schema.test.js.template +34 -0
  22. package/src/ng-add/files/analytics/lib/entity_sync.js.template +397 -0
  23. package/src/ng-add/files/analytics/lib/entity_sync.test.js.template +212 -0
  24. package/src/ng-add/files/analytics/lib/identifier_salt.js.template +57 -0
  25. package/src/ng-add/files/analytics/lib/identifier_salt.test.js.template +36 -0
  26. package/src/ng-add/files/analytics/lib/snapshot_files.js.template +46 -0
  27. package/src/ng-add/files/analytics/lib/snapshot_files.test.js.template +67 -0
  28. package/src/ng-add/files/analytics/lib/sqlite.js.template +92 -0
  29. package/src/ng-add/files/analytics/lib/upload_entities.js.template +81 -0
  30. package/src/ng-add/files/analytics/lib/upload_entities.test.js.template +86 -0
  31. package/src/ng-add/files/analytics/proxy.conf.json.template +7 -0
  32. package/src/ng-add/files/analytics/scripts/refresh_snapshot.js.template +518 -0
  33. package/src/ng-add/files/analytics/scripts/start.js.template +88 -0
  34. package/src/ng-add/files/analytics/server/server.js.template +212 -0
  35. package/src/ng-add/files/angular.json.template +80 -1
  36. package/src/ng-add/files/bigquery/queries/active_time_by_route.sql.template +27 -8
  37. package/src/ng-add/files/bigquery/queries/active_user_windows.sql.template +67 -0
  38. package/src/ng-add/files/bigquery/queries/dashboard_route_visits.sql.template +47 -0
  39. package/src/ng-add/files/bigquery/queries/data_quality.sql.template +323 -0
  40. package/src/ng-add/files/bigquery/queries/onboarding_funnel.sql.template +512 -0
  41. package/src/ng-add/files/bigquery/queries/onboarding_stage_observations.sql.template +134 -0
  42. package/src/ng-add/files/bigquery/queries/weekly_retention_cohorts.sql.template +90 -0
  43. package/src/ng-add/files/bigquery/scripts/export_entities.js.template +120 -0
  44. package/src/ng-add/files/bigquery/scripts/init_views.js.template +57 -0
  45. package/src/ng-add/files/bigquery/scripts/run_query.js.template +141 -0
  46. package/src/ng-add/files/bigquery/views/events_flat.sql.template +27 -12
  47. package/src/ng-add/files/bigquery/views/logs_latest.sql.template +16 -3
  48. package/src/ng-add/files/docs-infra/analytics-guide.md.template +270 -25
  49. package/src/ng-add/files/docs-infra/analytics-workbench-guide.md.template +307 -0
  50. package/src/ng-add/files/docs-infra/authentication-architecture.md.template +54 -24
  51. package/src/ng-add/files/docs-infra/email-infrastructure.md.template +43 -0
  52. package/src/ng-add/files/docs-infra/firestore-index-checker.md.template +87 -0
  53. package/src/ng-add/files/docs-infra/infrastructure-guide.md.template +108 -29
  54. package/src/ng-add/files/docs-infra/load-system-architecture.md.template +15 -1
  55. package/src/ng-add/files/docs-infra/querying-strategy.md.template +14 -0
  56. package/src/ng-add/files/docs-infra/stream-system-architecture.md.template +21 -7
  57. package/src/ng-add/files/eslint.config.js.template +22 -3
  58. package/src/ng-add/files/functions/package.json.template +1 -0
  59. package/src/ng-add/files/functions/src/email.ts.template +23 -0
  60. package/src/ng-add/files/jest.config.ts.template +3 -2
  61. package/src/ng-add/files/package.json.template +39 -16
  62. package/src/ng-add/files/projects/analytics/src/app/analytics-api.service.ts.template +130 -0
  63. package/src/ng-add/files/projects/analytics/src/app/app.component.html.template +77 -0
  64. package/src/ng-add/files/projects/analytics/src/app/app.component.scss.template +240 -0
  65. package/src/ng-add/files/projects/analytics/src/app/app.component.ts.template +96 -0
  66. package/src/ng-add/files/projects/analytics/src/app/app.routes.ts.template +11 -0
  67. package/src/ng-add/files/projects/analytics/src/app/dashboard-pages.spec.ts.template +151 -0
  68. package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.html.template +39 -0
  69. package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.scss.template +1 -0
  70. package/src/ng-add/files/projects/analytics/src/app/data-quality/data-quality-page/data-quality-page.component.ts.template +95 -0
  71. package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.html.template +47 -0
  72. package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.scss.template +1 -0
  73. package/src/ng-add/files/projects/analytics/src/app/engagement/engagement-page/engagement-page.component.ts.template +120 -0
  74. package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.html.template +40 -0
  75. package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.scss.template +1 -0
  76. package/src/ng-add/files/projects/analytics/src/app/onboarding/onboarding-page/onboarding-page.component.ts.template +98 -0
  77. package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.html.template +35 -0
  78. package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.scss.template +1 -0
  79. package/src/ng-add/files/projects/analytics/src/app/overview/overview-page/overview-page.component.ts.template +84 -0
  80. package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.html.template +42 -0
  81. package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.scss.template +1 -0
  82. package/src/ng-add/files/projects/analytics/src/app/routes/routes-page/routes-page.component.ts.template +110 -0
  83. package/src/ng-add/files/projects/analytics/src/app/shared/analytics-utils.ts.template +43 -0
  84. package/src/ng-add/files/projects/analytics/src/app/shared/chart-theme.ts.template +42 -0
  85. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-layout.scss.template +239 -0
  86. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.html.template +76 -0
  87. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.scss.template +128 -0
  88. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.spec.ts.template +31 -0
  89. package/src/ng-add/files/projects/analytics/src/app/shared/dashboard-table/dashboard-table.component.ts.template +153 -0
  90. package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.html.template +16 -0
  91. package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.scss.template +63 -0
  92. package/src/ng-add/files/projects/analytics/src/app/shared/funnel-chart/funnel-chart.component.ts.template +52 -0
  93. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.html.template +5 -0
  94. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.scss.template +56 -0
  95. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.spec.ts.template +30 -0
  96. package/src/ng-add/files/projects/analytics/src/app/shared/metric-card/metric-card.component.ts.template +15 -0
  97. package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.html.template +9 -0
  98. package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.scss.template +43 -0
  99. package/src/ng-add/files/projects/analytics/src/app/shared/quality-chart/quality-chart.component.ts.template +62 -0
  100. package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.html.template +9 -0
  101. package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.scss.template +33 -0
  102. package/src/ng-add/files/projects/analytics/src/app/shared/route-distribution-chart/route-distribution-chart.component.ts.template +82 -0
  103. package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.html.template +15 -0
  104. package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.scss.template +45 -0
  105. package/src/ng-add/files/projects/analytics/src/app/shared/route-traffic-chart/route-traffic-chart.component.ts.template +55 -0
  106. package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.html.template +18 -0
  107. package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.scss.template +45 -0
  108. package/src/ng-add/files/projects/analytics/src/app/shared/status-message/status-message.component.ts.template +15 -0
  109. package/src/ng-add/files/projects/analytics/src/app/vega-chart/vega-chart.component.ts.template +121 -0
  110. package/src/ng-add/files/projects/analytics/src/index.html.template +19 -0
  111. package/src/ng-add/files/projects/analytics/src/main.ts.template +16 -0
  112. package/src/ng-add/files/projects/analytics/src/styles.scss.template +28 -0
  113. package/src/ng-add/files/projects/analytics/tsconfig.app.json.template +13 -0
  114. package/src/ng-add/files/projects/analytics/tsconfig.spec.json.template +15 -0
  115. package/src/ng-add/files/src/app/admin/admin-panel/admin-panel.component.spec.ts.template +4 -5
  116. package/src/ng-add/files/src/app/admin/admin-panel/admin-settings/admin-settings.component.spec.ts.template +4 -5
  117. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.spec.ts.template +11 -12
  118. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-list.component.ts.template +7 -7
  119. 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
  120. package/src/ng-add/files/src/app/admin/admin-panel/admin-user-list/admin-user-table/admin-user-table.component.ts.template +3 -2
  121. package/src/ng-add/files/src/app/app.component.html.template +1 -1
  122. package/src/ng-add/files/src/app/app.component.scss.template +1 -1
  123. package/src/ng-add/files/src/app/app.component.spec.ts.template +4 -5
  124. package/src/ng-add/files/src/app/app.component.ts.template +1 -2
  125. package/src/ng-add/files/src/app/app.config.ts.template +21 -15
  126. package/src/ng-add/files/src/app/auth-routing.spec.ts.template +4 -5
  127. package/src/ng-add/files/src/app/core/analytics/time-analytics.service.spec.ts.template +46 -29
  128. package/src/ng-add/files/src/app/core/analytics/time-analytics.service.ts.template +27 -18
  129. package/src/ng-add/files/src/app/core/auth/auth.providers.spec.ts.template +112 -0
  130. package/src/ng-add/files/src/app/core/auth/auth.providers.ts.template +48 -0
  131. package/src/ng-add/files/src/app/core/auth/auth.service.ts.template +9 -23
  132. package/src/ng-add/files/src/app/core/auth/guards/require-admin.guard.spec.ts.template +3 -14
  133. package/src/ng-add/files/src/app/core/firebase/data.providers.prod.ts.template +21 -0
  134. package/src/ng-add/files/src/app/core/firebase/data.providers.ts.template +13 -0
  135. package/src/ng-add/files/src/app/core/local-storage/session.service.spec.ts.template +43 -0
  136. package/src/ng-add/files/src/app/core/local-storage/session.service.ts.template +7 -0
  137. package/src/ng-add/files/src/app/core/store/app-data.spec.ts.template +76 -0
  138. package/src/ng-add/files/src/app/core/store/auth/auth.mock.ts.template +19 -67
  139. package/src/ng-add/files/src/app/core/store/auth/auth.store.spec.ts.template +102 -12
  140. package/src/ng-add/files/src/app/core/store/auth/auth.store.ts.template +32 -237
  141. package/src/ng-add/files/src/app/core/store/user/user.mock.ts.template +17 -12
  142. package/src/ng-add/files/src/app/core/store/user/user.model.ts.template +6 -7
  143. package/src/ng-add/files/src/app/core/store/user/user.store.ts.template +14 -10
  144. package/src/ng-add/files/src/app/core/store/user-context/user-context.mock.ts.template +20 -8
  145. package/src/ng-add/files/src/app/core/store/user-context/user-context.model.ts.template +5 -6
  146. package/src/ng-add/files/src/app/core/store/user-context/user-context.store.ts.template +14 -10
  147. package/src/ng-add/files/src/app/core/store/user-private/user-private.mock.ts.template +20 -7
  148. package/src/ng-add/files/src/app/core/store/user-private/user-private.model.ts.template +5 -6
  149. package/src/ng-add/files/src/app/core/store/user-private/user-private.store.ts.template +14 -10
  150. package/src/ng-add/files/src/app/core/testing/app-mocks.ts.template +42 -0
  151. package/src/ng-add/files/src/app/first-time/consent/consent.component.html.template +2 -1
  152. package/src/ng-add/files/src/app/first-time/consent/consent.component.scss.template +7 -3
  153. package/src/ng-add/files/src/app/first-time/consent/consent.component.spec.ts.template +31 -11
  154. package/src/ng-add/files/src/app/first-time/consent/consent.component.ts.template +16 -1
  155. package/src/ng-add/files/src/app/first-time/early-access/early-access.component.spec.ts.template +15 -15
  156. package/src/ng-add/files/src/app/first-time/early-access/early-access.component.ts.template +11 -3
  157. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.html.template +2 -1
  158. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.scss.template +7 -3
  159. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.spec.ts.template +20 -6
  160. package/src/ng-add/files/src/app/first-time/early-access/survey-form/survey-form.component.ts.template +2 -0
  161. package/src/ng-add/files/src/app/first-time/early-access/waitlist-view/waitlist-view.component.spec.ts.template +4 -5
  162. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.spec.ts.template +17 -1
  163. package/src/ng-add/files/src/app/first-time/email-link/email-link.component.ts.template +15 -0
  164. package/src/ng-add/files/src/app/first-time/first-time-routing.spec.ts.template +4 -5
  165. package/src/ng-add/files/src/app/first-time/landing/hero/hero.component.ts.template +15 -0
  166. package/src/ng-add/files/src/app/first-time/landing/landing.component.spec.ts.template +2 -0
  167. package/src/ng-add/files/src/app/first-time/login/login.component.spec.ts.template +21 -3
  168. package/src/ng-add/files/src/app/first-time/login/login.component.ts.template +26 -0
  169. package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.spec.ts.template +4 -2
  170. package/src/ng-add/files/src/app/first-time/onboarding/onboarding.component.ts.template +1 -1
  171. package/src/ng-add/files/src/app/main/account-profile/account-profile.component.spec.ts.template +2 -2
  172. package/src/ng-add/files/src/app/main/account-profile/delete-guest-card/delete-guest-card.component.spec.ts.template +2 -2
  173. package/src/ng-add/files/src/app/main/account-profile/profile-details-card/profile-details-card.component.spec.ts.template +4 -4
  174. package/src/ng-add/files/src/app/main/account-profile/sign-in-methods-card/sign-in-methods-card.component.spec.ts.template +2 -2
  175. package/src/ng-add/files/src/app/main/home/home.component.spec.ts.template +4 -5
  176. package/src/ng-add/files/src/app/main/home/home.component.ts.template +1 -1
  177. package/src/ng-add/files/src/app/shared/guest-warning-bar/guest-warning-bar.component.spec.ts.template +4 -4
  178. package/src/ng-add/files/src/app/shared/navbar/navbar.component.spec.ts.template +2 -2
  179. package/src/ng-add/files/tsconfig.spec.json.template +3 -1
  180. package/src/ng-add/index.js +7 -0
  181. package/src/ng-add/index.js.map +1 -1
  182. package/src/shared/entity-registry.d.ts +8 -0
  183. package/src/shared/entity-registry.js +28 -0
  184. package/src/shared/entity-registry.js.map +1 -0
  185. package/.agents/skills/publish-npm/SKILL.md +0 -37
  186. package/.agents/skills/publish-npm/eval.yaml +0 -32
  187. package/.agents/skills/publish-npm/fixtures/package-v21.json.template +0 -8
  188. package/.husky/commit-msg +0 -1
  189. package/.husky/pre-commit +0 -1
  190. package/.t4g/agent-memory.db +0 -0
  191. package/src/component/index_spec.d.ts +0 -1
  192. package/src/component/index_spec.js +0 -68
  193. package/src/component/index_spec.js.map +0 -1
  194. package/src/entity/index_spec.d.ts +0 -1
  195. package/src/entity/index_spec.js +0 -153
  196. package/src/entity/index_spec.js.map +0 -1
  197. package/src/guard/index_spec.d.ts +0 -1
  198. package/src/guard/index_spec.js +0 -64
  199. package/src/guard/index_spec.js.map +0 -1
  200. package/src/ng-add/files/bigquery/scripts/export_entities.py.template +0 -143
  201. package/src/ng-add/files/bigquery/scripts/run_query.py.template +0 -167
  202. package/src/ng-add/files/src/app/core/firebase/cached-listeners.service.ts.template +0 -500
  203. package/src/ng-add/files/src/app/core/firebase/database.service.ts.template +0 -73
  204. package/src/ng-add/files/src/app/core/firebase/email-link-context.service.spec.ts.template +0 -59
  205. package/src/ng-add/files/src/app/core/firebase/email-link-context.service.ts.template +0 -147
  206. package/src/ng-add/files/src/app/core/firebase/firebase.mock.service.ts.template +0 -453
  207. package/src/ng-add/files/src/app/core/firebase/firebase.service.spec.ts.template +0 -116
  208. package/src/ng-add/files/src/app/core/firebase/firebase.service.ts.template +0 -639
  209. package/src/ng-add/files/src/app/core/firebase/simulate-load.spec.ts.template +0 -104
  210. package/src/ng-add/files/src/app/core/firebase/simulate-stream.spec.ts.template +0 -127
  211. package/src/ng-add/files/src/app/core/firebase/simulation.mock.ts.template +0 -38
  212. package/src/ng-add/files/src/app/core/firebase/stream-multiplexer.ts.template +0 -445
  213. package/src/ng-add/files/src/app/core/logging/logging.service.spec.ts.template +0 -118
  214. package/src/ng-add/files/src/app/core/logging/logging.service.ts.template +0 -168
  215. package/src/ng-add/files/src/app/core/store/app.model.ts.template +0 -21
  216. package/src/ng-add/files/src/app/core/store/app.store.spec.ts.template +0 -920
  217. package/src/ng-add/files/src/app/core/store/app.store.ts.template +0 -1320
  218. package/src/ng-add/files/src/app/core/store/batch-write.firebase.service.ts.template +0 -58
  219. package/src/ng-add/files/src/app/core/store/batch-write.mock.service.ts.template +0 -105
  220. package/src/ng-add/files/src/app/core/store/batch-write.service.ts.template +0 -126
  221. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.html.template +0 -9
  222. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.scss.template +0 -46
  223. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.spec.ts.template +0 -69
  224. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.component.ts.template +0 -39
  225. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.spec.ts.template +0 -122
  226. package/src/ng-add/files/src/app/shared/redeployment-warning/redeployment-warning.service.ts.template +0 -88
  227. package/src/ng-add/index_spec.d.ts +0 -1
  228. package/src/ng-add/index_spec.js +0 -108
  229. package/src/ng-add/index_spec.js.map +0 -1
@@ -0,0 +1,512 @@
1
+ -- Metric contract: two sequential first-time conversion funnels.
2
+ -- Purpose: Separate acquisition before authentication from activation after a
3
+ -- genuinely first-time sign-in, rather than treating every later visit or login
4
+ -- as another opportunity to enter the funnel.
5
+ -- Grain: One output row per named stage in each analysis. `journeys` counts
6
+ -- distinct cohort identities reaching that stage; conversion_from_cohort uses
7
+ -- the fixed entry cohort as denominator, not the preceding stage.
8
+ -- pre_sign_in identity: device_id. A device enters at its earliest / or /landing
9
+ -- visit only if that landing predates every known-user/authentication signal.
10
+ -- post_sign_in identity: attributed user ID, using route user_id or a successful
11
+ -- auth_result's properties.authenticatedUserId. Users already complete at auth,
12
+ -- or historical users who go directly to home with no activation signals,
13
+ -- are intentionally excluded as returning users.
14
+ -- Sequence: later post-sign-in stages require the previous successful stage and
15
+ -- a nondecreasing timestamp, so incomplete telemetry cannot create an inverted
16
+ -- funnel. Zero means no qualifying observed path under these rules.
17
+ -- Admin parameters: @excludeAdmin filters attributed admin-user events through
18
+ -- analytics.dim_user; events with no attributed user remain eligible.
19
+ -- SQL approach: normalize identity/event fields, establish cohort-entry CTEs,
20
+ -- build stage-reach sets with UNION DISTINCT, count them, then LEFT JOIN fixed
21
+ -- stage definitions so stages with no observations still return explicit zeros.
22
+
23
+ WITH event_identity AS (
24
+ -- Normalize route and authentication identity once so both funnels use the
25
+ -- same event interpretation and optional admin filter.
26
+
27
+ SELECT
28
+ device_id,
29
+ user_id,
30
+ COALESCE(
31
+ user_id,
32
+ JSON_VALUE(SAFE.PARSE_JSON(properties), '$.authenticatedUserId')
33
+ ) AS attributed_user_id,
34
+ timestamp AS occurred_at_ms,
35
+ event_type,
36
+ SPLIT(route, '?')[SAFE_OFFSET(0)] AS route_path,
37
+ category,
38
+ action,
39
+ properties
40
+ FROM
41
+ `analytics.events_flat`
42
+ WHERE
43
+ device_id IS NOT NULL
44
+ AND (
45
+ NOT @excludeAdmin
46
+ OR COALESCE(user_id, JSON_VALUE(SAFE.PARSE_JSON(properties), '$.authenticatedUserId')) IS NULL
47
+ OR TO_HEX(SHA256(CONCAT(@idSalt, ':', COALESCE(user_id, JSON_VALUE(SAFE.PARSE_JSON(properties), '$.authenticatedUserId')), ':', @idSalt))) NOT IN (
48
+ SELECT user_key FROM `analytics.dim_user` WHERE role = 'admin'
49
+ )
50
+ )
51
+ ),
52
+
53
+ first_landing_by_device AS (
54
+
55
+ SELECT
56
+ device_id,
57
+ MIN(occurred_at_ms) AS cohort_started_at_ms
58
+ FROM
59
+ event_identity
60
+ WHERE
61
+ event_type = 'route_visit'
62
+ AND route_path IN ('/', '/landing')
63
+ GROUP BY
64
+ device_id
65
+ ),
66
+
67
+ first_known_user_by_device AS (
68
+
69
+ SELECT
70
+ device_id,
71
+ MIN(occurred_at_ms) AS first_known_user_at_ms
72
+ FROM
73
+ event_identity
74
+ WHERE
75
+ attributed_user_id IS NOT NULL
76
+ GROUP BY
77
+ device_id
78
+ ),
79
+
80
+ first_auth_by_device AS (
81
+
82
+ SELECT
83
+ device_id,
84
+ MIN(occurred_at_ms) AS authenticated_at_ms
85
+ FROM
86
+ event_identity
87
+ WHERE
88
+ event_type = 'interaction'
89
+ AND category = 'onboarding'
90
+ AND action = 'auth_result'
91
+ AND JSON_VALUE(SAFE.PARSE_JSON(properties), '$.outcome') = 'success'
92
+ GROUP BY
93
+ device_id
94
+ ),
95
+
96
+ pre_sign_in_cohort AS (
97
+ -- Devices that were truly anonymous at cohort entry. Later authentication is
98
+ -- allowed and becomes the final acquisition stage.
99
+ SELECT
100
+ landing.device_id,
101
+ landing.cohort_started_at_ms,
102
+ auth.authenticated_at_ms
103
+ FROM
104
+ first_landing_by_device AS landing
105
+ LEFT JOIN
106
+ first_known_user_by_device AS known_user
107
+ USING
108
+ (device_id)
109
+ LEFT JOIN
110
+ first_auth_by_device AS auth
111
+ USING
112
+ (device_id)
113
+ WHERE
114
+ -- Ensure device was not already authenticated
115
+ (
116
+ auth.authenticated_at_ms IS NULL
117
+ OR landing.cohort_started_at_ms < auth.authenticated_at_ms
118
+ )
119
+ AND (
120
+ known_user.first_known_user_at_ms IS NULL
121
+ OR landing.cohort_started_at_ms < known_user.first_known_user_at_ms
122
+ )
123
+ ),
124
+
125
+ pre_sign_in_reach AS (
126
+
127
+ -- Stage 10: Landing Page
128
+ SELECT
129
+ device_id,
130
+ 'Landing' AS stage,
131
+ 10 AS stage_order
132
+ FROM
133
+ pre_sign_in_cohort
134
+
135
+ UNION DISTINCT
136
+
137
+ -- Stage 20: Login Page Visit
138
+ SELECT
139
+ cohort.device_id,
140
+ 'Login' AS stage,
141
+ 20 AS stage_order
142
+ FROM
143
+ pre_sign_in_cohort AS cohort
144
+ JOIN
145
+ event_identity AS event
146
+ USING
147
+ (device_id)
148
+ WHERE
149
+ event.event_type = 'route_visit'
150
+ AND event.route_path = '/login'
151
+ AND event.occurred_at_ms >= cohort.cohort_started_at_ms
152
+ AND (
153
+ cohort.authenticated_at_ms IS NULL
154
+ OR event.occurred_at_ms <= cohort.authenticated_at_ms
155
+ )
156
+
157
+ UNION DISTINCT
158
+
159
+ -- Stage 30: Authentication Attempt Started
160
+ SELECT
161
+ cohort.device_id,
162
+ 'Authentication started' AS stage,
163
+ 30 AS stage_order
164
+ FROM
165
+ pre_sign_in_cohort AS cohort
166
+ JOIN
167
+ event_identity AS event
168
+ USING
169
+ (device_id)
170
+ WHERE
171
+ event.event_type = 'interaction'
172
+ AND event.category = 'onboarding'
173
+ AND event.action = 'auth_attempt'
174
+ AND event.occurred_at_ms >= cohort.cohort_started_at_ms
175
+ AND (
176
+ cohort.authenticated_at_ms IS NULL
177
+ OR event.occurred_at_ms <= cohort.authenticated_at_ms
178
+ )
179
+
180
+ UNION DISTINCT
181
+
182
+ -- Stage 40: Successful Sign-in
183
+ SELECT
184
+ cohort.device_id,
185
+ 'Signed in' AS stage,
186
+ 40 AS stage_order
187
+ FROM
188
+ pre_sign_in_cohort AS cohort
189
+ WHERE
190
+ cohort.authenticated_at_ms IS NOT NULL
191
+ AND cohort.authenticated_at_ms >= cohort.cohort_started_at_ms
192
+ ),
193
+
194
+ successful_auth_events AS (
195
+ SELECT
196
+ attributed_user_id AS user_id,
197
+ occurred_at_ms AS authenticated_at_ms,
198
+ JSON_VALUE(SAFE.PARSE_JSON(properties), '$.accessState') AS access_state
199
+ FROM
200
+ event_identity
201
+ WHERE
202
+ attributed_user_id IS NOT NULL
203
+ AND event_type = 'interaction'
204
+ AND category = 'onboarding'
205
+ AND action = 'auth_result'
206
+ AND JSON_VALUE(SAFE.PARSE_JSON(properties), '$.outcome') = 'success'
207
+ ),
208
+
209
+ activation_completed_by_user AS (
210
+ -- A successful consent write is the trusted transition to AccessState.DONE.
211
+ SELECT
212
+ attributed_user_id AS user_id,
213
+ MIN(occurred_at_ms) AS completed_at_ms
214
+ FROM
215
+ event_identity
216
+ WHERE
217
+ attributed_user_id IS NOT NULL
218
+ AND event_type = 'interaction'
219
+ AND category = 'onboarding'
220
+ AND action = 'consent_submit_result'
221
+ AND JSON_VALUE(SAFE.PARSE_JSON(properties), '$.outcome') = 'success'
222
+ GROUP BY
223
+ user_id
224
+ ),
225
+
226
+ auth_followup_signals AS (
227
+ -- Current telemetry records accessState at authentication. For older events,
228
+ -- reaching home without any recorded activation step is evidence that the
229
+ -- route guard recognized an already-completed returning user.
230
+ SELECT
231
+ auth.user_id,
232
+ auth.authenticated_at_ms,
233
+ auth.access_state,
234
+ completion.completed_at_ms,
235
+ MIN(
236
+ IF(
237
+ event.event_type = 'interaction'
238
+ AND event.category = 'onboarding'
239
+ AND event.action = 'interest_submit_result'
240
+ AND JSON_VALUE(SAFE.PARSE_JSON(event.properties), '$.outcome') = 'success',
241
+ event.occurred_at_ms,
242
+ NULL
243
+ )
244
+ ) AS first_interest_at_ms,
245
+ MIN(
246
+ IF(
247
+ event.event_type = 'interaction'
248
+ AND event.category = 'onboarding'
249
+ AND event.action = 'consent_submit_result'
250
+ AND JSON_VALUE(SAFE.PARSE_JSON(event.properties), '$.outcome') = 'success',
251
+ event.occurred_at_ms,
252
+ NULL
253
+ )
254
+ ) AS first_consent_at_ms,
255
+ MIN(
256
+ IF(
257
+ event.event_type = 'route_visit'
258
+ AND event.route_path = '/home',
259
+ event.occurred_at_ms,
260
+ NULL
261
+ )
262
+ ) AS first_home_at_ms
263
+ FROM
264
+ successful_auth_events AS auth
265
+ LEFT JOIN
266
+ activation_completed_by_user AS completion
267
+ USING
268
+ (user_id)
269
+ LEFT JOIN
270
+ event_identity AS event
271
+ ON event.attributed_user_id = auth.user_id
272
+ AND event.occurred_at_ms >= auth.authenticated_at_ms
273
+ GROUP BY
274
+ auth.user_id,
275
+ auth.authenticated_at_ms,
276
+ auth.access_state,
277
+ completion.completed_at_ms
278
+ ),
279
+
280
+ first_auth_by_user AS (
281
+ -- Only users who were not already through activation may enter this cohort.
282
+ -- QUALIFY keeps one first eligible authentication per user.
283
+ SELECT
284
+ user_id,
285
+ authenticated_at_ms AS cohort_started_at_ms
286
+ FROM
287
+ auth_followup_signals
288
+ WHERE
289
+ COALESCE(access_state, '') != 'done'
290
+ AND (
291
+ completed_at_ms IS NULL
292
+ OR completed_at_ms > authenticated_at_ms
293
+ )
294
+ AND NOT (
295
+ access_state IS NULL
296
+ AND first_home_at_ms IS NOT NULL
297
+ AND first_interest_at_ms IS NULL
298
+ AND first_consent_at_ms IS NULL
299
+ )
300
+ QUALIFY
301
+ ROW_NUMBER() OVER (
302
+ PARTITION BY user_id
303
+ ORDER BY authenticated_at_ms
304
+ ) = 1
305
+ ),
306
+
307
+ post_interest_by_user AS (
308
+ SELECT
309
+ cohort.user_id,
310
+ MIN(event.occurred_at_ms) AS reached_at_ms
311
+ FROM
312
+ first_auth_by_user AS cohort
313
+ JOIN
314
+ event_identity AS event
315
+ ON event.attributed_user_id = cohort.user_id
316
+ WHERE
317
+ event.event_type = 'interaction'
318
+ AND event.category = 'onboarding'
319
+ AND event.action = 'interest_submit_result'
320
+ AND JSON_VALUE(SAFE.PARSE_JSON(event.properties), '$.outcome') = 'success'
321
+ AND event.occurred_at_ms >= cohort.cohort_started_at_ms
322
+ GROUP BY
323
+ cohort.user_id
324
+ ),
325
+
326
+ post_consent_view_by_user AS (
327
+ SELECT
328
+ interest.user_id,
329
+ MIN(event.occurred_at_ms) AS reached_at_ms
330
+ FROM
331
+ post_interest_by_user AS interest
332
+ JOIN
333
+ event_identity AS event
334
+ ON event.attributed_user_id = interest.user_id
335
+ WHERE
336
+ event.event_type = 'route_visit'
337
+ AND event.route_path = '/consent'
338
+ AND event.occurred_at_ms >= interest.reached_at_ms
339
+ GROUP BY
340
+ interest.user_id
341
+ ),
342
+
343
+ post_consented_by_user AS (
344
+ SELECT
345
+ consent_view.user_id,
346
+ MIN(event.occurred_at_ms) AS reached_at_ms
347
+ FROM
348
+ post_consent_view_by_user AS consent_view
349
+ JOIN
350
+ event_identity AS event
351
+ ON event.attributed_user_id = consent_view.user_id
352
+ WHERE
353
+ event.event_type = 'interaction'
354
+ AND event.category = 'onboarding'
355
+ AND event.action = 'consent_submit_result'
356
+ AND JSON_VALUE(SAFE.PARSE_JSON(event.properties), '$.outcome') = 'success'
357
+ AND event.occurred_at_ms >= consent_view.reached_at_ms
358
+ GROUP BY
359
+ consent_view.user_id
360
+ ),
361
+
362
+ post_home_by_user AS (
363
+ SELECT
364
+ consented.user_id,
365
+ MIN(event.occurred_at_ms) AS reached_at_ms
366
+ FROM
367
+ post_consented_by_user AS consented
368
+ JOIN
369
+ event_identity AS event
370
+ ON event.attributed_user_id = consented.user_id
371
+ WHERE
372
+ event.event_type = 'route_visit'
373
+ AND event.route_path = '/home'
374
+ AND event.occurred_at_ms >= consented.reached_at_ms
375
+ GROUP BY
376
+ consented.user_id
377
+ ),
378
+
379
+ post_sign_in_reach AS (
380
+ -- Stage 10: Signed in
381
+ SELECT
382
+ user_id,
383
+ 'Signed in' AS stage,
384
+ 10 AS stage_order
385
+ FROM
386
+ first_auth_by_user
387
+
388
+ UNION DISTINCT
389
+
390
+ -- Stage 20: Submitted Interest Form
391
+ SELECT
392
+ user_id,
393
+ 'Interest submitted' AS stage,
394
+ 20 AS stage_order
395
+ FROM
396
+ post_interest_by_user
397
+
398
+ UNION DISTINCT
399
+
400
+ -- Stage 30: Viewed Research Consent Form
401
+ SELECT
402
+ user_id,
403
+ 'Consent viewed' AS stage,
404
+ 30 AS stage_order
405
+ FROM
406
+ post_consent_view_by_user
407
+
408
+ UNION DISTINCT
409
+
410
+ -- Stage 40: Submitted IRB Consent Form
411
+ SELECT
412
+ user_id,
413
+ 'Consented' AS stage,
414
+ 40 AS stage_order
415
+ FROM
416
+ post_consented_by_user
417
+
418
+ UNION DISTINCT
419
+
420
+ -- Stage 50: Started First Home Session
421
+ SELECT
422
+ user_id,
423
+ 'Home reached' AS stage,
424
+ 50 AS stage_order
425
+ FROM
426
+ post_home_by_user
427
+ ),
428
+
429
+ pre_counts AS (
430
+
431
+ SELECT
432
+ stage,
433
+ stage_order,
434
+ COUNT(*) AS journeys
435
+ FROM
436
+ pre_sign_in_reach
437
+ GROUP BY
438
+ stage,
439
+ stage_order
440
+ ),
441
+
442
+ post_counts AS (
443
+
444
+ SELECT
445
+ stage,
446
+ stage_order,
447
+ COUNT(*) AS journeys
448
+ FROM
449
+ post_sign_in_reach
450
+ GROUP BY
451
+ stage,
452
+ stage_order
453
+ ),
454
+
455
+ pre_stage_definitions AS (
456
+
457
+ SELECT *
458
+ FROM
459
+ UNNEST([
460
+ STRUCT('Landing' AS stage, 10 AS stage_order),
461
+ STRUCT('Login' AS stage, 20 AS stage_order),
462
+ STRUCT('Authentication started' AS stage, 30 AS stage_order),
463
+ STRUCT('Signed in' AS stage, 40 AS stage_order)
464
+ ])
465
+ ),
466
+
467
+ post_stage_definitions AS (
468
+
469
+ SELECT *
470
+ FROM
471
+ UNNEST([
472
+ STRUCT('Signed in' AS stage, 10 AS stage_order),
473
+ STRUCT('Interest submitted' AS stage, 20 AS stage_order),
474
+ STRUCT('Consent viewed' AS stage, 30 AS stage_order),
475
+ STRUCT('Consented' AS stage, 40 AS stage_order),
476
+ STRUCT('Home reached' AS stage, 50 AS stage_order)
477
+ ])
478
+ )
479
+
480
+
481
+ SELECT
482
+ CONCAT('pre_sign_in:', definition.stage) AS cohort_stage_key,
483
+ 'pre_sign_in' AS analysis,
484
+ definition.stage,
485
+ definition.stage_order,
486
+ COALESCE(counts.journeys, 0) AS journeys,
487
+ SAFE_DIVIDE(COALESCE(counts.journeys, 0), (SELECT COUNT(*) FROM pre_sign_in_cohort)) AS conversion_from_cohort
488
+ FROM
489
+ pre_stage_definitions AS definition
490
+ LEFT JOIN
491
+ pre_counts AS counts
492
+ USING
493
+ (stage, stage_order)
494
+
495
+ UNION ALL
496
+
497
+ SELECT
498
+ CONCAT('post_sign_in:', definition.stage) AS cohort_stage_key,
499
+ 'post_sign_in' AS analysis,
500
+ definition.stage,
501
+ definition.stage_order,
502
+ COALESCE(counts.journeys, 0) AS journeys,
503
+ SAFE_DIVIDE(COALESCE(counts.journeys, 0), (SELECT COUNT(*) FROM first_auth_by_user)) AS conversion_from_cohort
504
+ FROM
505
+ post_stage_definitions AS definition
506
+ LEFT JOIN
507
+ post_counts AS counts
508
+ USING
509
+ (stage, stage_order)
510
+ ORDER BY
511
+ analysis,
512
+ stage_order;
@@ -0,0 +1,134 @@
1
+ -- Dataset contract: de-identified, event-level onboarding stage observations.
2
+ -- Purpose: Preserve the observed route and interaction milestones needed for
3
+ -- exploratory journey analysis without exposing raw device or user IDs.
4
+ -- Grain: One output row per recognized stage occurrence. This is not the strict
5
+ -- funnel: identities can emit a stage multiple times and stages need not occur
6
+ -- in order here.
7
+ -- Inputs: selected onboarding routes plus category=onboarding interactions.
8
+ -- Successful result actions receive distinct *_success stages; unsuccessful or
9
+ -- unknown outcomes retain the generic result stage and the outcome column.
10
+ -- Identity: observation_key hashes document/stage/timestamp; journey_key hashes
11
+ -- device_id; user_key hashes the route-level or authenticatedUserId fallback.
12
+ -- Parameters: @idSalt creates stable, joinable pseudonymous keys. Raw IDs never
13
+ -- leave BigQuery in this result.
14
+ -- SQL approach: UNION route and interaction observations into one shape, map
15
+ -- stage names to explicit numeric order, hash keys, then reject unknown stages
16
+ -- and events without a device identity.
17
+
18
+ WITH stage_events AS (
19
+ -- Route-derived stages describe views/arrivals; they do not prove form writes.
20
+ SELECT
21
+ document_id,
22
+ device_id,
23
+ user_id,
24
+ timestamp,
25
+ CASE SPLIT(route, '?')[SAFE_OFFSET(0)]
26
+ WHEN '/' THEN 'landing_view'
27
+ WHEN '/landing' THEN 'landing_view'
28
+ WHEN '/login' THEN 'login_view'
29
+ WHEN '/early-access' THEN 'early_access_view'
30
+ WHEN '/consent' THEN 'consent_view'
31
+ WHEN '/home' THEN 'home_reached'
32
+ END AS stage,
33
+ CAST(NULL AS STRING) AS outcome,
34
+ CAST(NULL AS STRING) AS auth_method
35
+ FROM
36
+ `analytics.events_flat`
37
+ WHERE
38
+ event_type = 'route_visit'
39
+ AND SPLIT(route, '?')[SAFE_OFFSET(0)] IN (
40
+ '/', '/landing', '/login', '/early-access', '/consent', '/home'
41
+ )
42
+
43
+ UNION ALL
44
+
45
+ -- Interaction-derived stages distinguish attempts, failures, and successes.
46
+ SELECT
47
+ document_id,
48
+ device_id,
49
+ COALESCE(
50
+ user_id,
51
+ JSON_VALUE(SAFE.PARSE_JSON(properties), '$.authenticatedUserId')
52
+ ) AS user_id,
53
+ timestamp,
54
+ CASE action
55
+ WHEN 'login_cta' THEN 'login_cta'
56
+ WHEN 'auth_attempt' THEN 'auth_attempt'
57
+ WHEN 'auth_result' THEN
58
+ CASE
59
+ WHEN JSON_VALUE(SAFE.PARSE_JSON(properties), '$.outcome') = 'success'
60
+ THEN 'auth_success'
61
+ ELSE 'auth_result'
62
+ END
63
+ WHEN 'interest_submit_attempt' THEN 'interest_submit_attempt'
64
+ WHEN 'interest_submit_result' THEN
65
+ CASE
66
+ WHEN JSON_VALUE(SAFE.PARSE_JSON(properties), '$.outcome') = 'success'
67
+ THEN 'interest_submit_success'
68
+ ELSE 'interest_submit_result'
69
+ END
70
+ WHEN 'consent_submit_attempt' THEN 'consent_submit_attempt'
71
+ WHEN 'consent_submit_result' THEN
72
+ CASE
73
+ WHEN JSON_VALUE(SAFE.PARSE_JSON(properties), '$.outcome') = 'success'
74
+ THEN 'consent_submit_success'
75
+ ELSE 'consent_submit_result'
76
+ END
77
+ END AS stage,
78
+ JSON_VALUE(SAFE.PARSE_JSON(properties), '$.outcome') AS outcome,
79
+ JSON_VALUE(SAFE.PARSE_JSON(properties), '$.method') AS auth_method
80
+ FROM
81
+ `analytics.events_flat`
82
+ WHERE
83
+ event_type = 'interaction'
84
+ AND category = 'onboarding'
85
+ )
86
+
87
+
88
+ SELECT
89
+
90
+ TO_HEX(SHA256(CONCAT(
91
+ @idSalt,
92
+ ':',
93
+ document_id,
94
+ ':',
95
+ stage,
96
+ ':',
97
+ CAST(timestamp AS STRING),
98
+ ':',
99
+ @idSalt
100
+ ))) AS observation_key,
101
+
102
+ TO_HEX(SHA256(CONCAT(@idSalt, ':', device_id, ':', @idSalt))) AS journey_key,
103
+
104
+ CASE
105
+ WHEN user_id IS NULL THEN NULL
106
+ ELSE TO_HEX(SHA256(CONCAT(@idSalt, ':', user_id, ':', @idSalt)))
107
+ END AS user_key,
108
+ stage,
109
+
110
+ CASE stage
111
+ WHEN 'landing_view' THEN 10
112
+ WHEN 'login_cta' THEN 20
113
+ WHEN 'login_view' THEN 30
114
+ WHEN 'auth_attempt' THEN 40
115
+ WHEN 'auth_result' THEN 45
116
+ WHEN 'auth_success' THEN 50
117
+ WHEN 'early_access_view' THEN 60
118
+ WHEN 'interest_submit_attempt' THEN 70
119
+ WHEN 'interest_submit_result' THEN 75
120
+ WHEN 'interest_submit_success' THEN 80
121
+ WHEN 'consent_view' THEN 90
122
+ WHEN 'consent_submit_attempt' THEN 100
123
+ WHEN 'consent_submit_result' THEN 105
124
+ WHEN 'consent_submit_success' THEN 110
125
+ WHEN 'home_reached' THEN 120
126
+ END AS stage_order,
127
+ timestamp AS occurred_at_ms,
128
+ outcome,
129
+ auth_method
130
+ FROM
131
+ stage_events
132
+ WHERE
133
+ stage IS NOT NULL
134
+ AND device_id IS NOT NULL;