first of all, I am a total beginner what comes to JavaScript.
Here is my issue: I am trying to create a script + cookie that stores the URL parameters of the website visitor. I am using Google Tag Manager to run the script, so all that I have left to do is finalize the code.
I've been working on this for a few days now and this is how far I've been able to get (the code below).
var cookieName = test-4
function SetCookieValue(cookieValue) {
var url = window.location.href;
if(url.indexOf('test-4=') !== -1)
document.cookie="test-4";
}
var expirationTime = 2592000; // One month in seconds
expirationTime = expirationTime * 1000; // Converts expirationtime to milliseconds
var date = new Date();
var dateTimeNow = date.getTime();
date.setTime(dateTimeNow + expirationTime); // Sets expiration time (Time now + one month)
var date = date.toUTCString(); // Converts milliseconds to UTC time string
function SetCookie(accountCookie) {
document.cookie= cookieName+"="+cookieValue+"; SameSite=None; Secure; expires="+date+"; path=/; domain=." + location.hostname.replace(/^www./i, ""); // Sets cookie for all subdomains
}
Currently, with this code no cookie is injected when the code is run when the Google Tag Manager tag is triggered.
To my understanding, the problem lies in either the first 5 lines or the last 4 lines, as the cookie expiration works fine when used separately (this code is made by combining two codes I found on cookie injection).
Any ideas to get me going again?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…