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

166
Views
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 answers
Answer question

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 Report
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!