From 0dbe581c5bd26b0200e2879c0ffbdc519d7822ee Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Thu, 24 Jun 2021 11:08:55 -0400 Subject: [PATCH] Ensure pending callbacks are called only once --- .../google-analytics_analytics.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/web_accessible_resources/google-analytics_analytics.js b/src/web_accessible_resources/google-analytics_analytics.js index aa4668bf0..0b6b7d569 100644 --- a/src/web_accessible_resources/google-analytics_analytics.js +++ b/src/web_accessible_resources/google-analytics_analytics.js @@ -85,16 +85,20 @@ setTimeout(item.eventCallback, 1); }; if ( Array.isArray(dl) ) { - for ( const item of dl ) { + dl.push = item => doCallback(item); + const q = dl.slice(); + dl.length = 0; + for ( const item of q ) { doCallback(item); } } - dl.push = item => doCallback(item); } } // empty ga queue if ( gaQueue instanceof Function && Array.isArray(gaQueue.q) ) { - for ( const entry of gaQueue.q ) { + const q = gaQueue.q.slice(); + gaQueue.q.length = 0; + for ( const entry of q ) { ga(...entry); } }