I’m in the process of upgrading to the new API from the old version, which we’ve been using for years.
After each “Viewed Product” event, we’d been calling trackViewedItem, with the product information structured slightly differently, so that it would register in the user’s recently viewed items list.
With the new API, calls to trackViewedItem are throwing an error. I’m using syntax similar to the example on https://developers.klaviyo.com/en/docs/guide_to_integrating_a_platform_without_a_pre_built_klaviyo_integration#viewed-product-tracking-snippet
I’ve isolated the failing call from my app and am invoking it directly in the browser console. Here’s an example:
var item = {
Title: "SampleItem",
ItemId: 47,
Categories: 4 "Things" ],
ImageUrl: "https://XXXXXXXXXXXXX.net/img/foo.gif",
Url: "https://XXXXXXXXXXXXX.net/sample",
Metadata: { Brand: "ACME", Price: 99.99 }
}
klaviyo.trackViewedItem(item);
The error:
fender_analytics.992c5dd9d8732b969bc5.js?cb=1:1 Uncaught (in promise) TypeError: Cannot read properties of null (reading 'LastViewedDate')
at fender_analytics.992c5dd9d8732b969bc5.js?cb=1:1:22628
at Array.reduce (<anonymous>)
at Y.trackViewedItem (fender_analytics.992c5dd9d8732b969bc5.js?cb=1:1:22608)
at Array.r 9as push] (fender_analytics.992c5dd9d8732b969bc5.js?cb=1:1:30334)
at Object.trackViewedItem (sharedUtils.32fecf14b565ff0981cb.js?cb=1:1:1208)
at Array.o 5as push] (sharedUtils.32fecf14b565ff0981cb.js?cb=1:1:2357)
at sharedUtils.32fecf14b565ff0981cb.js?cb=1:1:2072
at new Promise (<anonymous>)
at Proxy.<anonymous> (sharedUtils.32fecf14b565ff0981cb.js?cb=1:1:2038)
at <anonymous>:1:9
k.push(“trackViewedItem”, item]) gives exactly the same error.
In the Klaviyo console, on the profile of the user I’m testing with, I see the “Viewed Product” events just fine, but the “Recently viewed products” section is empty. We were successfully using this feature before, with the old API, as I can see by browsing accounts recently active on the production server.