Hey there digital tracking enthusiasts.
This is Sofiia from MeasureSchool.com. And today I will show you how to set
a first party cookie and store your value in it.
And to be able to do that you would need
your web page as well as your Tag Manager account.
And please make sure your Tag Manager is implemented on your web page.
Okay. So let's dive into it.
You might ask why would I need this kind of tracking?
Well let's have a look at my situation.
So here I have my checkout page and you
can see the revenue and I want to track the revenue.
But on the confirmation page and if I make
a purchase, you can see that my price is not available on the thank you page.
But I want to grab it somehow.
And if you use the Tag Manager and reload
the page, the value is not saved anywhere and we have to remember it somehow.
And one of the options to do that is
actually to use a cookie and I will show you how to do that.
Okay. So let's go and make a purchase again.
So step number one is to grab the value we want to track.
Okay.
So I'll add my product to cart and let's view cart.
And here we have the revenue.
So we want to grab it somehow and I will
use an extension which is called a GTM variable builder.
So let's right click and then inspect.
And here we just console and we should
highlight the value we want to track and click on this extension.
And here we have the instructions paste this into the console to test.
Okay, so let's do that.
I will copy it and paste it here and I can see my revenue.
So it seems to be correct.
This means I can use this function in my Tag Manager.
Amazing. So let's copy our function here.
Let's go to the Tag Manager and we should create a variable.
So let's go to variables and here use
the define variables new variable configuration.
And this should be a custom JavaScript variable and we can paste it here.
And let's provide a name.
So we'll say custom JavaScript revenue and let's save it.
So this is our total price.
This is our revenue.
The step number two is to set a cookie and there are multiple ways to do that.
So you could use the custom HTML tag for example.
Or you could create a custom JavaScript variable for that.
But there is a very nice solution and I will use a template.
And thank you so much for the outstanding
contribution to the Tag Manager development.
So let's go to templates and we can search Gallery here
and we should type cookie.
And this is our template cookie creator.
So let's choose this template and we should add it to workspace.
Let's click add. Great.
And before we can actually use this template we should configure it.
So let's click cookie creator one more
time and we should give several permissions to be able to use it.
So let's go to permissions, set cookie and here we should list all
the cookies that we want to use and provide their names.
In my case I would say I want to use multiple cookies.
So this is why I can use an Asterisk
symbol and I will simply add it and save. So,
If you make some modifications.
The template cannot be updated automatically.
But don't worry, you can do that manually.
So we click continue.
Now our template is ready to use.
So step number three is to create a tag. So
Let's go to Tags and click New Tag
configuration and let's look for Cookie creator and cookie name.
Let's say revenue and we should choose
the value and we created our variable for that.
So this is custom JavaScript revenue. Great.
Here we have the expiration mode so you
can choose the period for your cookie to expire.
I would say by month.
But this is according to your business needs.
This setup should be fine but maybe
the most attentive have noticed that I have a subdomain.
If you have a subdomain you should do an additional setup.
So let's click advance settings, set domain, enable domain option your domain.
Then we should provide auto
and then set path enable path option and we put a slash here.
Great. So everything is set up correctly.
And now we can also add our trigger.
So let's click triggering and we should create a new trigger.
Trigger configuration.
So what trigger should I use in this case?
Let's go back to our checkout page
and here you can see that the revenue is available on this specific subpage.
So I can actually use this part of the URL.
I can copy it and I will say okay, this is the subpage where I want to set
a cookie and we should use actually Dom ready.
Why? Because we have to make sure that all
elements are rendered and we can access their values.
Okay.
So let's choose some Dom ready events page URL contains and we can paste checkout here.
And let's provide a name.
So checkout great.
And let's save our trigger.
And we should also provide a name for our tag.
So let's say set cookie revenue and let's save our tag.
Great.
So now we should actually preview what is happening.
So let's click preview.
Okay, so let's have a look.
Here is my custom JavaScript variable and the value is correct.
And now let's have a look at our cookie.
We can do right click Inspect
and then we go to application and here we can look for revenue and here
you can see the correct value and let's make a test purchase.
And the value is also here.
Well done.
So now we can use this value and set up some additional text.
And the next question would be how can I actually grab it.
Where can I store it?
This is why we have to go back to the Tag Manager and we can create an additional
variable so let's go to variables click new variable configuration and here we
have first party cookie and our variable name should be revenue because this is
exactly the name of our cookie and here we can write first party cookie revenue
and let's check if this is working so let's preview our page one more time.
Okay.
So let's make a purchase again so let's go to home and let's buy a beautiful product.
Here is my cart
this is my checkout page so let's go back
to our preview and let's check what we can see here.
So if I check my variables
we can see that the first party cookie has
this value and then here the custom jobs also has a value and this is exactly our
revenue and now let's make a test purchase to see if the web page can
remember our value and we can also check it here right click inspect
application
and let's look for our revenue and we can
see the value here and now you can also have a variable in the tag manager
which you can use for your future Tags if you want to work with this value.
If you managed to set this up good job.
So guys I wish you happy measuring till next time.
All right. Thanks.
Sofiia for these great insights.
If you guys want to see more Google Tag
Manager implementation videos we have one linked up right over here which should be
quite interesting and from everybody here at measureschool happy measuring.