From f2f60c4dbd3203cb995431c3ec5659bb8dfece06 Mon Sep 17 00:00:00 2001 From: xpdota Date: Fri, 1 Nov 2024 07:08:21 -0700 Subject: [PATCH] More analytics, fix a race condition (#398) --- packages/frontend/src/scripts/components/ads.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/packages/frontend/src/scripts/components/ads.ts b/packages/frontend/src/scripts/components/ads.ts index dae432c3..11db9b25 100644 --- a/packages/frontend/src/scripts/components/ads.ts +++ b/packages/frontend/src/scripts/components/ads.ts @@ -132,6 +132,7 @@ class ManagedAd { window.addEventListener('nitroAds.loaded', () => { + console.debug('nitroAds.loaded'); recheckAds(); }); @@ -223,6 +224,8 @@ function recheckAds() { } } +window['recheckAds'] = recheckAds; + let firstLoad = true; export function insertAds(element: HTMLElement) { @@ -233,9 +236,12 @@ export function insertAds(element: HTMLElement) { if (adsEnabled()) { recordEvent('adsEnabled'); } - else { + else if (Array.from(document.head.querySelectorAll('script')).find(script => script.src && script.src.includes('nitro'))) { recordEvent('adsDisabled'); } + else { + recordEvent('adsNotInjected'); + } }, 10_000); try { @@ -325,6 +331,7 @@ export function insertAds(element: HTMLElement) { } element.prepend(...currentAds.map(a => a.adContainer.outer)); setTimeout(recheckAds); + setTimeout(recheckAds, 2_000); if (firstLoad) { firstLoad = false; }