Skip to main content

cart_viewed

The cart_viewed event logs an instance where a customer visited the cart page.

Anchor to clientId
clientId
string

The client-side ID of the customer, provided by Shopify

Anchor to context
context

A snapshot of various read-only properties of the browser at the time of event

string

The ID of the customer event

string

The name of the customer event

number

The sequence index number of the event.

Anchor to timestamp
timestamp
string

The timestamp of when the customer event occurred, in ISO 8601 format

.Standard
Examples
import {register} from '@shopify/web-pixels-extension';

register(({analytics}) => {
analytics.subscribe('cart_viewed', (event) => {
// Example for accessing event data
const totalCartCost = event.data.cart.cost.totalAmount.amount;

const firstCartLineItemName =
event.data.cart.lines[0]?.merchandise.product.title;

const payload = {
event_name: event.name,
event_data: {
cartCost: totalCartCost,
firstCartItemName: firstCartLineItemName,
},
};

// Example for sending event data to third party servers
fetch('https://example.com/pixel', {
method: 'POST',
body: JSON.stringify(payload),
keepalive: true,
});
});
});

Was this page helpful?