@molecule/app-analytics-angular
Feature · analytics · App (browser) · v1.1.3 · Apache-2.0
Angular bindings for @molecule/app-analytics (route listener)
npm install @molecule/app-analytics-angularHow it works
@molecule/app-analytics-angular is a ready-made analytics feature for the app (browser) side. It composes the core interfaces it needs, so it works with whichever providers your app has bonded.
import { bootstrapApplication } from '@angular/platform-browser'
import { createMemoryRouter } from '@molecule/app-routing'
import { provideRouter } from '@molecule/app-angular'
import { AnalyticsRouteListener } from '@molecule/app-analytics-angular'
import { Home } from './home.js'
bootstrapApplication(Home, {
providers: [provideRouter(createMemoryRouter({ initialEntries: ['/'] }))],
}).catch((error) => console.error(error))Works with: @molecule/app-analytics, @molecule/app-angular, @molecule/app-ui, @molecule/app-ui-angular
Reference
Angular bindings for @molecule/app-analytics.
Provides ready-made Angular components that consume the wired analytics
bond. Currently exports AnalyticsRouteListener, a render-free
component that fires a page event on every client-side route change.
Mount AnalyticsRouteListener once inside the router registration's
scope (provideRouter) — it follows useLocation() and forwards each
pathname / search change to the wired analytics bond's page().
Auto-generated, AI-first package reference for the molecule.dev ecosystem. It is written to be read by coding agents as much as by people, and is generated from this package's source — edit
src/index.tsJSDoc, not this file.
Quick Start
import { bootstrapApplication } from '@angular/platform-browser'
import { createMemoryRouter } from '@molecule/app-routing'
import { provideRouter } from '@molecule/app-angular'
import { AnalyticsRouteListener } from '@molecule/app-analytics-angular'
import { Home } from './home.js'
bootstrapApplication(Home, {
providers: [provideRouter(createMemoryRouter({ initialEntries: ['/'] }))],
}).catch((error) => console.error(error))
Type
feature
Installation
npm install @molecule/app-analytics-angular @angular/common @angular/core @angular/platform-browser @molecule/app-analytics @molecule/app-angular @molecule/app-ui @molecule/app-ui-angular
API
Classes
AnalyticsRouteListener
AnalyticsRouteListener component.
Angular counterpart of @molecule/app-analytics-react's
AnalyticsRouteListener — the same behavior for the same input: a page
event with the current pathname / search on mount and on every client-side
route change, dispatched through the wired analytics bond. It takes no
inputs and renders nothing.
React's root is nothing at all, so the host contributes no DOM either: it is
kept out of the page for its whole life (useHostPresence), exactly like a
React component that returns null.
@Component({
selector: 'mol-analytics-route-listener',
standalone: true,
template: '',
})
export class AnalyticsRouteListener {
/** The current route location, as the binding's router sees it. */
private readonly location = useLocation()
// React keys its effect on the pathname and search VALUES. The computed
// signals keep that behavior: a navigation that replaces the location
// without changing either value does not re-record.
/** The current pathname, the recorded page's `name`. */
private readonly name = computed(() => this.location().pathname)
/** The pathname and search together, the recorded page's `path`. */
private readonly path = computed(() => `${this.name()}${this.location().search}`)
constructor() {
useHostPresence(() => false)
effect(() => {
void page({
name: this.name(),
path: this.path(),
url: typeof window !== 'undefined' ? window.location.href : undefined,
})
})
}
}
Injection Notes
Requirements
Peer dependencies:
@angular/common^22.0.0@angular/core^22.0.0@angular/platform-browser^22.0.0@molecule/app-analytics^1.0.1@molecule/app-angular^3.12.1 || ^4.0.0@molecule/app-ui^1.0.1@molecule/app-ui-angular^1.1.0
Runtime Dependencies
-
@angular/common -
@angular/core -
@angular/platform-browser -
@molecule/app-analytics -
@molecule/app-angular -
@molecule/app-ui -
@molecule/app-ui-angular -
The analytics provider comes from the wired
app-analyticsbond (setProvider); unbonded, thepagecalls are no-ops. -
React's root is nothing, so the component contributes no DOM at all: its host stays out of the page.