@autobusal/common 1.7.0 → 1.8.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 +14 -0
- package/Meta.tsx +28 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,20 @@
|
|
|
3
3
|
All notable changes to `@autobusal/common` are documented here. This project follows
|
|
4
4
|
[Keep a Changelog](https://keepachangelog.com/) and [Semantic Versioning](https://semver.org/).
|
|
5
5
|
|
|
6
|
+
## [1.8.0] - 2026-07-30
|
|
7
|
+
|
|
8
|
+
### Added
|
|
9
|
+
|
|
10
|
+
- **GA4 SPA pageview tracking in `Meta`.** gtag.js only auto-sends a
|
|
11
|
+
page_view on its initial `config` call - every client-side route change
|
|
12
|
+
was invisible to analytics (pairs with `@autobusal/providers` 1.6.2, which
|
|
13
|
+
disables the automatic one). Meta now sends an explicit pageview
|
|
14
|
+
(`location.pathname + location.search`, current title) whenever the path
|
|
15
|
+
changes, since it's already rendered on nearly every real page. Excluded
|
|
16
|
+
from the effect's dependencies on purpose: a title-only change (e.g. a
|
|
17
|
+
language switch) does not fire a new pageview, only an actual navigation
|
|
18
|
+
does.
|
|
19
|
+
|
|
6
20
|
## [1.7.0] - 2026-07-30
|
|
7
21
|
|
|
8
22
|
### Added
|
package/Meta.tsx
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { useLocation } from 'react-router-dom';
|
|
3
|
+
import ReactGA from 'react-ga4';
|
|
4
|
+
import { useGetSettings } from '@autobusal/providers/services';
|
|
3
5
|
|
|
4
6
|
interface Props {
|
|
5
7
|
title: string
|
|
@@ -70,11 +72,37 @@ const useCanonicalUrl = (explicit?: string): string => {
|
|
|
70
72
|
return explicit ?? `${ window.location.origin }${ location.pathname }`;
|
|
71
73
|
};
|
|
72
74
|
|
|
75
|
+
// GA4's gtag.js only auto-sends a page_view on its initial `config` call
|
|
76
|
+
// (see providers/Setup/analytics.ts, which disables that and initializes
|
|
77
|
+
// with send_page_view: false) - every client-side route change in this SPA
|
|
78
|
+
// was otherwise invisible to analytics. Meta is the one component rendered
|
|
79
|
+
// on nearly every real page (136 call sites across both apps), already
|
|
80
|
+
// tracks the canonical path via useLocation, and mounts fresh on every
|
|
81
|
+
// navigation - the natural place to fire the pageview React Router itself
|
|
82
|
+
// doesn't have a dedicated hook for. The 2-3 truly Meta-less pages (a
|
|
83
|
+
// redirect-only auth callback, an invalid-signature bounce) aren't
|
|
84
|
+
// meaningful page views anyway.
|
|
85
|
+
const usePageviewTracking = (path: string, title: string): void => {
|
|
86
|
+
const { data: settings } = useGetSettings();
|
|
87
|
+
const gaId = settings.preferences.googleAnalyticsID;
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (gaId === null) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
ReactGA.send({ hitType: 'pageview', page: path, title });
|
|
95
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
96
|
+
}, [gaId, path]);
|
|
97
|
+
};
|
|
98
|
+
|
|
73
99
|
const Meta = ({ title, keywords, description, image, url, type = 'website', noIndex = false, children }: Props): JSX.Element => {
|
|
74
100
|
const fullTitle = withBrand(title);
|
|
75
101
|
const canonicalUrl = useCanonicalUrl(url);
|
|
102
|
+
const location = useLocation();
|
|
76
103
|
|
|
77
104
|
useSoleTitleOwnership(fullTitle);
|
|
105
|
+
usePageviewTracking(location.pathname + location.search, fullTitle);
|
|
78
106
|
|
|
79
107
|
return (
|
|
80
108
|
<>
|