Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

309
Vistas
How can i make sure my onetrust consent script is loaded before facebook pixel tracking NextJS

I need to have my Cookies consent script loaded as the first scrip in our NextJS application. My issue is that we have Facebook pixel tracking implemented and they have a parentNode.insertBefore so their script is always on top.

This is how we are using facebook pixel, and its from their own docs

const html = [
  "!function(f,b,e,v,n,t,s)",
  "{if(f.fbq)return;n=f.fbq=function(){n.callMethod?",
  "n.callMethod.apply(n,arguments):n.queue.push(arguments)};",
  "if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';",
  "n.queue=[];t=b.createElement(e);t.async=!0;",
  "t.src=v;s=b.getElementsByTagName(e)[0];",
  "s.parentNode.insertBefore(t,s)}(window,document,'script',",
  "'https://connect.facebook.net/en_US/fbevents.js');",
  `fbq('init', '111222333');`,
  "fbq('track', 'PageView');",
  `fbq('init', '1234');`,
  "fbq('track', 'PageView');",
].join("");

const DocumentFacebookPixel = () => (
  <>
    <script key="track-fb-pixel" dangerouslySetInnerHTML={{ __html: html }} />
  </>
);

export default DocumentFacebookPixel;

And this is the onetrust code

 const DocumentOneTrust = () => {
  return (
    <>
      <script
        src="https://url.com"
        type="text/javascript"
        charSet="UTF-8"
        data-domain-script="id-123-4"
      ></script>

      <script type="text/javascript">{function OptanonWrapper() {}}</script>
    </>
  );
};

export default DocumentOneTrust;

And i load my onetrust script component before the facebook, here:

class Document extends NextDocument {
  render() {
    return (
      <Html>
        <NextHead>
         <DocumentOneTrust />
        </NextHead>
        <body>
          <Main />
          <NextScript />
          <DocumentFacebookPixel />
        </body>
      </Html>
    );
  }
}


about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda