# init

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.

```javascript
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
  });
});

```

```javascript
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
});

```

## Properties

### Init

### context

value: `Context`


### customerPrivacy

value: `CustomerPrivacyData`


### data

value: `RegisterInitData`


### CustomerPrivacyData

### analyticsProcessingAllowed

value: `boolean`

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.

### marketingAllowed

value: `boolean`

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.

### preferencesProcessingAllowed

value: `boolean`

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.

### saleOfDataAllowed

value: `boolean`

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.

### RegisterInitData

### cart

value: `Cart | null`

A cart represents the merchandise that a customer intends to purchase, and the estimated cost associated with the cart.

### customer

value: `Customer | null`

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.

### purchasingCompany

value: `PurchasingCompany | null`

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.

### shop

value: `Shop`

The shop represents information about the store, such as the store name and currency.

### Cart

A cart represents the merchandise that a customer intends to purchase, and the estimated cost associated with the cart.

### attributes

value: `Attribute[]`

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).

### cost

value: `CartCost`

The estimated costs that the customer will pay at checkout.

### id

value: `string | null`

A globally unique identifier.

### lines

value: `CartLine[]`

A list of lines containing information about the items the customer intends to purchase.

### totalQuantity

value: `number`

The total number of items in the cart.

### Attribute

Custom attributes associated with the cart or checkout.

### key

value: `string`

The key for the attribute.

### value

value: `string`

The value for the attribute.

### CartCost

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).

### totalAmount

value: `MoneyV2`

The total amount for the customer to pay.

### MoneyV2

A monetary value with currency.

### amount

value: `number`

The decimal money amount.

### currencyCode

value: `string`

The three-letter code that represents the currency, for example, USD. Supported codes include standard ISO 4217 codes, legacy codes, and non- standard codes.

### CartLine

Information about the merchandise in the cart.

### cost

value: `CartLineCost`

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.

### merchandise

value: `ProductVariant`

The merchandise that the buyer intends to purchase.

### quantity

value: `number`

The quantity of the merchandise that the customer intends to purchase.

### CartLineCost

The cost of the merchandise line that the customer will pay at checkout.

### totalAmount

value: `MoneyV2`

The total cost of the merchandise line.

### ProductVariant

A product variant represents a different version of a product, such as differing sizes or differing colors.

### id

value: `string | null`

A globally unique identifier.

### image

value: `Image | null`

Image associated with the product variant. This field falls back to the product image if no image is available.

### price

value: `MoneyV2`

The product variant’s price.

### product

value: `Product`

The product object that the product variant belongs to.

### sku

value: `string | null`

The SKU (stock keeping unit) associated with the variant.

### title

value: `string | null`

The product variant’s title.

### untranslatedTitle

value: `string | null`

The product variant’s untranslated title.

### Image

An image resource.

### src

value: `string | null`

The location of the image as a URL.

### Product

A product is an individual item for sale in a Shopify store.

### id

value: `string | null`

The ID of the product.

### title

value: `string`

The product’s title.

### type

value: `string | null`

The [product type](https://help.shopify.com/en/manual/products/details/product-type) specified by the merchant.

### untranslatedTitle

value: `string | null`

The product’s untranslated title.

### url

value: `string | null`

The relative URL of the product.

### vendor

value: `string`

The product’s vendor name.

### Customer

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.

### email

value: `string | null`

The customer’s email address.

### firstName

value: `string | null`

The customer’s first name.

### id

value: `string`

The ID of the customer.

### lastName

value: `string | null`

The customer’s last name.

### ordersCount

value: `number | null`

The total number of orders that the customer has placed.

### phone

value: `string | null`

The customer’s phone number.

### PurchasingCompany

Provides details of the company and the company location that the business customer is purchasing on behalf of.

### company

value: `PurchasingCompanyCompany`

Includes information of the company that the business customer is purchasing on behalf of.

### location

value: `PurchasingCompanyLocation`

Includes information of the company location that the business customer is purchasing on behalf of.

### PurchasingCompanyCompany

Includes information of the company that the business customer is purchasing on behalf of.

### externalId

value: `string | null`

The external ID of the company that can be set by the merchant.

### id

value: `string`

The company ID.

### name

value: `string`

The name of the company.

### PurchasingCompanyLocation

Includes information of the company location that the business customer is purchasing on behalf of.

### externalId

value: `string | null`

The external ID of the company location that can be set by the merchant.

### id

value: `string`

The company location ID.

### name

value: `string`

The name of the company location.

### Shop

The shop represents information about the store, such as the store name and currency.

### countryCode

value: `string`

The shop’s country code.

### myshopifyDomain

value: `string`

The shop’s myshopify.com domain.

### name

value: `string`

The shop’s name.

### paymentSettings

value: `ShopPaymentSettings`

Settings related to payments.

### storefrontUrl

value: `string | null`

The shop’s primary storefront URL.

### ShopPaymentSettings

Settings related to payments.

### currencyCode

value: `string`

The three-letter code for the shop’s primary currency.