What products were viewed but not purchased?
Everything that was viewed including all the items purchased can be found in the simpleProductViewsObj
. Likewise everything that was actually purchased can be seen in the simpleBasketObj
.
To find what was viewed but not purchased all we have to do is take the difference between these two data sets.
Now, given that the excilent lodash
library is a dependency of syrup
you have access to all of it's functions as well. And lodash
has a handy function for generating the difference
between two arrays.
To simplify the code we make use of the skus
arrays which contain a list of all unique skus / upcs in the objects.
- The
simpleBasketObj.skus
is all items in the basket - The
simpleProductViewsObj.skus
is all items that have been viewed regardless of if they were purchased.
The result is either an empty array []
or the SKUS
of the products viewed but not purchased.
let basket = r.questions().simpleBasketObj()
let views = r.questions().simpleProductViewsObj()
console.log(_.difference(views[0].skus, basket[0].skus))
var r = await syrup.fetchRespondentData({
projectID: '8fcbb2dc-8093-40d7-6c41-88ecccdcb2aa',
pageID: 'b8b70dca-a5b8-4a1a-4a8f-f60254fea95c',
respondentID: 'HNTEST12',
})
let basket = r.questions().simpleBasketObj()
let views = r.questions().simpleProductViewsObj()
console.log('simpleBasket: ', basket)
console.log('simpleViews: ', views)
console.log(_.difference(views[0].skus, basket[0].skus))