Export All of Your Tags from GTM to a Spreadsheet Effortlessly

Are you looking to perform an audit or organize your Google Tag Manager (GTM) tags into a neat spreadsheet? You might have noticed GTM doesn’t offer a direct way to do this. But don’t worry, we’ve got a straightforward, no-coding-required solution for you!

Why Export GTM Tags to a Spreadsheet?

Whether it’s for auditing purposes or just to keep your digital marketing efforts organized, having your GTM tags in a spreadsheet can be incredibly helpful. It allows you to review and manage your tags efficiently, especially when you’re dealing with a large number of them.

Steps to Copy GTM Tags to a Spreadsheet

Our technique involves using a simple JavaScript snippet in your browser’s Dev Tools console. This script will extract all your GTM tags in a JSON format. From there, you can easily convert this JSON file into a CSV format using an online tool like this or a straightforward Python script (see example below).

This method is as simple as copy-pasting the code and following a few easy steps.

  1. Copy the script provided below
  2. Open GTM to the tags section (set to display all tags)
  3. Open Dev Tools (Ctr + Shift + C), go to Console, paste the script and click Enter
  4. Copy the resulting JSON object
  5. Go to this free JSON to CSV/Excel converter  and paste the JSON code
  6. Download the result in CSV or Excel format

 

Here is how the end result looks like:

The JavaScript Script to Use in Console of Chrome Dev Tools

Here’s the JavaScript script you’ll need to use:

				
					// Paste this script in the Console section of your browser Dev Tools.  
gtmData = [];

var button = document.querySelector(".suite.suite-up-button.md-button.md-standard-theme.md-ink-ripple.layout-align-start-center.layout-row");

// Extract the account name
var accountNameElements = button.querySelectorAll(".suite-up-button-text-secondary");
var accountName;
if (accountNameElements.length > 1) {
    accountName = accountNameElements[1].textContent.trim();
} else {
    console.log("Expected more than one .suite-up-button-text-secondary element, found less");
}

// Extract the GTM container name
var gtmContainerNameElement = button.querySelector(".suite-up-text-name");
var gtmContainerName = gtmContainerNameElement.textContent.trim();

// GTM Container ID
var gtmNumber = document.querySelector('.gtm-container-public-id.md-gtm-theme').textContent.trim();

document.querySelectorAll('tr[gtm-table-row]').forEach(n => {
    const td2 = n.querySelector('td:nth-child(2)');
    const td3 = n.querySelector('td:nth-child(3)');
    const td4 = n.querySelector('td:nth-child(4)');
    const td5 = n.querySelector('td:nth-child(5)');

    const triggerName = td2 ? td2.textContent.trim() : '';
    const eventType = td3 ? td3.textContent.trim() : '';
    const firingTriggers = Array.from(n.querySelectorAll('td:nth-child(4) .small-trigger-chip')).map(conditionElement => conditionElement.textContent.trim());
    const lastEdited = td5 ? td5.textContent.trim() : '';


    // To find if Tag is currently paused 
    let paused;
    if (td5) {
        const lastEditedClassNames = Array.from(td5.childNodes).filter(child => child.clientHeight > 0);
        paused = lastEditedClassNames.length !== 0;
    } else {
        console.log("No td:nth-child(6) found.");
    }

    const tag = {
        Account: accountName,
        Property: gtmContainerName,
        GTM_Container: gtmNumber,  
        Name: triggerName,
        Type: eventType,
        Firing_Triggers: firingTriggers,
        Last_Edited: lastEdited,
        Currently_Paused: paused
    }

    gtmData.push(tag);
})

console.log(gtmData); // To see the output in console
				
			

 

Just copy and paste this script into your browser’s console when you have your GTM container open to the Tags section. It will automatically gather all your tag details including:

  • Account name 
  • Container ID
  • Tag Name
  • Tag Type
  • Firing Triggers
  • Last edited 
  • Tag Paused (true/false) 

Copy the Tags (JSON Object)

Once you have your JSON, right click on it and copy:

Convert to CSV/Excel and Download

Then head over to this free online JSON to CSV converter for an easy conversion to CSV.

Here is how the end result will look like:

 

Alternatively, if you’re comfortable with a bit of Python, here’s a simple script that helps you convert your saved JSON file (you’ll have to copy that JSON and save it on your computer with .json extension):

				
					# Convert JSON object to CSV

import pandas as pd

# Create DataFrame from JSON file
df = pd.read_json('file.json') # path to your JSON file 

# Save DataFrame to CSV file
df.to_csv('file.csv', index=False) # target path and file name



				
			

And there you have it! A quick and hassle-free way to get your GTM tags organized into a spreadsheet. This method is perfect for digital marketers, SEO specialists, or anyone who needs to audit or organize their GTM tags without diving deep into coding.

Remember, efficient data organization is key to a streamlined digital strategy, and with this simple technique, you’re well on your way to achieving just that. Happy organizing!

Leave a Reply

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