@@ -68,9 +68,8 @@ const { canonicalOrigin, privacyUrl } = Astro.props;
6868 ? new URL(window.location.pathname, canonicalOrigin).toString()
6969 : undefined;
7070 const browserDeniesTracking = trackingDeniedByBrowser();
71- let sentGeneration: string | null = null;
72- let pendingGeneration: string | null = null;
73- let currentState: TrackingState | null = null;
71+ // Retain attempts after ambiguous delivery so recovery cannot count a visit twice.
72+ let attemptedGeneration: string | null = null;
7473 let client: ReturnType<typeof createSharedTrackingClient> | undefined;
7574
7675 const showPanel = () => {
@@ -96,7 +95,6 @@ const { canonicalOrigin, privacyUrl } = Astro.props;
9695 errorMessage.hidden = true;
9796 delete errorMessage.dataset.trackingFailure;
9897 }
99- currentState = state;
10098 if (state.choice === null) {
10199 showPanel();
102100 return;
@@ -111,36 +109,27 @@ const { canonicalOrigin, privacyUrl } = Astro.props;
111109 if (
112110 state.choice !== 'accepted' ||
113111 !state.generation ||
114- state.generation === sentGeneration ||
115- state.generation === pendingGeneration ||
112+ state.generation === attemptedGeneration ||
116113 !client
117114 )
118115 return;
119116
120- pendingGeneration = state.generation;
121117 try {
122118 const pageview = buildMauticPageview({
123119 canonicalUrl,
124120 currentUrl: window.location.href,
125121 pageTitle: document.title,
126122 referrer: document.referrer,
127123 });
124+ attemptedGeneration = state.generation;
128125 await client.pageview(pageview);
129- if (
130- currentState?.choice === 'accepted' &&
131- currentState.generation === state.generation
132- ) {
133- sentGeneration = state.generation;
134- }
135126 } catch (error) {
136127 if (
137128 client.state.choice === 'accepted' &&
138129 client.state.generation === state.generation
139130 ) {
140131 showFailure(error);
141132 }
142- } finally {
143- if (pendingGeneration === state.generation) pendingGeneration = null;
144133 }
145134 };
146135
0 commit comments