Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The APP does  not install  the tracking code for implementing all of the advanced reporting supported by Hawksearch. The  keyword and autocomplete reports will be populated based on the search keywords on the search results  page and autocomplete requests. However  for the personalization  features please implement the "Event  tracking" code specified in the following section


Event Tracking Code


The code can be implemented using tracking tags. For any additional questions please reach out support@hawksearch.com

...

<script type="text/javascript">
    HawkSearch.customEvent = function() {
        HawkSearch.Tracking.track('pageload', {pageType: 'order'});
    }

    var orderNum = '{{checkout.order.id}}';
    console.log('orderNo = ' + orderNum);
    if (orderNum) {
        var xhttp = new XMLHttpRequest();
        xhttp.onreadystatechange = function() {
            if (this.readyState == 4 && this.status == 200) {
                if (this.responseText) {
                    var response = JSON.parse(this.responseText);
                    var itemList = [];

                    for (var i = 0; i < response.lineItems.physicalItems.length; i++) {
                        var item = response.lineItems.physicalItems[i];
                        itemList.push({
                            uniqueid: item.productId,
                            itemPrice: item.listPrice,
                            quantity: item.quantity
                        });
                    }

                    var hsObject = {
                        orderNo: orderNum,
                        itemList: itemList,
                        total: response.orderAmount,
                        subtotal                    subTotal: response.baseAmount,
                        tax: response.taxes[0].amount,
                        currency: response.currency.code
                    };

                    HawkSearch.customEvent = function() {
                        HawkSearch.Tracking.track('sale', hsObject);
                    }
                }
            }
        };
        xhttp.open('GET', '/api/storefront/orders/' + orderNum, true);
        xhttp.send();
    }
</script>

...