#tip – Grabbing current dataLayer variable name within GTM

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 🙂

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.