Skip to main content

Integrating your cart with Rokt

Subscribe to Rokt placement cart changes#

The in-transaction/cart integration notifies your frontend whenever a customer selects a Rokt upsell opportunity, allowing for the change to be reflected in a customer's cart. This is achieved by listening to the V2_CART_ITEM_UPDATED message of a placement, which is triggered every time a customer makes changes to selected items on the Rokt side.

You can subscribe to that message by using the Selection.on method which allows you to listen for messages from any selected placement. The payload of those messages is described in UpdateCartItemPlacementMessageBody.

Additionally, you can provide extra information by passing attributes to better tailor an offers' selection to a customer. In some cases, depending on your catalog provider, additional information may be required for Rokt to retrieve catalog items.

// (...) loading Rokt script and creating Integration Launcher instance
const selection = await launcher.selectPlacements({  attributes: {    // attributes required by Rokt to retrieve the catalog items    eventId: "eventId",    venueName: "venueName",    // any additional attributes    email: "email",  },});
selection.on("V2_CART_ITEM_UPDATED").subscribe((event) => {  // Below you should provide your code to reflect changes to your cart  clientCart.updateCart(event.body.cartItem, event.body.oldCartItem);});

Update Rokt placement cart from your cart#

In the scenario where your cart changes need to be reflected on the Rokt side, you can send messages to the Placement to do so. For your convenience, you can send a message to each placement in selection by using the Selection.send method. The affected Rokt placement will listen and action accordingly. The payload of this message is described in UpdateCartItemPartnerMessageBody.

Note Please be advised that certain changes will not be performed if the configuration does not allow it. For instance, if a forced upsell has a minimum quantity of 1, and the placement receives a message from the partner to remove that selection, the placement will not action it.

Be sure though, there is always a message sent back to the partner from the placement, to close the loop and share the Rokt placement cart state to the partner, to ensure both carts are aligned (please see section above).

const selection = await launcher.selectPlacements({  attributes: {    // attributes required by Rokt to retrieve the catalog items  },});
selection.send("V2_UPDATE_CART_ITEM", payload);

Checking placement availability#

This extension involves your backend issuing a call to Rokt to check if any placements are available. You can then decide if your upsell page should be displayed or skipped. In this scenario, your pages have most likely already been generated on the backend, and you have already included customer and transaction data to Rokt in the initial call. Since that call may have already generated your session ID, the Rokt JavaScript API requires you to include your session ID in the Rokt.createLauncher method so both interactions can be paired together for identification and performance reasons.

// (...) loading Rokt script
const launcher = await Rokt.createLauncher({  accountId: "roktAccountId",  sessionId: "uniqueSessionId", // session ID generated by Rokt backend});
// (...) the rest of the integration logic
Was this article helpful?