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

121
Vistas
function to return innerhtml of clicked class in google tag manager

I need a variable in Google Tagmanager which returns the innerhtml of a clicked class. Since there are more elements with this class I have to add an event listener to the classes and return the innerhtml of the clicked element.

Unfortunately my code keeps returning 'undefined'.

document.querySelectorAll(".myclass").foreach(function (item) {
  item.addEventListener("click", function(event) {
    return event.innerHTML;
  })
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Okay, so a variable that returns inner html of a clicked element (you don't click classes, you click elements).

  1. Make a click trigger where you would use whatever CSS selector you need it to work for.

  2. Make a Custom JS variable like so:

    return {{Clicked Element}}.innerHTML;

  3. Now you can make a tag where you would use your trigger and your CJS variable.

No need to add your own event listeners when GTM is perfectly capable of doing it for you. While you certainly still can add your event listeners and pass the data from them to GTM through the dataLayer, you're increasing the complexity needlessly.

about 4 years ago · Juan Pablo Isaza Denunciar
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