Set a 30 day cookie window

laurenq
New Member
22 0 0

Hi!

 

I have just signed up with an Affiliate company and want to set a 30-day cookie window on my Shopify Site. How do I do that?

 

Thank you so much!!

 

Signed,

Lost and Confused.

0 Likes
Greg_Kujawa
Shopify Partner
951 80 203

Assuming you are using front-end JavaScript, here are some details --> https://www.w3schools.com/js/js_cookies.asp.

 

0 Likes
laurenq
New Member
22 0 0
Hi Greg, Thanks for your message. How do I know if I'm using a front-end
JavaScript?
0 Likes
Greg_Kujawa
Shopify Partner
951 80 203

If you are working within the Shopify admin area to manage content, then you are probably using Liquid, standard HTML/CSS, and JavaScript. Are you working within Shopify's admin area or creating a separate app?

0 Likes
laurenq
New Member
22 0 0
I am working directly within in Shopify's admin area.
0 Likes
Greg_Kujawa
Shopify Partner
951 80 203

Then you could add something like this into the particular form you are looking to add a cookie to. Roughed up example :)

 

<script>
function setCookie(cname, cvalue, exdays) {
  var d = new Date();
  d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
  var expires = "expires="+d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}

function getCookie(cname) {
  var name = cname + "=";
  var ca = document.cookie.split(';');
  for(var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

function checkCookie() {
  var user = getCookie("username");
  if (user != "") {
    alert("Welcome again " + user);
  } else {
    user = prompt("Please enter your name:", "");
    if (user != "" && user != null) {
      setCookie("username", user, 365);
    }
  }
}

setCookie("mycookie","myvalue", 30)
</script>
0 Likes
laurenq
New Member
22 0 0
I am working with an affiliate and am brand new to cookies. Would I only
add it on the checkout page? I need them to be able to keep track of what
is sold when the customer comes via their site, so they can receive
commission.
0 Likes
Greg_Kujawa
Shopify Partner
951 80 203

I gave you a pretty practical sample of what would be included on your checkout page :) If you have other questions, your affiliate's support folks might have some other specific suggestions!

0 Likes
laurenq
New Member
22 0 0
Ok. Thanks for your help!!
0 Likes