s.getPreviousvalue cookie | Community
Skip to main content
December 29, 2023
Solved

s.getPreviousvalue cookie

  • December 29, 2023
  • 1 reply
  • 2264 views

Hi everyone,

We have two website a main website and a website on subdomain . As, both are somewhere related like the the subdomain is for portal login and main website is public.

We have seperate properties for the main and subdomain.So, here whenever I navigate to subdomain and comeback to main website.

s.getPreviousvalue cookie i get two seperate gpv cookies. Which is creating problems where the sub domain gpv cookie is bypassing the public pages which  is giving me a previous page value prop incorrectly. Not sure why two gpv cookies are set when I go to subdomain. Same code is written 

for s.getPreviousvalue for both properties.

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jennifer_Dungan

@aepaa 

Ohkk that's real weird.

Let me try and replicate similar setup tomorrow and check.

 

Hey@jennifer_dungan Any thoughts on what else might be going on here ?


Ah, yep.. having cookies set to the main domain and to the subdomain is going to cause some issues... 

 

Both sites are using the same Launch property?

 

However, both 
https://example.com 
and 

https://xyz.example.com 
should use 2 domain periods in the settings, which should set cookies to ".example.com"....

 

 

 

But I am not sure about if the plugin uses those settings (it should... but its hard to say)

 

I dug into the code of the plugin a bit, and I think the problem is this piece:

h=window.location.hostname

 

h is the host that the cookie is written to, and "window.location.hostname" returns the full hostname, not the "main domain"....

 

Most of these plugins were written a long time ago, mostly for simpler times without the use of a lot of subdomains....

 

I think to make this work, you might need to make some minor changes to the code... here is a suggestion, but please test this thoroughly before using:

 

/* Adobe Consulting Plugin: getPreviousValue v3.0 */ function getPreviousValue(v,c){var k=v,d=c;if("-v"===k)return{plugin:"getPreviousValue",version:"3.0"};var a=function(){if("undefined"!==typeof window.s_c_il)for(var c=0,b;c<window.s_c_il.length;c++)if(b=window.s_c_il[c],b._c&&"s_c"===b._c)return b}();"undefined"!==typeof a&&(a.contextData.getPreviousValue="3.0");window.cookieWrite=window.cookieWrite||function(c,b,f){if("string"===typeof c){var h=getMainDomain(window.location.hostname),a=getMainDomain(window.location.hostname).split(".").length-1;if(h&&!/^[0-9.]+$/.test(h)){a=2<a?a:2;var e=h.lastIndexOf(".");if(0<=e){for(;0<=e&&1<a;)e=h.lastIndexOf(".",e-1),a--;e=0<e?h.substring(e):h}}g=e;b="undefined"!==typeof b?""+b:"";if(f||""===b)if(""===b&&(f=-60),"number"===typeof f){var d=new Date;d.setTime(d.getTime()+6E4*f)}else d=f;return c&&(document.cookie=encodeURIComponent(c)+"="+encodeURIComponent(b)+"; path=/;"+(f?" expires="+d.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!==typeof cookieRead)?cookieRead(c)===b:!1}};window.cookieRead=window.cookieRead||function(c){if("string"===typeof c)c=encodeURIComponent(c);else return"";var b=" "+document.cookie,a=b.indexOf(" "+c+"="),d=0>a?a:b.indexOf(";",a);return(c=0>a?"":decodeURIComponent(b.substring(a+2+c.length,0>d?b.length:d)))?c:""};var l;d=d||"s_gpv";a=new Date;a.setTime(a.getTime()+18E5);window.cookieRead(d)&&(l=window.cookieRead(d));k?window.cookieWrite(d,k,a):window.cookieWrite(d,l,a);return l}; /******************************************** END CODE TO DEPLOY ********************************************/ function getMainDomain(host){ mainDomain = host.match(/[^\.]*\.[^.]*$/)[0]; return mainDomain; }

 

Basically I modified the "h" and "a" values in the plugin:

 

var h=getMainDomain(window.location.hostname),a=getMainDomain(window.location.hostname).split(".").length-1;

 

And added a function to process the host values to return the main part of the domain.....

 

 

I can test my function, but I can't test the whole plugin.... 

1 reply

abhinavbalooni
Community Advisor
Community Advisor
December 29, 2023

Hey @aepaa 

 

Seems to be an issue of cookiedomainperiods. One cookie might be getting set on the subdomain and the other one in the root.

 

Try checking the configuration by referring to this documentation: https://experienceleague.adobe.com/docs/analytics/implementation/vars/config-vars/cookiedomainperiods.html?lang=en

 

Usually plugin issues happen due to the above.

 

Hopefully this would sort out the issue.

 

Cheers,

Abhinav

AEPAAAuthor
December 30, 2023

But , I have two seperate tag property for both having same code in Analytics extension.. Where should I be probably add the cookie domain period.

Also, in the document they have  mentioned important  note that don't set the variables  for sub domain.

abhinavbalooni
Community Advisor
Community Advisor
December 30, 2023

Hey @aepaa 

what does you domain look like ? www.example.com ? or something like www.example.co.uk ? In the second case your cookie domain period would need to be set to 3.

 

Though the default value is 2, so it doesn't need to be set explicitly but if your setup is playing up, you can try setting it in analytics extension under cookies accordian.

 

Can you though confirm you are indeed seeing two cookies on root and subdomain ?

 

Cheers,

Abhinav