@momentumcms/plugins-analytics 0.3.0 → 0.4.1
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/index.cjs +295 -45
- package/index.js +291 -45
- package/lib/analytics-admin-routes.cjs +2108 -0
- package/lib/analytics-admin-routes.js +2195 -0
- package/lib/client/tracker.cjs +541 -0
- package/lib/client/tracker.js +523 -0
- package/lib/collectors/block-field-injector.cjs +206 -0
- package/lib/collectors/block-field-injector.js +179 -0
- package/lib/page-view-tracker.cjs +208 -0
- package/lib/page-view-tracker.js +189 -0
- package/package.json +64 -55
- package/src/index.d.ts +3 -1
- package/src/lib/analytics-admin-routes.d.ts +3 -0
- package/src/lib/analytics-config.types.d.ts +29 -0
- package/src/lib/analytics-plugin.d.ts +1 -1
- package/src/lib/collectors/page-view-collector.d.ts +29 -0
- package/src/lib/page-view-tracker.d.ts +21 -0
- package/src/lib/page-view-tracker.utils.d.ts +28 -0
- package/src/lib/utils/content-route-matcher.d.ts +42 -0
- package/CHANGELOG.md +0 -99
- package/LICENSE +0 -21
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
4
|
+
var result = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
5
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
6
|
+
if (decorator = decorators[i])
|
|
7
|
+
result = (kind ? decorator(target, key, result) : decorator(result)) || result;
|
|
8
|
+
if (kind && result)
|
|
9
|
+
__defProp(target, key, result);
|
|
10
|
+
return result;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// libs/plugins/analytics/src/lib/page-view-tracker.ts
|
|
14
|
+
import {
|
|
15
|
+
Injectable,
|
|
16
|
+
InjectionToken,
|
|
17
|
+
inject,
|
|
18
|
+
DestroyRef,
|
|
19
|
+
PLATFORM_ID,
|
|
20
|
+
makeEnvironmentProviders,
|
|
21
|
+
ENVIRONMENT_INITIALIZER
|
|
22
|
+
} from "@angular/core";
|
|
23
|
+
import { DOCUMENT, isPlatformBrowser } from "@angular/common";
|
|
24
|
+
import { Router, NavigationEnd } from "@angular/router";
|
|
25
|
+
import { HttpClient } from "@angular/common/http";
|
|
26
|
+
import { filter } from "rxjs";
|
|
27
|
+
|
|
28
|
+
// libs/plugins/analytics/src/lib/utils/content-route-matcher.ts
|
|
29
|
+
function escapeRegex(str) {
|
|
30
|
+
return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
31
|
+
}
|
|
32
|
+
function compileContentRoute(collection, pattern) {
|
|
33
|
+
const segments = pattern.split("/").filter(Boolean);
|
|
34
|
+
const paramNames = [];
|
|
35
|
+
let staticCount = 0;
|
|
36
|
+
const regexParts = segments.map((seg) => {
|
|
37
|
+
if (seg.startsWith(":")) {
|
|
38
|
+
paramNames.push(seg.slice(1));
|
|
39
|
+
return "([^/]+)";
|
|
40
|
+
}
|
|
41
|
+
staticCount++;
|
|
42
|
+
return escapeRegex(seg);
|
|
43
|
+
});
|
|
44
|
+
const regexStr = "^/" + regexParts.join("/") + "/?$";
|
|
45
|
+
return {
|
|
46
|
+
collection,
|
|
47
|
+
pattern,
|
|
48
|
+
regex: new RegExp(regexStr),
|
|
49
|
+
paramNames,
|
|
50
|
+
staticSegments: staticCount
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function compileContentRoutes(routes) {
|
|
54
|
+
const compiled = Object.entries(routes).map(
|
|
55
|
+
([collection, pattern]) => compileContentRoute(collection, pattern)
|
|
56
|
+
);
|
|
57
|
+
compiled.sort((a, b) => b.staticSegments - a.staticSegments);
|
|
58
|
+
return compiled;
|
|
59
|
+
}
|
|
60
|
+
function matchContentRoute(path, routes) {
|
|
61
|
+
for (const route of routes) {
|
|
62
|
+
const match = route.regex.exec(path);
|
|
63
|
+
if (match) {
|
|
64
|
+
const params = {};
|
|
65
|
+
for (let i = 0; i < route.paramNames.length; i++) {
|
|
66
|
+
params[route.paramNames[i]] = match[i + 1];
|
|
67
|
+
}
|
|
68
|
+
return { collection: route.collection, params };
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return void 0;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// libs/plugins/analytics/src/lib/page-view-tracker.utils.ts
|
|
75
|
+
var DEFAULT_EXCLUDE_PREFIXES = ["/admin", "/api/"];
|
|
76
|
+
function shouldTrackNavigation(url, isFirstNavigation, excludePrefixes) {
|
|
77
|
+
if (isFirstNavigation)
|
|
78
|
+
return false;
|
|
79
|
+
const path = url.split("?")[0].split("#")[0];
|
|
80
|
+
for (const prefix of excludePrefixes) {
|
|
81
|
+
if (path.startsWith(prefix))
|
|
82
|
+
return false;
|
|
83
|
+
}
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
function buildPageViewEvent(url, compiledRoutes) {
|
|
87
|
+
const path = url.split("?")[0].split("#")[0];
|
|
88
|
+
const properties = { path };
|
|
89
|
+
if (compiledRoutes) {
|
|
90
|
+
const routeMatch = matchContentRoute(path, compiledRoutes);
|
|
91
|
+
if (routeMatch) {
|
|
92
|
+
properties["collection"] = routeMatch.collection;
|
|
93
|
+
properties["slug"] = routeMatch.params["slug"];
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
name: "page_view",
|
|
98
|
+
category: "page",
|
|
99
|
+
properties
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// libs/plugins/analytics/src/lib/page-view-tracker.ts
|
|
104
|
+
var PAGE_VIEW_TRACKING_CONFIG = new InjectionToken(
|
|
105
|
+
"PAGE_VIEW_TRACKING_CONFIG"
|
|
106
|
+
);
|
|
107
|
+
function getOrCreateStorageId(storage, key) {
|
|
108
|
+
let id = storage.getItem(key);
|
|
109
|
+
if (!id) {
|
|
110
|
+
id = Date.now().toString(36) + Math.random().toString(36).slice(2, 10);
|
|
111
|
+
storage.setItem(key, id);
|
|
112
|
+
}
|
|
113
|
+
return id;
|
|
114
|
+
}
|
|
115
|
+
var PageViewTrackerService = class {
|
|
116
|
+
constructor() {
|
|
117
|
+
this.router = inject(Router);
|
|
118
|
+
this.http = inject(HttpClient);
|
|
119
|
+
this.platformId = inject(PLATFORM_ID);
|
|
120
|
+
this.destroyRef = inject(DestroyRef);
|
|
121
|
+
this.config = inject(PAGE_VIEW_TRACKING_CONFIG);
|
|
122
|
+
this.doc = inject(DOCUMENT);
|
|
123
|
+
this.isFirstNavigation = true;
|
|
124
|
+
this.endpoint = this.config.endpoint ?? "/api/analytics/collect";
|
|
125
|
+
this.compiledRoutes = this.config.contentRoutes ? compileContentRoutes(this.config.contentRoutes) : void 0;
|
|
126
|
+
this.excludePrefixes = this.config.excludePrefixes ? [...DEFAULT_EXCLUDE_PREFIXES, ...this.config.excludePrefixes] : DEFAULT_EXCLUDE_PREFIXES;
|
|
127
|
+
if (!isPlatformBrowser(this.platformId))
|
|
128
|
+
return;
|
|
129
|
+
const sub = this.router.events.pipe(filter((e) => e instanceof NavigationEnd)).subscribe((event) => {
|
|
130
|
+
const url = event.urlAfterRedirects;
|
|
131
|
+
if (!shouldTrackNavigation(url, this.isFirstNavigation, this.excludePrefixes)) {
|
|
132
|
+
this.isFirstNavigation = false;
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
this.isFirstNavigation = false;
|
|
136
|
+
this.trackPageView(url);
|
|
137
|
+
});
|
|
138
|
+
this.destroyRef.onDestroy(() => sub.unsubscribe());
|
|
139
|
+
}
|
|
140
|
+
trackPageView(url) {
|
|
141
|
+
const eventPayload = buildPageViewEvent(url, this.compiledRoutes);
|
|
142
|
+
const win = this.doc.defaultView;
|
|
143
|
+
let visitorId;
|
|
144
|
+
let sessionId;
|
|
145
|
+
try {
|
|
146
|
+
if (win?.localStorage)
|
|
147
|
+
visitorId = getOrCreateStorageId(win.localStorage, "_m_vid");
|
|
148
|
+
if (win?.sessionStorage)
|
|
149
|
+
sessionId = getOrCreateStorageId(win.sessionStorage, "_m_sid");
|
|
150
|
+
} catch {
|
|
151
|
+
}
|
|
152
|
+
const clientEvent = {
|
|
153
|
+
...eventPayload,
|
|
154
|
+
context: {
|
|
155
|
+
url: win?.location?.href ?? "",
|
|
156
|
+
referrer: this.doc.referrer
|
|
157
|
+
},
|
|
158
|
+
visitorId,
|
|
159
|
+
sessionId
|
|
160
|
+
};
|
|
161
|
+
this.http.post(this.endpoint, { events: [clientEvent] }).subscribe();
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
PageViewTrackerService = __decorateClass([
|
|
165
|
+
Injectable()
|
|
166
|
+
], PageViewTrackerService);
|
|
167
|
+
function providePageViewTracking(config) {
|
|
168
|
+
return makeEnvironmentProviders([
|
|
169
|
+
{ provide: PAGE_VIEW_TRACKING_CONFIG, useValue: config },
|
|
170
|
+
PageViewTrackerService,
|
|
171
|
+
{
|
|
172
|
+
provide: ENVIRONMENT_INITIALIZER,
|
|
173
|
+
multi: true,
|
|
174
|
+
useFactory: () => {
|
|
175
|
+
inject(PageViewTrackerService);
|
|
176
|
+
return () => {
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
]);
|
|
181
|
+
}
|
|
182
|
+
export {
|
|
183
|
+
DEFAULT_EXCLUDE_PREFIXES,
|
|
184
|
+
PAGE_VIEW_TRACKING_CONFIG,
|
|
185
|
+
PageViewTrackerService,
|
|
186
|
+
buildPageViewEvent,
|
|
187
|
+
providePageViewTracking,
|
|
188
|
+
shouldTrackNavigation
|
|
189
|
+
};
|
package/package.json
CHANGED
|
@@ -1,56 +1,65 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
2
|
+
"name": "@momentumcms/plugins-analytics",
|
|
3
|
+
"version": "0.4.1",
|
|
4
|
+
"description": "Analytics and content tracking plugin for Momentum CMS",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Momentum CMS Contributors",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/DonaldMurillo/momentum-cms.git",
|
|
10
|
+
"directory": "libs/plugins/analytics"
|
|
11
|
+
},
|
|
12
|
+
"homepage": "https://github.com/DonaldMurillo/momentum-cms#readme",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/DonaldMurillo/momentum-cms/issues"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"cms",
|
|
18
|
+
"momentum-cms",
|
|
19
|
+
"analytics",
|
|
20
|
+
"tracking",
|
|
21
|
+
"content-performance"
|
|
22
|
+
],
|
|
23
|
+
"engines": {
|
|
24
|
+
"node": ">=18"
|
|
25
|
+
},
|
|
26
|
+
"main": "./index.cjs",
|
|
27
|
+
"types": "./src/index.d.ts",
|
|
28
|
+
"exports": {
|
|
29
|
+
".": {
|
|
30
|
+
"types": "./src/index.d.ts",
|
|
31
|
+
"default": "./index.cjs"
|
|
32
|
+
},
|
|
33
|
+
"./admin-routes": {
|
|
34
|
+
"types": "./src/lib/analytics-admin-routes.d.ts",
|
|
35
|
+
"default": "./lib/analytics-admin-routes.cjs"
|
|
36
|
+
},
|
|
37
|
+
"./block-fields": {
|
|
38
|
+
"types": "./src/lib/collectors/block-field-injector.d.ts",
|
|
39
|
+
"default": "./lib/collectors/block-field-injector.cjs"
|
|
40
|
+
},
|
|
41
|
+
"./client": {
|
|
42
|
+
"types": "./src/lib/client/tracker.d.ts",
|
|
43
|
+
"default": "./lib/client/tracker.cjs"
|
|
44
|
+
},
|
|
45
|
+
"./page-tracker": {
|
|
46
|
+
"types": "./src/lib/page-view-tracker.d.ts",
|
|
47
|
+
"default": "./lib/page-view-tracker.cjs"
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
"dependencies": {
|
|
51
|
+
"@momentumcms/core": "0.4.1",
|
|
52
|
+
"@momentumcms/logger": "0.4.1",
|
|
53
|
+
"@momentumcms/plugins-core": "0.4.1",
|
|
54
|
+
"@momentumcms/server-core": "0.4.1",
|
|
55
|
+
"express": "^4.21.0"
|
|
56
|
+
},
|
|
57
|
+
"peerDependencies": {
|
|
58
|
+
"pg": "^8.0.0"
|
|
59
|
+
},
|
|
60
|
+
"peerDependenciesMeta": {
|
|
61
|
+
"pg": {
|
|
62
|
+
"optional": true
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
package/src/index.d.ts
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
export type { AnalyticsEvent, AnalyticsCategory, AnalyticsContext, AnalyticsQueryOptions, AnalyticsQueryResult, } from './lib/analytics-event.types';
|
|
2
|
-
export type { AnalyticsAdapter, AnalyticsConfig } from './lib/analytics-config.types';
|
|
2
|
+
export type { AnalyticsAdapter, AnalyticsConfig, PageViewTrackingOptions, } from './lib/analytics-config.types';
|
|
3
3
|
export { EventStore, type EventStoreOptions } from './lib/event-store';
|
|
4
4
|
export { injectCollectionCollector, type AnalyticsEmitter, type CollectionCollectorOptions, } from './lib/collectors/collection-collector';
|
|
5
5
|
export { createApiCollectorMiddleware } from './lib/collectors/api-collector';
|
|
6
|
+
export { createPageViewCollectorMiddleware, isBot, type PageViewEmitter, } from './lib/collectors/page-view-collector';
|
|
7
|
+
export { compileContentRoutes, matchContentRoute, type CompiledContentRoute, type ContentRouteMatch, } from './lib/utils/content-route-matcher';
|
|
6
8
|
export { createIngestRouter, type IngestHandlerOptions } from './lib/ingest-handler';
|
|
7
9
|
export { MemoryAnalyticsAdapter } from './lib/adapters/memory-adapter';
|
|
8
10
|
export { postgresAnalyticsAdapter, type PostgresAnalyticsAdapterOptions, } from './lib/adapters/postgres-adapter';
|
|
@@ -16,6 +16,27 @@ export interface AnalyticsAdapter {
|
|
|
16
16
|
/** Flush pending events and close connections */
|
|
17
17
|
shutdown?(): Promise<void>;
|
|
18
18
|
}
|
|
19
|
+
/**
|
|
20
|
+
* Options for server-side page view tracking.
|
|
21
|
+
*/
|
|
22
|
+
export interface PageViewTrackingOptions {
|
|
23
|
+
/** Additional path prefixes to exclude from tracking. */
|
|
24
|
+
excludePaths?: string[];
|
|
25
|
+
/** File extensions to ignore (overrides defaults when provided). */
|
|
26
|
+
excludeExtensions?: string[];
|
|
27
|
+
/** Only track responses with 2xx status codes. @default true */
|
|
28
|
+
onlySuccessful?: boolean;
|
|
29
|
+
/** Whether to track bot traffic (Googlebot, Bingbot, etc.). @default false */
|
|
30
|
+
trackBots?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Map collection slugs to URL patterns for content attribution.
|
|
33
|
+
* When a page view URL matches a pattern, the event is enriched with
|
|
34
|
+
* collection and slug metadata, enabling per-document analytics.
|
|
35
|
+
* Patterns use Express-style `:param` syntax.
|
|
36
|
+
* @example { articles: '/articles/:slug', pages: '/:slug' }
|
|
37
|
+
*/
|
|
38
|
+
contentRoutes?: Record<string, string>;
|
|
39
|
+
}
|
|
19
40
|
/**
|
|
20
41
|
* Analytics configuration.
|
|
21
42
|
*/
|
|
@@ -30,6 +51,14 @@ export interface AnalyticsConfig {
|
|
|
30
51
|
trackApi?: boolean;
|
|
31
52
|
/** Admin action tracking. @default true */
|
|
32
53
|
trackAdmin?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* Server-side page view tracking (SSR page renders).
|
|
56
|
+
* - `true` (default): enable with default settings
|
|
57
|
+
* - `false`: disable
|
|
58
|
+
* - object: override page view tracking options
|
|
59
|
+
* @default true
|
|
60
|
+
*/
|
|
61
|
+
trackPageViews?: boolean | PageViewTrackingOptions;
|
|
33
62
|
/** Client-side ingest endpoint path. @default '/api/analytics/collect' */
|
|
34
63
|
ingestPath?: string;
|
|
35
64
|
/** Rate limit for ingest endpoint (requests per minute per IP). @default 100 */
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Analytics Plugin
|
|
3
3
|
*
|
|
4
4
|
* A Momentum CMS plugin that wires all analytics collectors together.
|
|
5
|
-
* Tracks collection CRUD, API requests, and accepts client-side events.
|
|
5
|
+
* Tracks collection CRUD, API requests, page views, and accepts client-side events.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```typescript
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page View Collector
|
|
3
|
+
*
|
|
4
|
+
* Express middleware that tracks SSR page view timing and context.
|
|
5
|
+
* Mounted at the application root to intercept page renders.
|
|
6
|
+
*/
|
|
7
|
+
import type { Request, Response, NextFunction } from 'express';
|
|
8
|
+
import type { AnalyticsEvent } from '../analytics-event.types';
|
|
9
|
+
import type { PageViewTrackingOptions } from '../analytics-config.types';
|
|
10
|
+
/**
|
|
11
|
+
* Callback type for page view event emission.
|
|
12
|
+
*/
|
|
13
|
+
export type PageViewEmitter = (event: AnalyticsEvent) => void;
|
|
14
|
+
/**
|
|
15
|
+
* Check whether a user-agent string belongs to a known bot.
|
|
16
|
+
*/
|
|
17
|
+
export declare function isBot(ua: string | undefined): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Check whether a request path should be excluded from page view tracking.
|
|
20
|
+
*/
|
|
21
|
+
export declare function shouldExcludePath(path: string, excludeExtensions: ReadonlySet<string>, excludePaths: readonly string[]): boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Creates Express middleware that tracks SSR page view metrics.
|
|
24
|
+
*
|
|
25
|
+
* @param emitter - Callback to emit analytics events
|
|
26
|
+
* @param options - Page view tracking options
|
|
27
|
+
* @returns Express middleware function
|
|
28
|
+
*/
|
|
29
|
+
export declare function createPageViewCollectorMiddleware(emitter: PageViewEmitter, options?: PageViewTrackingOptions): (req: Request, res: Response, next: NextFunction) => void;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EnvironmentProviders } from '@angular/core';
|
|
2
|
+
|
|
3
|
+
/** Configuration for the client-side page view tracker. */
|
|
4
|
+
export interface PageViewTrackingConfig {
|
|
5
|
+
/** Map of collection slug -> URL pattern (e.g. `{ articles: '/articles/:slug' }`) */
|
|
6
|
+
contentRoutes?: Record<string, string>;
|
|
7
|
+
/** Ingest endpoint URL. @default '/api/analytics/collect' */
|
|
8
|
+
endpoint?: string;
|
|
9
|
+
/** Additional path prefixes to exclude from tracking. */
|
|
10
|
+
excludePrefixes?: readonly string[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Provide client-side page view tracking for an Angular application.
|
|
15
|
+
*
|
|
16
|
+
* Listens to Angular Router NavigationEnd events and sends page_view analytics
|
|
17
|
+
* events to the ingest endpoint for SPA navigations.
|
|
18
|
+
*/
|
|
19
|
+
export declare function providePageViewTracking(
|
|
20
|
+
config: PageViewTrackingConfig,
|
|
21
|
+
): EnvironmentProviders;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Page View Tracker — Pure Logic
|
|
3
|
+
*
|
|
4
|
+
* Testable functions used by the Angular PageViewTrackerService.
|
|
5
|
+
* No Angular dependencies — safe for Node.js and Vitest environments.
|
|
6
|
+
*/
|
|
7
|
+
import { type CompiledContentRoute } from './utils/content-route-matcher';
|
|
8
|
+
/** Default path prefixes excluded from client-side page view tracking. */
|
|
9
|
+
export declare const DEFAULT_EXCLUDE_PREFIXES: readonly string[];
|
|
10
|
+
/**
|
|
11
|
+
* Determine whether a navigation should be tracked.
|
|
12
|
+
*
|
|
13
|
+
* @param url - The navigated URL (may include query string / fragment)
|
|
14
|
+
* @param isFirstNavigation - True for the initial route (already tracked by SSR)
|
|
15
|
+
* @param excludePrefixes - Path prefixes to skip
|
|
16
|
+
*/
|
|
17
|
+
export declare function shouldTrackNavigation(url: string, isFirstNavigation: boolean, excludePrefixes: readonly string[]): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* Build a page_view client event payload from a URL.
|
|
20
|
+
*
|
|
21
|
+
* @param url - The navigated URL (may include query / fragment)
|
|
22
|
+
* @param compiledRoutes - Pre-compiled content routes for collection matching
|
|
23
|
+
*/
|
|
24
|
+
export declare function buildPageViewEvent(url: string, compiledRoutes: readonly CompiledContentRoute[] | undefined): {
|
|
25
|
+
name: string;
|
|
26
|
+
category: string;
|
|
27
|
+
properties: Record<string, unknown>;
|
|
28
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Route Matcher
|
|
3
|
+
*
|
|
4
|
+
* Compiles Express-style :param patterns into matchers for
|
|
5
|
+
* attributing page views to CMS collections.
|
|
6
|
+
*/
|
|
7
|
+
/** A compiled content route matcher. */
|
|
8
|
+
export interface CompiledContentRoute {
|
|
9
|
+
/** Collection slug this route maps to */
|
|
10
|
+
collection: string;
|
|
11
|
+
/** Original pattern string */
|
|
12
|
+
pattern: string;
|
|
13
|
+
/** Compiled regex */
|
|
14
|
+
regex: RegExp;
|
|
15
|
+
/** Ordered parameter names extracted from the pattern */
|
|
16
|
+
paramNames: readonly string[];
|
|
17
|
+
/** Number of static (non-param) segments — used for priority sorting */
|
|
18
|
+
staticSegments: number;
|
|
19
|
+
}
|
|
20
|
+
/** Result of matching a URL against content routes. */
|
|
21
|
+
export interface ContentRouteMatch {
|
|
22
|
+
/** Collection slug */
|
|
23
|
+
collection: string;
|
|
24
|
+
/** Extracted route parameters */
|
|
25
|
+
params: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Compile a single route pattern into a regex matcher.
|
|
29
|
+
*
|
|
30
|
+
* Supports Express-style `:paramName` segments.
|
|
31
|
+
* e.g. `/articles/:slug` compiles to `/^\/articles\/([^/]+)\/?$/`
|
|
32
|
+
*/
|
|
33
|
+
export declare function compileContentRoute(collection: string, pattern: string): CompiledContentRoute;
|
|
34
|
+
/**
|
|
35
|
+
* Compile all content routes, sorted by specificity (most static segments first).
|
|
36
|
+
*/
|
|
37
|
+
export declare function compileContentRoutes(routes: Record<string, string>): CompiledContentRoute[];
|
|
38
|
+
/**
|
|
39
|
+
* Match a URL path against compiled content routes.
|
|
40
|
+
* Returns the first (highest-priority) match, or undefined.
|
|
41
|
+
*/
|
|
42
|
+
export declare function matchContentRoute(path: string, routes: readonly CompiledContentRoute[]): ContentRouteMatch | undefined;
|
package/CHANGELOG.md
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
## 0.3.0 (2026-02-20)
|
|
2
|
-
|
|
3
|
-
### 🚀 Features
|
|
4
|
-
|
|
5
|
-
- add named tabs support with nested data grouping and UI improvements ([#30](https://github.com/DonaldMurillo/momentum-cms/pull/30))
|
|
6
|
-
|
|
7
|
-
### ❤️ Thank You
|
|
8
|
-
|
|
9
|
-
- Claude Opus 4.6
|
|
10
|
-
- Donald Murillo @DonaldMurillo
|
|
11
|
-
|
|
12
|
-
## 0.2.0 (2026-02-17)
|
|
13
|
-
|
|
14
|
-
This was a version bump only for plugins-analytics to align it with other projects, there were no code changes.
|
|
15
|
-
|
|
16
|
-
## 0.1.10 (2026-02-17)
|
|
17
|
-
|
|
18
|
-
### 🩹 Fixes
|
|
19
|
-
|
|
20
|
-
- **create-momentum-app:** add shell option to execFileSync for Windows ([#28](https://github.com/DonaldMurillo/momentum-cms/pull/28))
|
|
21
|
-
|
|
22
|
-
### ❤️ Thank You
|
|
23
|
-
|
|
24
|
-
- Claude Opus 4.6
|
|
25
|
-
- Donald Murillo @DonaldMurillo
|
|
26
|
-
|
|
27
|
-
## 0.1.9 (2026-02-16)
|
|
28
|
-
|
|
29
|
-
This was a version bump only for plugins-analytics to align it with other projects, there were no code changes.
|
|
30
|
-
|
|
31
|
-
## 0.1.8 (2026-02-16)
|
|
32
|
-
|
|
33
|
-
### 🩹 Fixes
|
|
34
|
-
|
|
35
|
-
- correct repository URLs and add GitHub link to CLI ([#26](https://github.com/DonaldMurillo/momentum-cms/pull/26))
|
|
36
|
-
|
|
37
|
-
### ❤️ Thank You
|
|
38
|
-
|
|
39
|
-
- Claude Opus 4.6
|
|
40
|
-
- Donald Murillo @DonaldMurillo
|
|
41
|
-
|
|
42
|
-
## 0.1.7 (2026-02-16)
|
|
43
|
-
|
|
44
|
-
### 🩹 Fixes
|
|
45
|
-
|
|
46
|
-
- correct repository URLs and add GitHub link to CLI output ([f7e96bb](https://github.com/DonaldMurillo/momentum-cms/commit/f7e96bb))
|
|
47
|
-
|
|
48
|
-
### ❤️ Thank You
|
|
49
|
-
|
|
50
|
-
- Claude Opus 4.6
|
|
51
|
-
- Donald Murillo @DonaldMurillo
|
|
52
|
-
|
|
53
|
-
## 0.1.6 (2026-02-16)
|
|
54
|
-
|
|
55
|
-
This was a version bump only for plugins-analytics to align it with other projects, there were no code changes.
|
|
56
|
-
|
|
57
|
-
## 0.1.5 (2026-02-16)
|
|
58
|
-
|
|
59
|
-
This was a version bump only for plugins-analytics to align it with other projects, there were no code changes.
|
|
60
|
-
|
|
61
|
-
## 0.1.4 (2026-02-16)
|
|
62
|
-
|
|
63
|
-
This was a version bump only for plugins-analytics to align it with other projects, there were no code changes.
|
|
64
|
-
|
|
65
|
-
## 0.1.3 (2026-02-16)
|
|
66
|
-
|
|
67
|
-
This was a version bump only for plugins-analytics to align it with other projects, there were no code changes.
|
|
68
|
-
|
|
69
|
-
## 0.1.2 (2026-02-16)
|
|
70
|
-
|
|
71
|
-
### 🩹 Fixes
|
|
72
|
-
|
|
73
|
-
- **release:** centralize manifestRootsToUpdate to update both source and dist ([2b8f832](https://github.com/DonaldMurillo/momentum-cms/commit/2b8f832))
|
|
74
|
-
- **create-app:** fix Angular SSR, Analog builds, and CJS/ESM compatibility ([28d4d0a](https://github.com/DonaldMurillo/momentum-cms/commit/28d4d0a))
|
|
75
|
-
|
|
76
|
-
### ❤️ Thank You
|
|
77
|
-
|
|
78
|
-
- Claude Opus 4.6
|
|
79
|
-
- Donald Murillo @DonaldMurillo
|
|
80
|
-
|
|
81
|
-
## 0.1.1 (2026-02-16)
|
|
82
|
-
|
|
83
|
-
This was a version bump only for plugins-analytics to align it with other projects, there were no code changes.
|
|
84
|
-
|
|
85
|
-
## 0.1.0 (2026-02-16)
|
|
86
|
-
|
|
87
|
-
### 🚀 Features
|
|
88
|
-
|
|
89
|
-
- add tracking rules, content performance, and block analytics ([#21](https://github.com/DonaldMurillo/momentum-cms/pull/21))
|
|
90
|
-
|
|
91
|
-
### 🩹 Fixes
|
|
92
|
-
|
|
93
|
-
- resolve CUD toast interceptor issues ([#17](https://github.com/DonaldMurillo/momentum-cms/pull/17), [#1](https://github.com/DonaldMurillo/momentum-cms/issues/1), [#2](https://github.com/DonaldMurillo/momentum-cms/issues/2), [#3](https://github.com/DonaldMurillo/momentum-cms/issues/3), [#4](https://github.com/DonaldMurillo/momentum-cms/issues/4))
|
|
94
|
-
|
|
95
|
-
### ❤️ Thank You
|
|
96
|
-
|
|
97
|
-
- Claude Haiku 4.5
|
|
98
|
-
- Claude Opus 4.6
|
|
99
|
-
- Donald Murillo @DonaldMurillo
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2024-present Momentum CMS Contributors
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|