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.
Solved! Go to Solution.
Views
Replies
Total Likes
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....
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/cookiedomainperiod...
Usually plugin issues happen due to the above.
Hopefully this would sort out the issue.
Cheers,
Abhinav
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.
Views
Replies
Total Likes
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
Views
Replies
Total Likes
Hi abhinav ,
My domain looks like https://example.com and my subdomain is https://xyz.example.com.
Will cookie domain works in this case?
Views
Replies
Total Likes
Hey @AEPAA
Cookie domain period just ensures that your plugin is set in the right place. In your case, that would be the root domain example.com
Try searching for cookie domain in your analytics extension in the property which you mentioned is set up on the sub domain. Do you see any value in that field ?
Yes, I have checked the gpv cookies
It is only set twice in Root domain and in subdomain there is no such extra gpv cookies.
Views
Replies
Total Likes
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....
Thanks Abhinav and Jennifer.
Hi Jennifer ,
Is it possible to make changes in plugin code, will that work?
Views
Replies
Total Likes
Hi @AEPAA I did modify the plugin code a bit... by adding the reference to the function that ran the regex match...
In theory, we could try to do it all in-line like this:
/* Adobe Consulting Plugin: getPreviousValue v3.0 */
/* Modified to use match regex on host name */
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=window.location.hostname.match(/[^\.]*\.[^.]*$/)[0],a=window.location.hostname.match(/[^\.]*\.[^.]*$/)[0].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 ********************************************/
You can try that ^
Views
Replies
Total Likes
Views
Likes
Replies