Expand my Community achievements bar.

getprevious value plugin

Avatar

Level 3

Hi Team,

 

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

bindukumari90_0-1720606300758.png

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

Topics

Topics help categorize Community content and increase your ability to discover relevant content.

5 Replies

Avatar

Community Advisor

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.

Avatar

Level 3

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?

Avatar

Community Advisor

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;
}

 

Avatar

Community Advisor and Adobe Champion

I am not sure if the plugin is returning literal undefined, or if they just meant the standard "unspecified"...

 

This solution won't solve for standard "unspecified" because not setting prop7 is the same as sending s.prop7 = "";

 

But if the lack of cookie is sending s.prop7 = "undefined" (then this will definitely help)

 

Avatar

Community Advisor and Adobe Champion

The first page of the visit has no "previous page". Having unspecified on the first page of your visit is the correct behaviour of the plugin...

 

 

Either the user opened their browser (and your site was set as the home page in their browser), so this is literally the first page the browser has opened, or (more likely) the technical previous page was not on your site (and therefore you don't have a value for it).

 

 

Remember, this is "Previous Page", not the current page.

 

Visit

  • Page 1 - Home
    • pageName = "home"
    • s.prop7 = "" (previous page - there is no previous page)
  • Page 2 - Section Page
    • pageName = "section"
    • s.prop7 = "home" (previous page was Page 1)
  • Page 3 - Detail Page
    • pageName = "detail"
    • s.prop7 = "section" (previous page was Page 2)

 

I hope this helps.