mirror of
https://github.com/kamranahmedse/developer-roadmap.git
synced 2025-09-01 21:32:35 +02:00
Add gam support
This commit is contained in:
59
src/components/Analytics/GoogleAdSlot.astro
Normal file
59
src/components/Analytics/GoogleAdSlot.astro
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<div
|
||||||
|
id='div-gpt-ad-1742391132948-0'
|
||||||
|
class='gam-slot fixed bottom-4 right-4 z-50 h-[160px] w-[350px] cursor-pointer max-md:bottom-0 max-md:right-0 max-md:h-[106px] max-md:w-full'
|
||||||
|
>
|
||||||
|
<script>
|
||||||
|
// @ts-nocheck
|
||||||
|
googletag.cmd.push(function () {
|
||||||
|
if (!googletag.pubads) {
|
||||||
|
console.log('googletag.pubads not found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Configure all ad slots on the page to be expanded by default, but
|
||||||
|
// collapse slots that are unable to be filled with an ad.
|
||||||
|
googletag.pubads().collapseEmptyDivs();
|
||||||
|
|
||||||
|
// Set non-personalized ads
|
||||||
|
googletag.pubads().setPrivacySettings({
|
||||||
|
restrictDataProcessing: true,
|
||||||
|
nonPersonalizedAds: true,
|
||||||
|
});
|
||||||
|
googletag.display('div-gpt-ad-1742391132948-0');
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
const nativeAds: Window[] = [];
|
||||||
|
|
||||||
|
function sendSize(iframe: Window) {
|
||||||
|
const breakpoint = window.innerWidth < 768 ? 'sm' : 'lg';
|
||||||
|
|
||||||
|
iframe.postMessage(`breakpoint:${breakpoint}`, '*');
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener(
|
||||||
|
'resize',
|
||||||
|
() => {
|
||||||
|
nativeAds.forEach((ad) => {
|
||||||
|
sendSize(ad);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
{
|
||||||
|
passive: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
window.addEventListener('message', function (e: MessageEvent<any>) {
|
||||||
|
if (e.data === 'initdfp') {
|
||||||
|
nativeAds.push(e.source as Window);
|
||||||
|
sendSize(e.source as Window);
|
||||||
|
} else if (e.data === 'close-ad') {
|
||||||
|
const ad = document.getElementById('div-gpt-ad-1742391132948-0');
|
||||||
|
if (ad) {
|
||||||
|
ad.remove();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
@@ -16,6 +16,7 @@ import type { ResourceType } from '../lib/resource-progress';
|
|||||||
import Clarity from '../components/Analytics/Clarity.astro';
|
import Clarity from '../components/Analytics/Clarity.astro';
|
||||||
import RedditPixel from '../components/Analytics/RedditPixel.astro';
|
import RedditPixel from '../components/Analytics/RedditPixel.astro';
|
||||||
import GoogleAd from '../components/Analytics/GoogleAd.astro';
|
import GoogleAd from '../components/Analytics/GoogleAd.astro';
|
||||||
|
import GoogleAdSlot from '../components/Analytics/GoogleAdSlot.astro';
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -192,21 +193,7 @@ const gaPageIdentifier = Astro.url.pathname
|
|||||||
client:load
|
client:load
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<!-- /22873384501/roadmap -->
|
<GoogleAdSlot />
|
||||||
<div id='div-gpt-ad-1742391132948-0' class='fixed bottom-2 right-2'>
|
|
||||||
<script>
|
|
||||||
// @ts-nocheck
|
|
||||||
googletag.cmd.push(function () {
|
|
||||||
// Set non-personalized ads
|
|
||||||
googletag.pubads().setPrivacySettings({
|
|
||||||
restrictDataProcessing: true,
|
|
||||||
nonPersonalizedAds: true,
|
|
||||||
});
|
|
||||||
googletag.display('div-gpt-ad-1742391132948-0');
|
|
||||||
});
|
|
||||||
</script>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<slot name='after-footer' />
|
<slot name='after-footer' />
|
||||||
|
|
||||||
<PageVisit
|
<PageVisit
|
||||||
|
Reference in New Issue
Block a user