From b8a027ab57aba29d64f300343d172123f00e0060 Mon Sep 17 00:00:00 2001 From: AykutSarac Date: Sun, 24 Jul 2022 23:39:21 +0300 Subject: [PATCH] fix carbonads --- src/components/CarbonAds/index.tsx | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/components/CarbonAds/index.tsx b/src/components/CarbonAds/index.tsx index 61c087f..a31c02b 100644 --- a/src/components/CarbonAds/index.tsx +++ b/src/components/CarbonAds/index.tsx @@ -1,3 +1,4 @@ +import Script from "next/script"; import React from "react"; import styled from "styled-components"; @@ -32,13 +33,25 @@ export const CarbonAds: React.FC<{ editor?: boolean }> = ({ editor = false, }) => { return ( - - + strategy="lazyOnload" + onLoad={() => { + const init = () => { + const parent = document.getElementById("carbon-wrapper"); + const ads = document.getElementById("carbonads"); + + if (ads === null) return setTimeout(() => init(), 500); + + parent?.appendChild(ads); + }; + + init(); + }} + /> ); };