{"id":4836,"date":"2020-12-22T12:07:22","date_gmt":"2020-12-22T09:07:22","guid":{"rendered":"https:\/\/trackingchef.com\/?p=4836"},"modified":"2024-10-28T19:03:25","modified_gmt":"2024-10-28T16:03:25","slug":"debugging-gtm-with-integromat-google-sheets","status":"publish","type":"post","link":"https:\/\/trackingchef.com\/google-tag-manager\/debugging-gtm-with-integromat-google-sheets\/","title":{"rendered":"Debugging GTM with Integromat & Google Sheets"},"content":{"rendered":"\n
One of the challenges when working with Google Tag Manager (GTM) is the gap between preview mode and actual deployment.<\/p>\n\n\n\n
Plenty of times, you deploy a tag with a certain configuration, and results show up entirely different. Sometimes this is due to the nature of edge cases that you didn’t think about or couldn’t simulate on your machine.<\/p>\n\n\n\n
One tactic I’ve found for tracing back the source of the issue is simply logging the tag fired and its variables. This is done by capturing all these in an HTTP POST webhook that logs these in a Google Sheets spreadsheet.<\/p>\n\n\n\n To capture the webhook and pass the data to Google Sheets I’ve used Integromat<\/a>, which is my go-to tool for automations, but you can also use Zapier just the same. You can create a free Integromat account here<\/a>, and their pricing is very reasonable compared to Zapier.<\/p>\n\n\n\n Log into your Integromat account and create a new scenario. For the scenario, select Webhooks and Google Sheets (can also do this later).<\/p>\n\n\n\n Select the Webhooks module as the first step and click “Custom Webhook”.<\/p>\n\n\n\n Click Add to create a new webhook URL and give it a descriptive name, e.g. GTM Logger.<\/p>\n\n\n\n Copy the webhook’s URL and have it available.<\/p>\n\n\n\n In GTM, open the tag you want to log. Identify the specific variables it uses and the trigger that applies to it.<\/p>\n\n\n\n Then, create a new tag of the Custom HTML. In the tag’s body, paste the following snippet.<\/p>\n\n\n\n Paste the webhook URL from Integromat in the appropriate place.<\/p>\n\n\n\n As an extra way to analyze, I’ve also added the current Data Layer to be sent with the webhook. No changes are required here.<\/p>\n\n\n\n The payload data sent to the webhook is structured as a JSON. This means that each variable has a pair of key and name separated by a colon, e.g. “orderId” : “12345”<\/em>.<\/p>\n\n\n\n In this example the date sent comes from a Google Ads tag, so I wanted to capture the values sent in its different variables:<\/p>\n\n\n\n { The values using Curly brackets {{ are variables from GTM, same as the ones used in the Google Ads tag I was debugging.<\/p>\n\n\n\n The Currency was set as a constant, so I didn’t use a variable but rather set it as a string.<\/p>\n\n\n\n The DL is simply the Data Layer captured at that moment.<\/p>\n\n\n\n You can edit any of these, add and remove, to tailor this to the payload you want to capture. <\/p>\n\n\n\n For example, when debugging a a Google Analytics event you can send:<\/p>\n\n\n\n { After adjusting the tag’s structure, you can add a trigger to the tag. Most likely this will be the same trigger as the tag you’re debugging.<\/p>\n\n\n\n After you’ve set up the Custom HTML you can publish it and wait for a request to be sent (you can trigger on yourself of course).<\/p>\n\n\n\nCreating the Integromat Scenario<\/h2>\n\n\n\n
<\/figure>\n\n\n\n
<\/figure>\n\n\n\n
Creating the Logger tag<\/h2>\n\n\n\n
<script>\nvar xhr = new XMLHttpRequest();\n\n\/\/ Paste below the webhook URL from Integromat\nvar url = \"https:\/\/hook.integromat.com\/abcdefg1234567\";\n\nvar dl = dataLayer;\ndl = dl[dl.length -1];\ndl = JSON.stringify(dl);\nxhr.open(\"POST\", url, true);\nxhr.setRequestHeader(\"Content-Type\", \"application\/json\");\n\n\/\/This is the payload data sent to the webhook\nvar data = JSON.stringify({\n \"id\": {{Google Ads ID}},\n \"label\": {{Google Ads Label}},\n \"value\": {{Product price USD}},\n \"orderid\": {{Transaction ID}},\n \"currency\": \"USD\",\n \"dl\":dl\n});\n\nxhr.send(data);\n<\/script><\/code><\/pre>\n\n\n\n
Webhook URL<\/h3>\n\n\n\n
Data Layer<\/h3>\n\n\n\n
Payload Data<\/h3>\n\n\n\n
“id”: {{Google Ads ID}},
“label”: {{Google Ads Label}},
“value”: {{Product price USD}},
“orderid”: {{Transaction ID}},
“currency”: “USD”,
“dl”:dl
}<\/p>\n\n\n\n
“eventCategory”: {{eventCategory}},
“eventAction”: {{eventAction}},
“eventLabel”: {{eventLabel}},
“eventValue”: {{eventValue}},
“nonInteraction”: {{nonInteraction}},
“dl”:dl
}<\/p>\n\n\n\nTrigger<\/h3>\n\n\n\n
Sending the request data<\/h2>\n\n\n\n
\n