Skip to content

Instantly share code, notes, and snippets.

@ReenaVerma
Last active May 4, 2022 10:23
Show Gist options
  • Save ReenaVerma/8fd35ecc765d57a7e49aa3f6cf1e3bf5 to your computer and use it in GitHub Desktop.
Save ReenaVerma/8fd35ecc765d57a7e49aa3f6cf1e3bf5 to your computer and use it in GitHub Desktop.
const getCookie = (c_name) => {
var i, x, y, ARRcookies = document.cookie.split(";");
for (i = 0; i < ARRcookies.length; i++) {
x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
x = x.replace(/^\s+|\s+$/g, "");
if (x == c_name) {
return unescape(y);
};
};
};
const setCookie = (cName, cValue, expDays) => {
let date = new Date();
date.setTime(date.getTime() + (expDays * 24 * 60 * 60 * 1000));
const expires = "expires=" + date.toUTCString();
document.cookie = cName + "=" + cValue + "; " + expires + "; path=/; domain=.ADD_YOUR_DOMAIN.com";
};
const cookieName = getCookie("_gaexp");
const removeLastNumber = cookieName.substr(0, cookieName.lastIndexOf("."));
// CHANGE THE NUMBER AFTER THE DOT HERE. EG REPLACE ".1", WITH ".2" OR ".0" ETC
let newCookieValue = removeLastNumber + ".1";
setCookie("_gaexp", newCookieValue, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment