Expand my Community achievements bar.

Join us January 15th for an AMA with Champion Achaia Walton, who will be talking about her article on Event-Based Reporting and Measuring Content Groups!
SOLVED

Web SDK | getPreviousValue

Avatar

Level 2

Hello Analytics Experts,
I hope everyone is have a great day.

 

I would like to seek your assistance regarding your best practice when using the getPreviousValue with Common Web SDK Plugins extension

 

Scenario:
I created a Data Element using the following sample setup (see screenshot below). However, when I tried calling _satellite.getVar("Previous Page Name"), the returning value are always current Page Name value, and not the "Previous Page Name" value.

Herder_0-1736412664983.png

 

Do you have any best practice on how we can get the actual previous value when using the getPreviousValue with Common Web SDK Plugins extension?

 

Thank you in advance.

 

 

Topics

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

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

Hi @Herder 

the getPreviousValue plugin returns the previous value exactly once. At the same time, the new value is persisted and from there on is returned as previous value.

 

The fix should be to make sure to only call this plugin once i.e., only request the data element in the page view rule and don't set it in any custom link tracking.

 

Cheers from Switzerland!


View solution in original post

2 Replies

Avatar

Correct answer by
Community Advisor

Hi @Herder 

the getPreviousValue plugin returns the previous value exactly once. At the same time, the new value is persisted and from there on is returned as previous value.

 

The fix should be to make sure to only call this plugin once i.e., only request the data element in the page view rule and don't set it in any custom link tracking.

 

Cheers from Switzerland!


Avatar

Level 4

To add on to what @bjoern__koth has shared, when you call this data element, it returns the value stored in the plugin cookie, it then resets the cookie expiration and assigns it the latest value from the variableToCheck argument your define in the data element.

This means, when you call this data element first time on the new page (either through a page load or a link track call), it returns the name of previous page (assuming variableToCheck argument is set to page name), resets the cookie expiration and then stores the current value of page name (which is current page name) in the cookie. Now if you call this data element again on the same page, the value that gets returned from the cookie is this page's name only.

So, as @bjoern__koth , call this data element only once per page load and that should give you the correct data. If you need to read this value multiple times on a page then add some custom logic to store the information either in a global JS variable or in session or local storage until next page load and read the value as and when needed.

Cheers!