Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda