Expand my Community achievements bar.

The Analytics Community Lens news letter for February 2024 is now here! Come see upcoming events and what's been going on in the community!
SOLVED

product variables persists in the checkout

Avatar

Level 2

question: I have an instance where once I submit the order and complete the purchase and then go back to buy another product in the same session. The previous product values persist in the order checkout. i.e in the s.products
I am clearing the variables after the checkout. Not sure what could be the bug. If I open a new session then that issue does not occur. It occurs if I am using the same browser window.
Below are the screenshots of my current checkout rule (edited) 

1f14faef-419a-4499-a727-1c7eb45704b0_720.png

19f3c6a8-cf3f-4d5a-bc86-6e1cf6483904_720.png

download_720.png

  

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

In your custom code, you're traversing through the ACDL to build your s.products string for the "scCheckout" event. Based on that and your problem statement, I suspect that your website is a Single Page Application (SPA) that does not have any so-called "physical" web pages.

If that is correct, then your ACDL basically keeps getting pushed with new events with every user interaction and "virtual" web page. It never gets reset to an empty array. So when you traverse your ACDL in your code, all of the old data still exist in ACDL, including the "scCheckout" one, which then causes your problem.

If that is correct, then you should use adobeDataLayer.getState() to get the computed data layer object, instead of traversing the adobeDataLayer array. Reference: https://github.com/adobe/adobe-client-data-layer/wiki#getstate

I suggest re-doing your Launch setup:

  1. Install the ACDL extension, if you haven't already.
  2. Move your custom code into its own data element, but only the "for" loop portion. Basically, that data element returns the s.products string that has been built from your "adobeDataLayer.getState().checkout.cartItems" array. Note the use of "adobeDataLayer.getState()" here, because you should use the computed data layer state to access your data layer, instead of traversing the adobeDataLayer array directly.
  3. Assuming you have a Checkout rule, trigger that rule with a ACDL "Data Pushed" event, specifying "scCheckout" as the Specific Event's Key. Include your AA Set Variables action in that rule, specifying s.products to have the value from your data element in step 2. You can also include the AA Send Beacon action if you have set all of the necessary AA variables in that same rule.

As you may have noticed, my suggestion involves a lot of re-work in your Launch setup, including replacing custom code like "s.t()" with a Send Beacon action from the AA extension. So this isn't a trivial suggestion to implement.

View solution in original post

3 Replies

Avatar

Community Advisor

Which values are persisting? Is it the Product identifier? Or some of the eVars... This could be a hard thing to sort out... we can only see a subset of the logic happening on your site.... 

 

Is it possible you have your eVar expiry set to maintain values for some period... clearing the value of a "visit" level eVar just means that you aren't explicitly sending a value... since no value is being sent that overrides the previous value, the eVar configuration will continue to populate the resulting data in your suite with that value until the visit is over.... 

 

This is how tracking a campaign generally functions... someone comes to my site with a ?cid=x (I put "x" into an eVar that will expire at the end of the Visit). If the user clicks on 4 more pages, there is no cid=x in the URL, but my eVar will track the value "x" on every page of that visit.

 

Your issue would benefit from a deep dive testing session; you may have to dig into all the actions and results to try and find where the problem is occuring.

 

Good Luck... issues like this are never easy to deal with.

Avatar

Correct answer by
Community Advisor

In your custom code, you're traversing through the ACDL to build your s.products string for the "scCheckout" event. Based on that and your problem statement, I suspect that your website is a Single Page Application (SPA) that does not have any so-called "physical" web pages.

If that is correct, then your ACDL basically keeps getting pushed with new events with every user interaction and "virtual" web page. It never gets reset to an empty array. So when you traverse your ACDL in your code, all of the old data still exist in ACDL, including the "scCheckout" one, which then causes your problem.

If that is correct, then you should use adobeDataLayer.getState() to get the computed data layer object, instead of traversing the adobeDataLayer array. Reference: https://github.com/adobe/adobe-client-data-layer/wiki#getstate

I suggest re-doing your Launch setup:

  1. Install the ACDL extension, if you haven't already.
  2. Move your custom code into its own data element, but only the "for" loop portion. Basically, that data element returns the s.products string that has been built from your "adobeDataLayer.getState().checkout.cartItems" array. Note the use of "adobeDataLayer.getState()" here, because you should use the computed data layer state to access your data layer, instead of traversing the adobeDataLayer array directly.
  3. Assuming you have a Checkout rule, trigger that rule with a ACDL "Data Pushed" event, specifying "scCheckout" as the Specific Event's Key. Include your AA Set Variables action in that rule, specifying s.products to have the value from your data element in step 2. You can also include the AA Send Beacon action if you have set all of the necessary AA variables in that same rule.

As you may have noticed, my suggestion involves a lot of re-work in your Launch setup, including replacing custom code like "s.t()" with a Send Beacon action from the AA extension. So this isn't a trivial suggestion to implement.

Avatar

Level 2

Based on your suggestion, I am going to redo the launch setup as it is currently traversing the entire DL and it is creating problems in debugging and reports.  Thanks a lot for the repository Link. Devs had implemented long time back and need to showcase that to them and pull those data in my rules using getState