There is a TON of javascript information out there, but I can't seem to put it all together. Through Google Tag Manager I've created a script to create a Cookie. I then used a 1st party variable to capture that value. This looks to be working. In the developer toolbox, in cookies, I can see the cookie with the name "LandingPage" and value of "/XYZ/". There are several other cookie values as well, but I'm focused on this particular one. What I can't figure out is how to read/display that particular "LandingPage" value.
For simplicity of learning, I was just trying to create a function, like an alert, to display the value of "LandingPage", which is "/XYZ/". I just haven't been able to get the LandingPage value to display.
Below is the code I'm using to set/create the cookie.
<script>
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
createCookie("LandingPage","{{Page Path}}")
</script>
In Google Tag Manager (GTM) you can easily access 1st party cookies with GTM's built-in variable called "1st Party Cookie". You need to provide a valuable name for your reference, e.g. "Landing Page Cookie Value", and also provide the name of the cookie, which is LandingPage in your case. You can reference this variable in any built-in tags, other variables, or even in custom HTML (script) codes: {{Landing Page Cookie Value}} based on the example name in this post. The variable should contain the value of your cookie.
Edit, detailed explanation
This is exactly the code, copied from the original post. I'm creating a new Custom HTML tag, which is run on all pages during page load.
This is my setting to create the variable, referencing the same cookie name.
I have also created a very simple custom HTML tag, which runs on any click event. So by simply clicking anywhere on the page, it'll trigger the code to run. It tries to display the content of the recently created Cookie variable in the console.
By opening my test page, after having turned on GTM preview mode, I can see my first tag having run on pageview.
Performing the click, I get the originally stored value in the console: