My favorites | English | Sign in

Google Checkout

Annotating Pages with Product Data

Note: This is the latest documentation. The previous version of this page is also available.

To use the Google Checkout shopping cart, you need to annotate your web page's HTML tags with CSS class names that identify information about your products to the JavaScript. For example, in the simple example below, the product class encapsulates HTML for a particular product. In turn, the product-image, product-title and product-price classes identify the portion of the HTML that contains the product's image, title and price, respectively.

<div class="product">
  <img class="product-image" src="http://www.example.com/image1.jpg"/><br/>
  <span class="product-title">Blue T-shirt</span><br/>
  <span class="product-price">$12.99</span><br/>
</div>

This page contains the following information:

Product Annotation Examples

The following examples illustrate several product annotation examples. Each example shows an image of a page that displays a T-shirt that can be added to a shopping cart. The HTML snippet below each image includes shows the class names that identify the product information that appears on the web page and in the shopping cart widget. Please note that the HTML examples do not include elements that only affect page layout, such as <table>, <td> or <br> tags.

Example 1: Specifying basic product information

This example shows a simple annotation with a product image, product title, product price, shipping cost and add-to-cart button.

This example uses the following HTML:

<div class="product">
  <img class="product-image" src="files/google_tshirt.jpg"/>
  <span class="product-title">Google T-shirt</span>
  Price: <span class="product-price">$12.99</span>
  Shipping: <span class="product-shipping">$4.99</span>
  <div  role="button" alt="Add to cart" tabindex="0" class="googlecart-add-button">
  </div>
</div>

Example 2: Adding custom attribute information

The Google Checkout shopping cart allows you to define as many custom attributes as you want for a product. For example, you could use custom attributes to specify the color of a T-shirt or a topping for a pizza.

To define a custom attribute, identify the attribute value using a CSS class named product-attr-XXX where XXX is the name of the attribute. Attribute names should be short – either one or two words – and may not contain spaces. If the attribute name is multiple words, use hyphens to separate the words – e.g. product-attr-release-date. For example, the following HTML snippet indicates to the shopping cart that the corresponding item is blue:

<span class="product-attr-color">Blue</span>

The example below adds two custom attributes to the annotation shown in example 1. In the shopping cart widget, the color and size values both appear below the product title. As shown in the image below, the custom attribute values are separated by commas ("blue, XL").

This example uses the following HTML:

<div class="product">
  <img class="product-image"
    src="files/google_tshirt.jpg"/>
  <span class="product-title">Google T-shirt</span>
  Price: <span class="product-price">$12.99</span>
  Shipping: <span class="product-shipping">$4.99</span>
  Size: <span class="product-attr-size">XL</span>
  Color: <span class="product-attr-color">blue</span>
  <div  role="button" alt="Add to cart" tabindex="0" class="googlecart-add-button">
  </div>
</div>

Example 3: Letting users customize a product before adding it to the shopping cart

You can enable your customer to specify certain product attributes before adding the product to the shopping cart. For example, if you sell clothing, you might want to let the customer choose the appropriate size of each item before adding it to the cart.

This example shows how to use custom attributes to let the user select the size and color of a T-shirt.

This example uses the following HTML:

<div class="product">
  <img class="product-image"
    src="files/google_tshirt.jpg"/>
  <span class="product-title">Google T-shirt</span>
  Price: <span class="product-price">$12.99</span><br/>
  Shipping: <span class="product-shipping">$4.99</span>

  <!-- The shopping cart automatically adds the selected color -->
  Color: <br/>
    <input class="product-attr-color" name="color" type="radio" value="blue"/> blue<br/>
    <input class="product-attr-color" name="color" type="radio" value="green"/> green<br/>
    <input class="product-attr-color" name="color" type="radio" value="red"/> red<br/>

  <!-- The shopping cart automatically adds the selected size -->
  Size: <select class="product-attr-size">
          <option>Small</option>
          <option>Medium</option>
          <option>Large</option>
          <option>X-Large</option>
        </select> 
  <div role="button" alt="Add to cart" tabindex="0" class="googlecart-add-button">
  </div> 
</div>

Example 4: Updating page content based on selected product attributes

This example shows how to define special rules that are applied when the user selects particular product attributes. This example adds a rule to the previous example that states that if the customer selects to buy an XL-sized T-shirt, the price for the shirt will be $14.99 instead of $12.99. To implement this rule, each option in the product-attr-size select menu uses the googlecart-set-product-price attribute to specify the price of that shirt size.

To use this functionality, add an attribute of the form googlecart-set-XXX="replacement value" to the element that triggers the change. In the attribute name, replace XXX with the name of the CSS class associated with the value is being updated. If that attribute is selected, the shopping cart JavaScript will use the replacement value that you have specified as the value of the element that uses the CSS class. For example, the googlecart-set-product-price attribute in the following HTML tag indicates that if the customer selects the X-Large size, then the price should be set to $14.99.

<option googlecart-set-product-price="$14.99">X-Large</option>

This example uses the following HTML:

<div class="product">
  <img class="product-image"
    src="files/google_tshirt.jpg"/>
  <div class="product-title">Google T-shirt</div>
  Price: <span class="product-price">$12.99</span><br/>
  Shipping: <span class="product-shipping">$4.99</span>
  Color: <br/>
    <input class="product-attr-color" name="color" type="radio" value="blue"/> blue<br/>
    <input class="product-attr-color" name="color" type="radio" value="green"/> green<br/>
    <input class="product-attr-color" name="color" type="radio" value="red"/> red<br/>
  Size: <select class="product-attr-size">
          <option googlecart-set-product-price="$12.99">Small</option>
          <option googlecart-set-product-price="$12.99">Medium</option>
          <option googlecart-set-product-price="$12.99">Large</option>
          <option googlecart-set-product-price="$14.99">X-Large</option>
        </select><br/><br/>
 <div role="button" alt="Add to cart" tabindex="0" class="googlecart-add-button">
 </div> 
</div>

Identifying product information

The following table summarizes the CSS class names that you can use to provide product information:

Class Name Description
product Required. The element that specifies this CSS class contains additional elements that specify product information, shipping costs and shopping cart controls.
product-title Required. The element that specifies this CSS class contains the name of the product.
product-price Recommended. The element that specifies this CSS class contains the price of the product. If a product does not specify a price, then Checkout sets the price to zero (free).
product-image Recommended. The element that specifies this CSS class contains an image of the product.
googlecart-quantity Optional. The element that specifies this CSS class indicates how many units of the item are being ordered. For example, if an item costs $10 and the googlecart-quantity value is set to 2, then the total cost for that item will be $20 (2 x $10). If a product does not specify a quantity, then Checkout automatically sets the quantity to 1. You can use an <input> or <select> element to let the user decide how many units of the item to add to the cart.
product-url Optional. The element that specifies this CSS class contains a URL related to the product, such as a product details page.
product-shipping Optional. The element that specifies this CSS class contains the per-unit shipping cost for the product. If a product does not specify a per-unit shipping cost, then Checkout sets the per-unit shipping cost to zero.
product-shipping-first Optional. The element that specifies this CSS class contains the shipping cost for this product if it is the only product in the shopping cart. If you do specify this value, then Google Checkout will calculate shipping costs by adding the maximum product-shipping-first value for all items in the shopping cart to the per-unit shipping cost for every other item in the cart. If the product-shipping-first cost is assessed for a product, then the per-unit cost, which is identified by the product-shipping class, will not be assessed for that same product.
product-digital Optional. If this class appears on any HTML tag for a product, then the product is treated as digital content. Google Checkout will not ask your customer for a shipping address if the shopping cart only contains digital items.
product-attr-XXX Optional. The shopping cart defines CSS styles that identify several basic and universally applicable product attributes. However, you may still want or need to associate other information with a product offer, such as the size or color that the customer is purchasing.

The product-attr-XXX class name allows you to create an unlimited number of custom attributes. For each attribute, set XXX to the attribute name. Attribute names should be short – one or two words – and may not contain spaces. If the attribute name is multiple words, use hyphens to separate the words – e.g. product-attr-release-date.
product-weight Optional. The element that specifies this CSS class specifies the weight of the product in pounds. You must specify product weights if you use the carrier-calculated shipping feature, which allows Google Checkout to dynamically calculate shipping rates for several FedEx, UPS and USPS shipping options. Carrier-calculated shipping is only available for U.S. merchants.

The following guidelines apply to the product information that you specify:

  • Any HTML element annotated with one of these CSS classes can also contain other classes for CSS or other purposes.

  • A single product should not contain multiple elements annotated with the same standard product keyword. (All of the keywords in the list above are for standard product classes except for the product-attr-XXX class.

  • A single product may contain multiple elements annotated with the same custom keyword. The Google Checkout shopping cart JavaScript will set the value for that keyword to be a comma-separated list of the values of those elements.

    For example, if a product node – e.g. <div class="product"> – has two child nodes with the class product-attr-artist, then when the item is added to the shopping cart, the item's artist property will be set to the value of both child nodes separated by a comma.

    If the elements that contain the same custom keyword are checkboxes, radio buttons or options in a select menu, then the comma-separated list will only contain the values of the selected elements. For example, if a restaurant lets a customer select toppings for a pizza and then add the pizza to the shopping cart, the shopping cart will only list the selected toppings.

Adding an Item to the Shopping Cart

The following CSS class names identify elements on your web page that a customer can click to add an item to the shopping cart. Each item should contain an HTML element annotated with one of these CSS class names:

Class Name Description
googlecart-add This CSS class identifies the element that can be clicked to add an item to the shopping cart.
googlecart-add-button This CSS class inserts Google's Add to cart button inside the corresponding element. The customer can click the button to add the item to the shopping cart. Note: This class may only be used on <div> elements.
googlecart-buynow-button This CSS class inserts Google's Buy Now button inside the corresponding element. The customer can click the button to proceed directly to Google Checkout to buy the item. Note: This class may only be used on <div> elements.

« Previous
(Annotating Pages for the Shopping Cart)
Next »
(Specifying Shipping Options)