Skip to main content
  1. Blog Post/

#tip - Grabbing current dataLayer variable name within GTM

1 min · 115 words

This is going to be a quick #tip post. and it's coming from a post on Measure Slack.

Let's learn how to grab the current dataLayer variable name within GTM. We'll need to create a variable with the following code:

function() {
    return Object.values(window.google_tag_manager).find(function(e) {
        if (e.dataLayer) return true;
    }).dataLayer.name;
}

Now our variable should hold the dataLayer name :)