Set a cookie with the Google Tag Manager

It is possible to set of edit (re-setting) a cookie for storing information during a vistor session.

Create a Custom Html Tag with the following code:

This wil look like:

setCookie4

Next step is setting a trigger when the trigger had to fire.

To read out the value of your cookie, you have to create a new 1st Party cookie variable.

setCookie5

The Cookie name is the name you have chosen by setting it. In my example it is nameOfTheCookie, but you have to change this to your own.

If you would like to retrieve te current value of your cookie you could make use of the EditThisCookie extension for Chrome.

Was it interesting? Share it, so someone else can read this too!Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

2 thoughts on “Set a cookie with the Google Tag Manager”

  1. Hi Marthijn,

    Great post! I have a question regarding storing multiple values within one cookie. Would this be possible with the script posted above and can these multiple values be used in the 1st Party cookie option in GTM? Since it is focused around one cookie name..

    Or for multiple values i just would have to make multiple cookies?

    1. Thanks for these very simple instructions. Much appreciated.

      There is a step missing after “Next step is setting a trigger when the trigger had to fire.”

      You need to navigate to “Variables”, then click New, then select User Defined Variable. This will open the screen to create a new 1st party cookie

Leave a Reply

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