Skip to content
ANALYTICS

#tip – Grabbing current dataLayer variable name within GTM

David Vallejo •
Share

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 🙂