Scenario
The category section needs to support pagination and show 3 products per page. If possible, the first product on each page will be a sponsored product. The products on this category page have the following structure:resolvedBidId
is null
when the product is not promoted and contain a string ID when it is.
Our goal is to have the pseudo code in place for an endpoint that could create lists of such products.
1. Query your organic results
The first step will be to query your organic results. The products that should be displayed for a specific page and category. The code to do this could look like this:Shoes
category, and there’s 3 or more products available in this category. This code would then output something similar to this:
resolvedBidId
field yet, let’s add it.
2. Running an auction
In our scenario we want to run an auction for a single slot:Not sure how run an auction for a category?
Check out these examples.
products
.
3. Query product data for winners
Now, when there are winners. We need to query the product data for them.resolvedBidId
to complete this data. But, this time we shouldn’t set it to null
, because we’re now dealing with promoted products.
If we assume queryProductsByIds
will return products in the same order as the provided ids
, we can add the bid IDs as follows:
Why is this bid ID necessary?
The bid ID is vital to enable Topsort to attribute events to bids and campaigns.
4. Merging
We want to show the promoted products at the start of the list. To achieve, we will need to prepend thepromoProducts
to the products
.
However, this can then make products
have more elements than our intended page size of 3. So we need to slice it to remain in this page size.