Skip to content

Commit

Permalink
More analytics, fix a race condition (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
xpdota authored Nov 1, 2024
1 parent e9ab968 commit f2f60c4
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/frontend/src/scripts/components/ads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ class ManagedAd {


window.addEventListener('nitroAds.loaded', () => {
console.debug('nitroAds.loaded');
recheckAds();
});

Expand Down Expand Up @@ -223,6 +224,8 @@ function recheckAds() {
}
}

window['recheckAds'] = recheckAds;

let firstLoad = true;

export function insertAds(element: HTMLElement) {
Expand All @@ -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 {
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f2f60c4

Please sign in to comment.