cookies - How to set and use session variables in shopify liquid file? -


I need to set session variables in shopify but no documents found for it.

When the user logs into the shopify app, this session creates a session (or cookie), so how can it be done manually My needs Some input data on a particular page can be used on another page It is intended to be achieved by the session variable.

Please be sure to shopify or not, please reply if possible, please try pasting some code. If not, how can I do it in Shopify?

Thank you.

Not sure that you have ever thought of it, but here's how I used javascript Has tracked the referral landing page:

I added a landing page with the code () that redirects to the main shop page after collecting the cookie.

  & lt; Script & gt; Function getParameterByName (name, url) {if (! Url) {url = window.location.href; } Name = name.replace (/ [\ [\]] / g, "\\ $ & amp;"); Var regex = New RegExp ("[? & Amp;]" + name + "(= ([^ & amp; #] *) | | | | | | | | $)"), result = regex.exec ( Url); If (! Result) return zero; If (! Results [2]) return ''; Return Decoderi Company (Results [2] .replace (/ \ + / g, "")); } Function set cookie (cname, cvalue, exdays) {var d = new date (); D.setTime (d.getTime () + (exdays * 24 * 60 * 60 * 1000)); Termination of var = "end =" + d.toUTCString (); Document.cookie = cname + "=" + cvalue + ";" + Finished + "path = /"; } SetCookie ('referrals', getParameterByName ('referee', blank, 1)); Window.location = 'http://www.myshopifysite.com'; Then, on a later page - I added a page to check the cookie - ()  
P>

  & lt; Script & gt; Function getCookie (cname) {var name = cname + "="; Var decodedCookie = decodeurIComponent (document.cookie); Var ca = decodedCookie.split (';'); For (var i = 0; i & lt; ca.length; i ++) {var c = ca [i]; While (c.charAt (0) == '') {c = csubstring (1); } If (c.indexOf (name) == 0) {return c.substring (name.length, c.length); }} Return ""; } // warning ('cookie value:' + getcookie ('referral')); & Lt; / Script & gt; Note: It depends on the client who 'turns' cookies on their browser, though I have the most people. But doubt these days do so. 

Be careful with your domain names ("" vs "" can cause problems with cookies - except on other things on shopping, I have found.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -