Read a Cookie With Google Tag Manager

Learn how to extract the value of a first-party cookie in a Google Tag Manager variable.

Published Categorized as Analytics

You can read the value of a first-party cookie in Google Tag Manager using the “1st Party Cookie” variable. Once you’ve set up the variable, you can pass the value to your tags and custom code.

Google Tag Manager can’t read third-party cookies—that is, cookies set by domains other than the one you are currently on. So if you have scripts on your site that drop cookies and you need to read their contents in GTM, make sure these cookies are first-party cookies.

How to Read a Cookie With Google Tag Manager

Step 1: Fire up your browser, go to Google Tag Manager, and open the GTM container you’d like to edit.

Step 2: Navigate to “Variables” from the left sidebar.

Navigating to the “Variables” tab

Step 3: Create a new user-defined variable.

Creating a new user-defined variable

Step 4: Under “Variable Configuration,” click on “Choose a variable type to begin setup…”

Step 5: The “Choose variable type” window will slide in. Look for “Page Variables” and select “1st Party Cookie.”

Creating a 1st Party Cookie variable

Step 6: Enter the name of your cookie under “Cookie Name.”

Select “URI-decode cookie” if your cookie contains URI-encoded characters, which you would like to be decoded from UTF-8 to regular, human-friendly characters.

Setting up the cookie variable

Step 7: Hit “Save,” then test your setup in Google Tag Manager’s Preview mode.

If the first-party cookie is there, your newly-configured variable should be readable at every event in the “Summary” sidebar.

(In case the cookie gets deployed by a tag after a certain event, make sure to look for it after that event has taken place and provided the tag has fired.)

By Dim Nikov

Editor of Maker's Aid. Part programmer, part marketer. Making things on the web and helping others do the same since the 2000s. Yes, I had Friendster and Myspace.

Leave a comment

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