DPC handles performance tracking to enable the Depict AI to optimize recommendations and product listings.
yarn
or npm
usePerformanceClient
hook in @depict-ai/react-ui
.
If you are using yarn
or npm
you must initialize it yourself:
DPC
it takes two arguments. The first is your Merchant ID. The second argument is an optional object with extra configuration. If the market is known at this point, it should be specified. If you initialize DPC before you know which market is active, use dpq.
Config values
All config values are optional.
data-recommendation-id
attribute in the DOM. The recommendation_id is unique for each recommendation and is all that is needed to track Impression
and Click
events. If you are rendering product cards through one of Depict’s UI packages, this is already handled for you.
If you have an add-to-cart button in your product card, add the depict-add-to-cart
class to your button and DPC will automatically track it as well.
Example Product Card HTML
This is a simple example where the two things relevant to DPC is the data-recommendation-id
attribute and the depict-add-to-cart
class on the add to cart button.
window.dpq
after initializing DPC. This way you can send events from anywhere in your code, even without a reference to the DPC instance. If you do have a DPC instance, it can also be used to send events directly.
window.dpq
is a function that takes two arguments. The first argument is always a string specifying the name of the event to send to DPC. The second argument contains the data, this can be a string or an object depending on the event.
window.dpq
availabilitywindow.dpq
is set when first initializing DPC with new DPC(...)
. It will then be globally available on the window
object. It can be accessed by simply calling dpq(...)
(without specifying window
) from anywhere in your code that executes on the browser after the new DPC(...)
call.window.dpq
is available when calling it from a different context such as Google Tag Manager, it can be initialized using:((e,n)=>{e.dpq||((n=e.dpq=function(){n.send_event?n.send_event.apply(n,arguments):n.queue.push(arguments)}).queue=[])})(window);
Event name | Description | Event Data |
---|---|---|
setProductId | Sets the product id after navigating to a PDP. | string - a product id |
addToCart | Sends an add to cart event to Depict. | string - the product id that was added |
purchase | Sends a purchase event to Depict. | object - a purchase object |
setMarket | Sets the currently active market used in all tracking events. | string - a market |
setSessionId | Sets the session_id for a user to get personalized recommendations. | string - an id you use to identify a logged in user or a session |
setProductId
event to register which product id is currently viewed.
setProductId
and addToCart
events must be the same type of id that is
returned in the displays by our API as product_id
. For an example of valid
product IDs, see the bottom table on the “Tracking status” tab on
app.depict.ai.addToCart
events, or automatically by marking add-to-cart buttons in the DOM with the depict-add-to-cart
class.
Sending add-to-cart events imperatively
Whenever a product was successfully added to the cart anywhere on your website (including surfaces not directly related to Depict), send an addToCart
event with the corresponding product id. If you implement imperative tracking, skip the automatic tracking section below.
depict-add-to-cart
class to all add-to-cart buttons on your website, including product cards and product detail pages. Depict will automatically track clicks as necessary, and attribute them to the corresponding products for add-to-cart buttons inside product cards.
transaction_id
should be whatever you use to identify the purchase in your system. The item_id
in the items
array should be the SKU of the product. The price
should be the final price of the product, after any taxes, discounts, etc have been applied.
localStorage.debug = true
in your browser console and reload the page.