we are using the shopify pixel to track the frontend events
we want to send the shopify generated cart id whenever customer adds something to the cart
we are using the below code, but sometimes the cart id is not present
register(async ({ analytics, browser, init, settings }) => {
analytics.subscribe("all_events", async (event: any) => {
if (event.name === "product_added_to_cart") {
if (!cartId) {
cartId = await thirdPartyCheckoutHelper.fetchCartToken();
cartId = cartId.split("?")[0];
// send this cartId along with event.data
});
});
async fetchCartToken() {
return await this.browser.cookie.get("cart");
}
is this the best way to do it ? why is it sometimes not present ? we are not able to reproduce the issue