Export Google Tag Manager data into Spreadsheets

A guide for effortlessly exporting and organising Google Tag Manager data

  • Article
  • Technical Web Analytics
Export GTM data into spreadsheets

Exporting Google Tag Manager (GTM) Tag Trigger and Variable information from your container into a spreadsheet can be useful for many reasons. You might want to do an Audit on the container of your new client, or just clean and organise an old container that you are working with for a long time. However, this functionality is not supported by default from GTM. In this article, we will explore various methods to export GTM container information and help you choose the best option based on your needs.

GTM tools add-on

While searching for an easy solution, the first thing I found was the GTM tools add-on for Google Sheets by Simo Ahava. This is a very good solution for many reasons. First, it is easy to use; you simply install the add-on, click one button in Google Sheets, and the job is done! It provides essential information such as tag names, trigger names, and variable names, as well as details about tag type, trigger type, and variable type.

However, this add-on has its limitations. Since it relies on the Tag Manager API to retrieve information, it can only provide what the Tag Manager API offers. For example, the only information provided for the Firing Triggers is a "Firing Trigger ID", which does not offer much insight to the user. The same applies for the Exception Triggers.

GTM triggers

Ideally, you would want the actual names of the firing triggers and exception triggers for each tag, not just an ID. Mapping the firing trigger ID to the trigger name requires additional work in Google Sheets. Another drawback of the Tag Manager API, and consequently the GTM Tools add-on, is that some returned values for tag type and variable type can be confusing and require extra effort to interpret. Here are some examples of tag types returned by the Tag Manager API:

GTM tag type

Would you have guessed the tag type without searching for it in your container? I could not. Additionally, if you want to know whether a tag is paused, you need to search through the JSON returned in column K. This is because the information is not properly presented in the columns.

tag paused GTM

How can we avoid these blockers that complicate the process?

I found the solution in an article of Axon Digital. They provided a script that you can copy and paste into your console to return a JavaScript object containing all the necessary information . You can then use a JSON-to-CSV converter to convert the JS object into CSV format and import the CSV into Excel or Sheets.

The only thing I was missing from this solution was that this script was working only for the Tags page and not for the Triggers or Variables.

So, I modified Axon Digital's script and created two scripts, one for the Triggers page and one for the Variables page. The procedure is the same: copy and paste these scripts into your console to retrieve information for your GTM Triggers and Variables.

Since these scripts scrape information from the Google Tag Manager HTML, they depend on the stability of the selectors used. As we all know in tagging, that stability doesn't last forever. These scripts were evaluated at the time of publishing. If you try to use them and they no longer work please let us know, and we will update the script. 

Try out these scripts and streamline your GTM data export process. Below are the scripts you need to get started:

GTM Triggers Script

// 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 td6 = n.querySelector('td:nth-child(6)');

const td7 = n.querySelector('td:nth-child(7)');



 

const triggerName = td2 ?td2.textContent.trim() : '';

const eventType = td3 ?td3.textContent.trim() : '';

const triggerFilters = Array.from(n.querySelectorAll('td:nth-child(4) .gtm-predicate-summary-row')).map(conditionElement => conditionElement.textContent.trim());

const folder = td5 ?td5.textContent.trim() : '';

const tags = td6 ?td6.textContent.trim() : '';

const lastEdited = td7 ?td7.textContent.trim() : '';

 

 

 

const tag = {

Account: accountName,

Property: gtmContainerName,

GTM_Container: gtmNumber,

Name: triggerName,

Type: eventType,

Folder: folder,

Tags: tags,

Last_Edited: lastEdited,

Trigger_Filters: triggerFilters

}

 

gtmData.push(tag);

})

 

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

GTM Variables Script

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

 

// get the account / container element and store it in a variable named "button"

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

 

// Get the All Accounts > {{account name}} elements in array format and store them in a variable

var accountNameElements = button.querySelectorAll(".suite-up-button-text-secondary");

 

// Extract the account name

var accountName;

 

if (accountNameElements.length > 1) {

accountName = accountNameElements[1].textContent.trim();

} else {

//if there is no account name element

console.log("Expected more than one .suite-up-button-text-secondary element, found less");

}

 

 

// Extract the GTM container element

var gtmContainerNameElement = button.querySelector(".suite-up-text-name");

 

//Get the GTM Container name

var gtmContainerName = gtmContainerNameElement.textContent.trim();

 

// GTM Container ID

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

 

 

document.querySelectorAll('div[data-table-id="variable-list-user-defined"] tr[gtm-table-row]').forEach(n => {

//get the second column value and store it in a variable

const td2 = n.querySelector('td:nth-child(2)');

//get the third column value and store it in a variable

const td3 = n.querySelector('td:nth-child(3)');

//get the fourth column value and store it in a variable

const td4 = n.querySelector('td:nth-child(4)');

const td5 = n.querySelector('td:nth-child(5)');

 

//remove whitespaces and store the value in a new variable. Also if the value does not exist set an empty string.

//tags

const variableName = td2 ?td2.textContent.trim() : '';

//event type

const type = td3 ?td3.textContent.trim() : '';

//firing triggers

const folder = td4 ?td4.textContent.trim() : '';

//last edited

const lastEdited = td5 ?td5.textContent.trim() : '';

 

const tag = {

Account: accountName,

Property: gtmContainerName,

GTM_Container: gtmNumber,

Name: variableName,

Type: type,

Folder: folder,

Last_Edited: lastEdited

}

 

gtmData.push(tag);

})

 

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

