Search

From Barion Documentation
Jump to navigation Jump to search


search

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 monitors users' interest in searched-for items. This event should be implemented every time a search button is clicked.

Trigger

A button click that starts a search in your webshop.

If your webshop displays search results when a search box is updated, trigger the event when the user clicks on a search result.

For product selection pages where search serves a filtering function, pass the event the query generated in the address bar as the searchString (In this example, the query would be "goats".)

Properties

Custom properties are supported.

Name Data type Description Required? Note
searchString array The user-entered search terms, or the HTTP property that contains the search terms. yes
contents array An array of content objects if the page displays multiple items for sale. no Don't include shipping or coupons.
contentType One of the following string options: "Page", "Product", "Article", "Promotion", "Banner", "Misc" The type of page that triggered the event. no 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) The currency that the associated item's price is listed in. no Required if "contentType": "Product"
customerValue float Your self-defined metric that represents the business value of the given customer (based on for example their average basket value). no
id string A unique identifier for the item or promotional material, such as a product ID, SKU, or promotion ID. no
name string The name of the search element that the search was triggered in, such as a search box or a filter array. no
totalResults integer The total number of results that the search returned. 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

Sample search result data

 var searchProperties = {
    'searchString': 'big GOATS',
    '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'
        }],
    'contentType': 'Product',
    'customerValue': 150.0,
    'id': 'search_01',
    'name': 'Book Search',
    'totalResults': 2
}

// 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('search_button').addEventListener('click', function() {
    bp('track', 'search', searchProperties);
});
// jQuery
$("#search_button").click(function() {
    bp('track', 'search', searchProperties);
});