AddToCart: Difference between revisions

From Barion Documentation
Jump to navigation Jump to search
No edit summary
 
Line 1: Line 1:
= addToCart =
__NOTOC__
{{PageTitle|title= addToCart}}
 
{| style="margin-left:2em;" align="right"
| __TOC__
|}


<blockquote>Required event. Handling this event on your Barion shop's screens is required as part of a Barion Full Pixel implementation.</blockquote>
<blockquote>Required event. Handling this event on your Barion shop's screens is required as part of a Barion Full Pixel implementation.</blockquote>

Latest revision as of 10:07, 23 May 2024

addToCart

Required event. Handling this event on your Barion shop's screens is required as part of a Barion Full Pixel implementation.

Short description

The event represents the user action of adding an item for sale to their cart in your webshop.

Trigger

A button click that explicitly represents the user's decision to purchase the item. This is mostly implemented by the item being added to the user's cart – if your webshop doesn't use the shopping cart metaphor, trigger this event when the user selects an equivalent button, such as one labeled "Buy" or "Reserv".

Properties

Custom properties are supported.

Name Data type Description Required? Note
contentType One of the following string options: "Page", "Product", "Article", "Promotion", "Banner", "Misc" The type of page that triggered the event. yes In case this is an item listing page, pass "Product". Otherwise, select the option that best matches the type of page. See the event's list property also.
currency string (ISO 4217 currency code) yes Required if "contentType": "Product"
id string A unique identifier for the item or promotional material, such as a product ID, SKU, or promotion ID. yes
name string The full name associated with the item or promotional material, or the title of the visited page.
Make sure that you use the same name across Barion Pixel events for the same item or promotional material.

yes
quantity float The quantity that is displayed on the page for the item on sale. yes Required if "contentType": "Product"
totalItemPrice float The total price of the item or items added to the cart, in the specified currency. yes
unit string The displayed item's unit (e.g. piece, set, liter). yes Required if "contentType": "Product"
unitPrice float The price of a single unit of the item for sale, in the currency property. yes Required if "contentType": "Product"
brand string The item's brand. no
category string -separated subcategory chain (e.g. "clothes|shoes|winter") or the single category (e.g. "winter shoes") of the item for sale. no
contents array An array of content objects if the page displays multiple items for sale. no Don't include shipping or coupons.
coupon string The coupon code used when the user added the item to the cart. no
creative string The associated promotion's name or description, such as an advertising slogan or the name of the promotional image file. no
customerValue float Your self-defined metric that represents the business value of the given customer (based on for example their average basket value). no
ean string The item's International Article Number (EAN). no
list string Select the function of the visited page from one of the following string options: "HomePage", "SearchPage", "ProductPage", "Recommendation", "ComparisonPage", "BasketPage", "Checkout", "Misc" no
positioning string The item's position in a list or collection (e.g. 2) or the position of its promotion on the page (e.g. banner_slot_1). no
step integer The order that the visited page is displayed in within a multi-step checkout process, if applicable. no Step numbering starts at 1.
variant string The variant of the item on sale that distinguishes it from other similar items (such as color, material, or time and date). no

Barion Pixel throws the following errors in your browser console if a required property is missing or is passed in the wrong format:

"Barion Pixel: Format of PROP_NAME is invalid in EVENT_NAME"

"Barion Pixel: The PROP_NAME parameter of the EVENT_NAME event cannot be empty"

Sample implementation

Physical item sample

// sample product data for single item
var addToCartProperties = {
    'contentType': 'Product',
    'currency': 'HUF',
    'id': 'item_42',
    'name': "Hitchhikers' Guide to the Galaxy, hardcover, ISBN: 9780575115347",
    'quantity': 10.0,
    'totalItemPrice': 49900.0,
    'unit': 'pcs.',
    'unitPrice': 4990.0,
    'brand': 'Gollancz',
    'category': 'books|hardcover|scifi, books|hardcover|comedy',
    'coupon': '43763436874',
    'creative': 'product_page_promo_42',
    'customerValue': 150.0,
    'ean': '9780575115347',
    'list': 'ProductPage',
    'positioning': '3',
    'variant': 'hardcover'
}
// sample product data for bundled items
var addToCartProperties = {
    'contentType': 'Product',
    'currency': 'HUF',
    'id': 'item_42pack',
    'name': "Hitchhikers' Guide to the Galaxy, hardcover, ISBN: 9780575115347",
    'quantity': 10.0,
    'totalItemPrice': 150000.0,
    'unit': 'pcs.',
    'unitPrice': 15000.0,
    'brand': 'Gollancz',
    'category': 'books|hardcover|scifi, books|hardcover|comedy',
    'contents': [{
        'contentType': 'Product',
        'currency': 'HUF',
        'id': 'item_42',
        'name': "Hitchhikers' Guide to the Galaxy, hardcover, ISBN: 9780575115347",
        'quantity': 3.0,
        'totalItemPrice': 7500.0,
        'unit': 'pcs',
        'unitPrice': 2500.0,
        'brand': 'Gollancz',
        'category': 'books|hardcover|scifi, books|hardcover|comedy',
        'description': 'The Hitchhikers Guide to the Galaxy is a comedy science fiction series created by Douglas Adams.',
        'ean': '9780575115347',
        'imageUrl': 'https://images-na.ssl-images-amazon.com/images/I/51MzUz8rQcL._SX305_BO1,204,203,200_.jpg',
        'variant': 'hardcover'
        },
        {
        'contentType': 'Product',
        'currency': 'USD',
        'id': 'item_42en',
        'name': "Hitchhikers' Guide to the Galaxy, hardcover, ISBN: 9780575115347",
        'quantity': 3.0,
        'totalItemPrice': 25935,
        'unit': 'pcs',
        'unitPrice': 8645,
        'brand': 'Gollancz',
        'category': 'books|hardcover|scifi, books|hardcover|comedy',
        'description': 'The Hitchhikers Guide to the Galaxy is a comedy science fiction series created by Douglas Adams.',
        'ean': '9780575115347',
        'imageUrl': 'https://images-na.ssl-images-amazon.com/images/I/51MzUz8rQcL._SX305_BO1,204,203,200_.jpg',
        'variant': 'hardcover'
        }],
    'coupon': '43763436874',
    'creative': 'add_to_cart_promo_42',
    'customerValue': 150.0,
    'ean': '9780575115347',
    'list': 'BasketPage',
    'positioning': '3',
    'variant': 'hardcover'
}
// Use one of these to add the event listener to the button click (use only one):
// vanilla JS (if you don't use jQuery)
document.getElementById('addtocart_button').addEventListener('click', function() {
    bp('track', 'addToCart', addToCartProperties);
});
// jQuery
$("#addtocart_button").click(function() {
    bp('track', 'addToCart', addToCartProperties);
});