getprevious value plugin | Community
Skip to main content
July 10, 2024
Question

getprevious value plugin

  • July 10, 2024
  • 1 reply
  • 1327 views

Hi Team,

 

Rightnow, I am migrating into websdk, so using getprevious value plugin to get the previous page name.

So, it is working fine, but some time it shows the value undefined for the first page. Please help me to understand the reson.

 

Thanks!!

Bindu Kumari

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

1 reply

pradnya_balvir
Community Advisor
Community Advisor
July 10, 2024

Hi @bindukumari90 ,

For example, assume the following code runs on the first page of the visit:

 

s.pageName = "Home";
s.prop7 = getPreviousValue(s.pageName,"gpv_Page");
s.t();

 

This code produces a server call where pageName is “Home” and prop7 is not set. However, the call to getPreviousValue stores the value of pageName in the gpv_Page cookie. Assume that immediately afterwards, on the same page, the following code runs:

 

s.pageName = "New value";
s.prop7 = getPreviousValue(s.pageName,"gpv_Page");

 

Since the t() function does not run in this code block, another image request is not sent. However, when the getPreviousValue function code runs this time, prop7 is set to the previous value of pageName (“Home”), then stores the new value of pageName (“New value”) in the gpv_Page cookie. Next, assume the visitor navigates to a different page and the following code runs on this page:

 

s.pageName = "Page 2";
s.prop7 = getPreviousValue(s.pageName,"gpv_Page");
s.t();

When the t() function runs, it creates an image request where pageName is “Page 2” and prop7 is “New value”, which was the value of pageName when the last call to getPreviousValue took place. The prop7 value of "Home" was never contained in an image request, even though “Home” was the first value passed to pageName.

July 10, 2024

Hi,

 

So, this means in the 1st visit of the page the previous value should be home page, not undefined right.

 

And, if it is coming then how we can resolve the issue?

Ankit_Chaudhary
Community Advisor
Community Advisor
July 10, 2024

Hi @bindukumari90 

The previous value plugin get it's value from a cookie whose name you have to set while setting up the plugin.

for ex: getPreviousValue(s.pageName,"gpv_Page"); here the value from s.pageName variable set into gpv_page cookie which you can retrieve in the next call.

So if you are setting the cookie value from s.pageName then you won't get it on the first page load because the value is yet to be set.

If the cookie value is not available you will get undefined in return Ideally the plug code is designed to handle this situation but if it's not working then you can place an additional condition to handle if gpv_page cookie is unedified.

Example:

var previousPageName = getPreviousValue(s.pageName, "gpv_Page"); if (previousPageName) { s.prop7 = previousPageName; }