|
| 1 | +import { Link } from '@tanstack/react-router' |
| 2 | +import React from 'react' |
| 3 | + |
| 4 | +declare global { |
| 5 | + interface Window { |
| 6 | + googletag: any |
| 7 | + } |
| 8 | +} |
| 9 | + |
| 10 | +const adSlots = { |
| 11 | + leaderboard: { |
| 12 | + id: 'div-gpt-ad-1738811978953-leaderboard', |
| 13 | + sizes: [[728, 90]], |
| 14 | + targeting: 'leaderboard', |
| 15 | + refreshInterval: 45_000, // 45 seconds |
| 16 | + }, |
| 17 | + footer: { |
| 18 | + id: 'div-gpt-ad-1738811978953-footer', |
| 19 | + sizes: [[728, 90]], |
| 20 | + targeting: 'footer', |
| 21 | + refreshInterval: 45_000, // 45 seconds |
| 22 | + }, |
| 23 | + rightRail: { |
| 24 | + id: 'div-gpt-ad-1738811978953-right-rail', |
| 25 | + sizes: [ |
| 26 | + // [160, 600], |
| 27 | + [300, 250], |
| 28 | + [250, 250], |
| 29 | + ], |
| 30 | + targeting: 'right-side-rail', |
| 31 | + refreshInterval: 45_000, // 45 seconds |
| 32 | + }, |
| 33 | + leftRail: { |
| 34 | + id: 'div-gpt-ad-1738811978953-left-rail', |
| 35 | + sizes: [ |
| 36 | + // [160, 600], |
| 37 | + [300, 250], |
| 38 | + ], |
| 39 | + targeting: 'left-side-rail', |
| 40 | + refreshInterval: 45_000, // 45 seconds |
| 41 | + }, |
| 42 | +} |
| 43 | + |
| 44 | +const googleScriptFn = (slots: typeof adSlots) => { |
| 45 | + window.googletag = window.googletag || { cmd: [] } |
| 46 | + googletag.cmd.push(function () { |
| 47 | + // Define all ad slots |
| 48 | + const slotInstances = Object.values(slots).map((slot) => { |
| 49 | + return googletag |
| 50 | + .defineSlot('/23278945940/TopLevel', slot.sizes, slot.id) |
| 51 | + .addService(googletag.pubads()) |
| 52 | + .setTargeting(slot.targeting, [slot.targeting]) |
| 53 | + }) |
| 54 | + |
| 55 | + googletag.pubads().enableSingleRequest() |
| 56 | + googletag.enableServices() |
| 57 | + |
| 58 | + // Set individual refresh intervals for each ad |
| 59 | + slotInstances.forEach((slotInstance, index) => { |
| 60 | + const slot = Object.values(slots)[index] |
| 61 | + setInterval(function () { |
| 62 | + googletag.cmd.push(function () { |
| 63 | + googletag.pubads().refresh([slotInstance]) |
| 64 | + }) |
| 65 | + }, slot.refreshInterval) |
| 66 | + }) |
| 67 | + }) |
| 68 | +} |
| 69 | + |
| 70 | +export function GoogleScripts() { |
| 71 | + return ( |
| 72 | + <> |
| 73 | + <script |
| 74 | + async |
| 75 | + src="https://securepubads.g.doubleclick.net/tag/js/gpt.js" |
| 76 | + ></script> |
| 77 | + |
| 78 | + <script |
| 79 | + dangerouslySetInnerHTML={{ |
| 80 | + __html: `(${googleScriptFn.toString()})(${JSON.stringify(adSlots)});`, |
| 81 | + }} |
| 82 | + /> |
| 83 | + </> |
| 84 | + ) |
| 85 | +} |
| 86 | + |
| 87 | +function Gad({ |
| 88 | + adId, |
| 89 | + children, |
| 90 | + ...props |
| 91 | +}: { adId: string } & React.HTMLAttributes<HTMLDivElement>) { |
| 92 | + React.useEffect(() => { |
| 93 | + window.googletag.cmd.push(function () { |
| 94 | + window.googletag.display(adId) |
| 95 | + }) |
| 96 | + }, []) |
| 97 | + |
| 98 | + return ( |
| 99 | + <div {...props} className="grid [&>*]:col-start-1 [&>*]:row-start-1"> |
| 100 | + <div id={adId} className="w-full flex-1 z-10"></div> |
| 101 | + <div className="flex items-center justify-center">{children}</div> |
| 102 | + </div> |
| 103 | + ) |
| 104 | +} |
| 105 | + |
| 106 | +export function GadLeader() { |
| 107 | + // return ( |
| 108 | + // <div className="overflow-hidden h-0 w-0"> |
| 109 | + // <Gad |
| 110 | + // adId={adSlots.leaderboard.id} |
| 111 | + // style={{ |
| 112 | + // maxWidth: '728px', |
| 113 | + // aspectRatio: '728 / 90', |
| 114 | + // }} |
| 115 | + // /> |
| 116 | + // </div> |
| 117 | + // ) |
| 118 | + |
| 119 | + return null |
| 120 | +} |
| 121 | + |
| 122 | +export function GadFooter() { |
| 123 | + return ( |
| 124 | + <Gad |
| 125 | + adId={adSlots.footer.id} |
| 126 | + style={{ maxWidth: '728px', aspectRatio: '728 / 90' }} |
| 127 | + /> |
| 128 | + ) |
| 129 | +} |
| 130 | + |
| 131 | +export function GadLeftRailSquare() { |
| 132 | + // return ( |
| 133 | + // <Gad |
| 134 | + // adId={adSlots.leftRail.id} |
| 135 | + // style={{ maxWidth: '300px', aspectRatio: '300 / 250' }} |
| 136 | + // /> |
| 137 | + // ) |
| 138 | + |
| 139 | + return null |
| 140 | +} |
| 141 | + |
| 142 | +export function GadRightRailSquare() { |
| 143 | + return ( |
| 144 | + <Gad |
| 145 | + adId={adSlots.rightRail.id} |
| 146 | + className="[aspect-ratio:250/250] xl:[aspect-ratio:300/250] flex items-center justify-center" |
| 147 | + > |
| 148 | + <Link |
| 149 | + to="/form" |
| 150 | + className="flex items-center gap-2 text-3xl font-black uppercase tracking-tighter h-full" |
| 151 | + > |
| 152 | + <span>TanStack</span> |
| 153 | + <span className="text-transparent bg-clip-text bg-gradient-to-r from-yellow-500 to-yellow-600"> |
| 154 | + Form |
| 155 | + </span> |
| 156 | + <span className="text-xs">V1</span> |
| 157 | + </Link> |
| 158 | + </Gad> |
| 159 | + ) |
| 160 | +} |
0 commit comments