Convert JSON to CSV/Excel

As mentioned in the Axon Digital article, the last thing you need to do is to convert the JavaScript Object returned to the console into a CSV.

GTM export to spreadhseet

To achieve this you can either use a free JSON to CSV converter or if you are familiar with Python you can also use the following script:

# 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 

We’re ready to help

I hope this article was useful and saves you time and energy when organising your GTM containers. Would you like to get help with streamlining your GTM data export process? Feel free to reach out to us.

An article by Nearchos Katsanikakis

Nearchos works as a Technical Web Analyst at Digital Power. He has worked for both small and large companies to implement robust tracking solutions with Google and Adobe Analytics.

Nearchos Katsanikakis

Receive data insights, use cases and behind-the-scenes peeks once a month?


Sign up for our email list and stay 'up to data':

You might also like:

Transform your web- and app data into actionable insights with server-side tracking

Server-side tracking is the process of collecting and processing data through a server rather than on the user's device. By migrating your tagging implementation to a controlled server environment, you improve data accuracy and protect user privacy. Turn your data into actionable insights and gain a full understanding of your users' interactions.

Read more

What is Tagbird, what do you use it for, and what can you do with it?

Tagbird is a Chrome extension developed by Digital Power. You can download it from the Chrome Web Store and add it to your browser. It is a debug/visualisation tool that provides a simple and clear insight into, among other things, the data layer, tag management events and analytics requests of a website. So you can quickly and easily test your entire analytics implementation with Tagbird.

Read more

How good Is your web analytics implementation?

How confident is your company in its web analytics data? In this article, we’ll first explain why web analytics tools can never provide 100% accurate data and why that’s not necessarily a bad thing. Then, we’ll dive into the practical side of things: how reliable are most web analytics implementations?

Read more

The impact of server-side tracking on privacy

In the digital age, where data privacy has become a forefront concern, server-side tracking stands out as a crucial tool for organisations aiming to gather user insights responsibly. Despite its potential, numerous myths surround its use and compliance with regulations. This article dispels these myths, offering a nuanced view of server-side tracking, its compliance with privacy laws, and the role of consent in its execution.

Read more

What is not server-side tracking?

Server-side tracking is becoming a hot topic among agencies, marketeers and analysts. A lot of information is available on the subject, but it is not always accurate. Server-side tracking has often been sold as a miracle solution against data loss, GDPR and other unethical challenges.

Read more

The impact of ITP on analytics and the user experience​

Intelligent Tracking Prevention (ITP) was launched by Apple in 2017 in an effort to restore "the balance the balance between privacy and the need for on-device data storage". With Intelligent Tracking Prevention, Apple aims to reduce cross-site tracking (following users across websites) by limiting the use of cookies. Find out what this means for you.

Read more

How can you tell if your GTM tagging server works?

There are reasons abound for deploying a tagging server on your website. This blog will not be about why it makes sense (or why perhaps in your case it doesn’t) to use server-side tagging. Instead we will jump forward in time and ask ourselves another pertinent question: ‘how can you tell if your tagging server is doing what it is supposed to?’

Read more

Switching from Universal Analytics to Google Analytics 4 (GA4)

On 14 October 2020, Google launched the new version of Analytics: Google Analytics 4 (GA4). Soon after the launch, it became clear that a number of important functionalities from Universal Analytics (GA3) were missing, and therefore the time to switch seemed far away. Fortunately, we see that the development team on the side of Google has not been idle. Some nice features have since been introduced within GA4 that have narrowed the gap between GA3 and GA4. This article answers the questions that are increasingly being asked about GA4.

Read more

Integration web and app data contributes to a 360-degree customer view

Univé is a Dutch insurance company that offers insurance, financial products, and services to both consumers and businesses. The company is focused on providing high-quality service and helping customers make responsible financial decisions. Since 2014, we have been working closely with Univé.

Read more

Which data traineeship is right for you?

You are almost done with your studies and looking for an employer that offers you the opportunity to learn everything about the field of data. Or you are no longer challenged in your current position and would like to become more technical. In both cases, you do not want to follow unpaid courses, but you would like to get started as soon as possible for real customers, with a serious salary. Does this sound familiar? Then these data traineeships are really something for you.

Read more

What are cookies?

Cookies. This word comes up a lot in the world of marketing and online analytics. But what exactly are those cookies? And are there different types of cookies?

Read more

Measure ecommerce events in GA4 and Universal Analytics with only the updated datalayer pushes

With our variable in the Google Tag Manager Community Template Gallery it is easy to start using all the new ecommerce analytics capabilities that Google Analytics 4 offers while fully supporting the 'old' enhanced ecommerce of Universal Analytics. Find out how the variable works.

Read more

How do I set up Google Tag Manager?

A tag management system such as Google Tag Manager (GTM) enables you to measure visitor behaviour on your website. You can also implement marketing pixels (such as Google Ads and Facebook) and cookie banners via this platform. This article gives you tips to keep in mind when setting up GTM. This allows you to collect reliable and usable data, and you will be less dependent on your web developers.

Read more