Google Tag Manager Debugging Quick Tips

Estimated Reading Time: 2 minute
April 10, 2017

Google Tag Manager’s preview mode allows you to browse a site on which your container code is implemented as if the current container draft was deployed.

In addition to using GTM Preview mode for debugging your GTM configuration here are two other quick tips to help you validate your configuration or assist you in testing your site more effectively.

Use Javascript to check if you are in Preview Mode

To make sure that you aren’t accidentally putting unnecessary console logs in your production environments you can add this conditional logic around your code.


var isGTMPreviewMode = {{Container Version}} == "QUICK_PREVIEW";
if(isGTMPreviewMode)console.log("Yay I'm only visible in preview mode!");

Log dataLayer pushes to the console

This is useful for being able to check what values are in the dataLayer on a site without having to dig through the dataLayer object each time to find the event you want to view.


var oldDLpush = dataLayer.push;
dataLayer.push = function(){
	oldDLpush();
	console.log(arguments[0]);
}

Check out our other Quick Tip about Google Tag Manager

Author

  • Seth Rujiraviriyapinyo

    Seth Rujiraviriyapinyo creates GTM implementations, automates changes using GA and GTM APIs, and supports multiple clients to implement analytics tracking across their sites. As an Analytics Engineer Seth specializes in using the GA and GTM APIs to master account management and standardization.

    View all posts
Last Updated: July 20, 2023

Get Your Assessment

Thank you! We will be in touch with your results soon.
{{ field.placeholder }}
{{ option.name }}

Talk To Us

Talk To Us

Receive Book Updates

Fill out this form to receive email announcements about Crawl, Walk, Run: Advancing Analytics Maturity with Google Marketing Platform. This includes pre-sale dates, official publishing dates, and more.

Search InfoTrust

Leave Us A Review

Leave a review and let us know how we’re doing. Only actual clients, please.

  • This field is for validation purposes and should be left unchanged.