Change the way routing works, so ad will fit better for everyone, we gotta find away to refresh it so we can use <Link> but right now quick and dirty solution

This commit is contained in:
2025-03-12 01:52:05 -04:00
parent b7f7fd1989
commit 01dc9c9749
6 changed files with 103 additions and 53 deletions

View File

@@ -0,0 +1,32 @@
"use client"
import { useEffect } from 'react';
import { useRouter } from 'next/router';
const useRefreshAds = () => {
const router = useRouter();
useEffect(() => {
if (typeof window !== 'undefined') {
console.log("Initializing Ad Refresh...");
window.googletag = window.googletag || { cmd: [] };
router.events.on('routeChangeComplete', () => {
console.log("Refreshing Ads...");
window.googletag.cmd.push(() => {
if (window.googletag?.pubads) {
window.googletag.pubads().refresh();
}
});
});
return () => {
router.events.off('routeChangeComplete', () => {});
};
}
}, [router]);
return null;
};
export default useRefreshAds;