A JSON object containing a snapshot of the page at time of page render. It will always have the present `Context` of the page, as well as the `Data` field, which provides access to the `Cart` and `Customer` objects.
import {register} from '@shopify/web-pixels-extension';
register(({analytics, init}) => {
analytics.subscribe('page_viewed', (event) => {
// On every page view, get the current state of the cart
const customer = init.data.customer;
const cart = init.data.cart;
const shop = init.data.shop;
const purchasingCompany = init.data.purchasingCompany;
console.log(`Customer Name: ${customer.firstName}`);
// Customer Name: Bogus
console.log(`Total Number of Items in Cart: ${cart.totalQuantity}`);
// Total Number of Items in Cart: 3
console.log(`Total Cost of Cart: ${cart.cost.totalAmount.amount}`);
// Total Cost of Cart: 50.82
console.log(`Shop name: ${shop.name}`);
// Shop name: Shop 123
console.log(`Shop currency code: ${shop.paymentSettings.currencyCode}`);
// Shop currency code: CAD
console.log(`Purchasing company name: ${purchasingCompany.company.name}`);
// Purchasing company name: Acme Corporation
console.log(
`Purchasing company location name: ${purchasingCompany.location.name}`,
);
// Purchasing company location name: Toronto fulfillment center
});
});
analytics.subscribe('page_viewed', (event) => {
// On every page view, get the current state of the cart
const customer = init.data.customer;
const cart = init.data.cart;
const shop = init.data.shop;
const purchasingCompany = init.data.purchasingCompany;
console.log(`Customer Name: ${customer.firstName}`);
// Customer Name: Bogus
console.log(`Total Number of Items in Cart: ${cart.totalQuantity}`);
// Total Number of Items in Cart: 3
console.log(`Total Cost of Cart: ${cart.cost.totalAmount.amount}`);
// Total Cost of Cart: 50.82
console.log(`Shop name: ${shop.name}`);
// Shop name: Shop 123
console.log(`Shop currency code: ${shop.paymentSettings.currencyCode}`);
// Shop currency code: CAD
console.log(`Purchasing company name: ${purchasingCompany.company.name}`);
// Purchasing company name: Acme Corporation
console.log(
`Purchasing company location name: ${purchasingCompany.location.name}`,
);
// Purchasing company location name: Toronto fulfillment center
});
This flag indicates whether the customer has allowed the processing of their data for analytics purposes on the initial page load. If a customer submits consent, you can use the [customer privacy API](/api/web-pixels-api/pixel-privacy#customer-privacy-api) to track whether or not the privacy permissions have changed.
This flag indicates whether the customer has allowed the processing of their data for marketing purposes on the initial page load. If a customer submits consent, you can use the [customer privacy API](/api/web-pixels-api/pixel-privacy#customer-privacy-api) to track whether or not the privacy permissions have changed.
This flag indicates whether the customer has allowed the processing of their data for preferences purposes on the initial page load. If a customer submits consent, you can use the [customer privacy API](/api/web-pixels-api/pixel-privacy#customer-privacy-api) to track whether or not the privacy permissions have changed.
This flag indicates whether the customer has allowed the sale of their data on the initial page load. If a customer submits consent, you can use the [customer privacy API](/api/web-pixels-api/pixel-privacy#customer-privacy-api) to track whether or not the privacy permissions have changed.
A cart represents the merchandise that a customer intends to purchase, and the estimated cost associated with the cart.
A customer represents a customer account with the shop. Customer accounts store contact information for the customer, saving logged-in customers the trouble of having to provide it at every checkout.
Provides details of the company and the company location that the business customer is purchasing on behalf of. This includes information that can be used to identify the company and the company location that the business customer belongs to.
The shop represents information about the store, such as the store name and currency.
A cart represents the merchandise that a customer intends to purchase, and the estimated cost associated with the cart.
The attributes associated with the cart. This property is only available if the shop has [upgraded to Checkout Extensibility](https://help.shopify.com/en/manual/checkout-settings/checkout-extensibility/checkout-upgrade).
The estimated costs that the customer will pay at checkout.
A globally unique identifier.
A list of lines containing information about the items the customer intends to purchase.
The total number of items in the cart.
Custom attributes associated with the cart or checkout.
The key for the attribute.
The value for the attribute.
The costs that the customer will pay at checkout. It uses [`CartBuyerIdentity`](https://shopify.dev/api/storefront/reference/cart/cartbuyeridentity) to determine [international pricing](https://shopify.dev/custom-storefronts/internationalization/international-pricing#create-a-cart).
The total amount for the customer to pay.
A monetary value with currency.
The decimal money amount.
The three-letter code that represents the currency, for example, USD. Supported codes include standard ISO 4217 codes, legacy codes, and non- standard codes.
Information about the merchandise in the cart.
The cost of the merchandise that the customer will pay for at checkout. The costs are subject to change and changes will be reflected at checkout.
The merchandise that the buyer intends to purchase.
The quantity of the merchandise that the customer intends to purchase.
The cost of the merchandise line that the customer will pay at checkout.
The total cost of the merchandise line.
A product variant represents a different version of a product, such as differing sizes or differing colors.
A globally unique identifier.
Image associated with the product variant. This field falls back to the product image if no image is available.
The product variant’s price.
The product object that the product variant belongs to.
The SKU (stock keeping unit) associated with the variant.
The product variant’s title.
The product variant’s untranslated title.
An image resource.
The location of the image as a URL.
A product is an individual item for sale in a Shopify store.
The ID of the product.
The product’s title.
The [product type](https://help.shopify.com/en/manual/products/details/product-type) specified by the merchant.
The product’s untranslated title.
The relative URL of the product.
The product’s vendor name.
A customer represents a customer account with the shop. Customer accounts store contact information for the customer, saving logged-in customers the trouble of having to provide it at every checkout.
The customer’s email address.
The customer’s first name.
The ID of the customer.
The customer’s last name.
The total number of orders that the customer has placed.
The customer’s phone number.
Provides details of the company and the company location that the business customer is purchasing on behalf of.
Includes information of the company that the business customer is purchasing on behalf of.
Includes information of the company location that the business customer is purchasing on behalf of.
Includes information of the company that the business customer is purchasing on behalf of.
The external ID of the company that can be set by the merchant.
The company ID.
The name of the company.
Includes information of the company location that the business customer is purchasing on behalf of.
The external ID of the company location that can be set by the merchant.
The company location ID.
The name of the company location.
The shop represents information about the store, such as the store name and currency.
The shop’s country code.
The shop’s myshopify.com domain.
The shop’s name.
Settings related to payments.
The shop’s primary storefront URL.
Settings related to payments.
The three-letter code for the shop’s primary currency.