Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Cargando etiquetas de anuncios de Google dinámicamente usando JavaScript

Seré breve y claro.

Tengo el siguiente código:

 <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'AW-10794286619'); </script> <script> gtag('event', 'conversion', { 'send_to': 'AW-10794286619/ZYX_CI3l2JEDEJv8jpso', 'transaction_id': '' }); </script>

Sabiendo que "AW-10794286619" y AW-10794286619/ZYX_CI3l2JEDEJv8jpso son VARIABLES CARGADAS DESDE EL SERVIDOR, ¿cómo puedo cargar esa secuencia de comandos (agregándola en HEADER y ejecutándola) desde javascript y hacer que funcione?

Esto es lo que he intentado:

 let googleTag = 'VALUE FROM SERVER' let initiateCheckoutGoogleA let initiateCheckoutGoogleB let initiateCheckoutGoogleC initiateCheckoutGoogleA = document.createElement('script') initiateCheckoutGoogleA.src = `https://www.googletagmanager.com/gtag/js?id=${googleTag.split('/')[0]}` initiateCheckoutGoogleA.async = true document.head.appendChild(initiateCheckoutGoogleA) initiateCheckoutGoogleB = document.createElement('script') initiateCheckoutGoogleB.innerHTML = `window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', ${googleTag.split('/')[0]});` document.head.appendChild(initiateCheckoutGoogleB) initiateCheckoutGoogleC = document.createElement('script') initiateCheckoutGoogleC.innerHTML = `gtag('event', 'conversion', { 'send_to': ${googleTag}});` document.head.appendChild(initiateCheckoutGoogleC)

Me da el siguiente error:

ingrese la descripción de la imagen aquí

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!