From 78d3f6991bcfa8972be65215b67447144b3da1e4 Mon Sep 17 00:00:00 2001 From: Waheed Ahmed Date: Tue, 2 Nov 2021 11:10:51 +0500 Subject: [PATCH] fix: blank page issue if google analytics blocked (#234) This fix is added to handle Google annalytics case which is injected by the segment.min.js. --- src/analytics/SegmentAnalyticsService.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/analytics/SegmentAnalyticsService.js b/src/analytics/SegmentAnalyticsService.js index c66e1ae75..eb4a398f7 100644 --- a/src/analytics/SegmentAnalyticsService.js +++ b/src/analytics/SegmentAnalyticsService.js @@ -192,10 +192,18 @@ class SegmentAnalyticsService { resolve(); }); - // this is added to handle a specific use-case where if a user has blocked the segment - // domain in their browser, this promise does not get resolved and user see a blank + // this is added to handle a specific use-case where if a user has blocked the analytics + // tools in their browser, this promise does not get resolved and user sees a blank // page. Dispatching this event in script.onerror callback in analytics.load. document.addEventListener('segmentFailed', resolve); + // This is added to handle the google analytics blocked case which is injected into + // the DOM by segment.min.js. + setTimeout(() => { + if (!global.ga || !global.ga.create) { + this.segmentInitialized = false; + resolve(); + } + }, 2000); }); }