@autobusal/common 1.11.0 → 1.12.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/Meta.tsx CHANGED
@@ -1,6 +1,6 @@
1
1
  import { useEffect } from 'react';
2
2
  import { useLocation } from 'react-router-dom';
3
- import ReactGA from 'react-ga4';
3
+ import { pageview } from '@autobusal/providers/Setup/analytics';
4
4
  import { useGetSettings } from '@autobusal/providers/services';
5
5
 
6
6
  interface Props {
@@ -124,28 +124,32 @@ const useCanonicalUrl = (explicit?: string): string => {
124
124
  return explicit ?? `${ window.location.origin }${ location.pathname }`;
125
125
  };
126
126
 
127
- // GA4's gtag.js only auto-sends a page_view on its initial `config` call
128
- // (see providers/Setup/analytics.ts, which disables that and initializes
129
- // with send_page_view: false) - every client-side route change in this SPA
130
- // was otherwise invisible to analytics. Meta is the one component rendered
131
- // on nearly every real page (136 call sites across both apps), already
132
- // tracks the canonical path via useLocation, and mounts fresh on every
133
- // navigation - the natural place to fire the pageview React Router itself
134
- // doesn't have a dedicated hook for. The 2-3 truly Meta-less pages (a
135
- // redirect-only auth callback, an invalid-signature bounce) aren't
136
- // meaningful page views anyway.
127
+ // A single-page app never reloads, so GTM's page-load trigger fires exactly
128
+ // once per session - every client-side route change after that is invisible
129
+ // unless it is announced. Meta is the one component rendered on nearly every
130
+ // real page (136 call sites across both apps), already tracks the canonical
131
+ // path via useLocation, and mounts fresh on every navigation - the natural
132
+ // place to fire the pageview React Router itself has no dedicated hook for.
133
+ // The 2-3 truly Meta-less pages (a redirect-only auth callback, an
134
+ // invalid-signature bounce) aren't meaningful page views anyway.
135
+ //
136
+ // Edited: Ferjolt Ozuni - Date: 2026-08-01
137
+ // Pushes to the GTM dataLayer rather than calling GA4 directly. The brand's
138
+ // container decides what to do with it, so switching or adding an analytics
139
+ // product is a change in GTM rather than in this file.
137
140
  const usePageviewTracking = (path: string, title: string): void => {
138
141
  const { data: settings } = useGetSettings();
139
- const gaId = settings.preferences.googleAnalyticsID;
142
+
143
+ const container = settings.analytics?.gtm_id;
140
144
 
141
145
  useEffect(() => {
142
- if (gaId === null) {
146
+ if (!container) {
143
147
  return;
144
148
  }
145
149
 
146
- ReactGA.send({ hitType: 'pageview', page: path, title });
150
+ pageview(path, title);
147
151
  // eslint-disable-next-line react-hooks/exhaustive-deps
148
- }, [gaId, path]);
152
+ }, [container, path]);
149
153
  };
150
154
 
151
155
  const Meta = ({ title, keywords, description, image, url, type = 'website', noIndex = false, children }: Props): JSX.Element => {
@@ -23,10 +23,10 @@ interface Props {
23
23
  * prerendered snapshot may have baked in, so an older "index" directive
24
24
  * cannot win by being first in the document.
25
25
  *
26
- * - Google Tag Manager loads, if the brand configured a container. That is
27
- * deliberate: a pre-launch page is exactly when a brand wants to measure
28
- * interest, and it is the only analytics that runs here since the app
29
- * itself never boots.
26
+ * - Google Tag Manager still runs, because Providers loads it before this
27
+ * renders - a pre-launch page is exactly when a brand wants to measure
28
+ * interest. It uses the brand's ONE container (admin > Analytics), not a
29
+ * separate id of its own; nothing extra is needed here.
30
30
  */
31
31
  const UnderConstruction = ({ t }: Props): JSX.Element => {
32
32
  const { data: settings } = useGetSettings();
@@ -51,29 +51,6 @@ const UnderConstruction = ({ t }: Props): JSX.Element => {
51
51
  };
52
52
  }, []);
53
53
 
54
- useEffect(() => {
55
- const container = construction?.gtm_id;
56
-
57
- if (!container) {
58
- return;
59
- }
60
-
61
- // Guard against a double insert - this component can re-render, and two
62
- // GTM containers on one page double-count everything they measure.
63
- if (document.getElementById('gtm-container')) {
64
- return;
65
- }
66
-
67
- (window as any).dataLayer = (window as any).dataLayer || [];
68
- (window as any).dataLayer.push({ 'gtm.start': new Date().getTime(), event: 'gtm.js' });
69
-
70
- const script = document.createElement('script');
71
- script.id = 'gtm-container';
72
- script.async = true;
73
- script.src = `https://www.googletagmanager.com/gtm.js?id=${ encodeURIComponent(container) }`;
74
- document.head.appendChild(script);
75
- }, [construction?.gtm_id]);
76
-
77
54
  const title = construction?.title || t('under_construction.title', { ns: 'common', company });
78
55
 
79
56
  const message = construction?.message || t('under_construction.message', { ns: 'common' });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@autobusal/common",
3
- "version": "1.11.0",
3
+ "version": "1.12.0",
4
4
  "author": "Ferjolt Ozuni",
5
5
  "type": "module",
6
6
  "main": "index.ts"