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

168
Vistas
Fetch value of a specific Key from dataLayer Google Analytics

A website stores a lot of parameters into dataLayer google analytics and inside one of my javascript functions, I am thinking of using one of the parameters and used below code to iterate between the properties

    var articleId=0;
    var brandId=-1;
    $.each( dataLayer, function( key, value ) {
      console.log( key + ": " + JSON.stringify(value) );
    });

some of the values from JSON.stringify(value) are like below

    {"BrandID":0}
    {"BrandName":"  Group"}
    {"Title":"  announces electric   cranes"}
    {"PageType":"Article"}
    {"ArticleID":8009988}
    {"ArticleTitle":"  announces electric   cranes"}
    {"ArticleLayout":"Standard"}
    {"ArticleTypeID":"1"}
    {"ArticleTypeName":"Article"}
    .......................................

and many more

How can I fetch the BrandID and ArticleID out of this? Is there any way of doing this without iterating through all the items of dataLayer

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

There's a built in method in the google tag manager api to get values:

google_tag_manager['<container-id>'].dataLayer.get('gtm.start');

The container-id is that of your GTM container, something like GTM-XXXXXXX

Edit: for getting values from multiple containers on one page, you can loop through each container after getting their ID's:

Something like:

const containerIds = Object.keys(google_tag_manager).filter(key => key.includes('GTM-'));

const values = containerIds.map(id => google_tag_manager[id].dataLayer.get('gtm.start'));

console.log(values); // [value1, value2, ...]

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