...
Code Block |
---|
|
<script type="text/javascript">
HawkSearch.customEvent = function() {
//<![CDATA[
if ('{{template}}') {
if (('{{template}}' == 'pages/category') || ('{{template}}' == 'pages/custom/category/category') || ('{{template}}' == 'pages/search')) {
HawkSearch.Tracking.track('pageload', {pageType: 'landing'}); } else if ('{{template}}' == 'pages/product') {
HawkSearch.Tracking.track('pageload', {pageType: 'item'});
HawkSearch.Context.add("UniqueId", "{{product.id}}"); } else if ('{{template}}' == 'pages/cart') {
HawkSearch.Tracking.track('pageload', {pageType: 'cart'}); } else {
HawkSearch.Tracking.track('pageload', {pageType: 'custom'});
}
} //]]>
}
</script> |
In \templates\pages\order-confirmation.html place the following code before the {{/partial}}
handlebar:In \templates\layout\base.html and \templates\layout\empty.html place the following code before the </body>
tag:
Code Block |
---|
|
<script type="text/javascript">
HawkSearch.customEvent = function() {
//<![CDATA[ if ('{{template}}') {
if (('{{template}}' == 'pages/category') || ('{{template}}' == 'pages/custom/category/category') || ('{{template}}' == 'pages/search')) {
HawkSearch.Tracking.track('pageload', {pageType: 'landing'});
}
else if ('{{template}}' == 'pages/product') {
HawkSearch.Tracking.track('pageload', {pageType: 'item'});
HawkSearch.Context.add("UniqueId", "{{product.id}}");
}
else if ('{{template}}' == 'pages/cart') {
HawkSearch.Tracking.track('pageload', {pageType: 'cart'});
}
else {
HawkSearch.Tracking.track('pageload', {pageType: 'custom'});
}
} //]]>
}
</script> |
In \templates\pages\order-confirmation.html place the following code before {{/partial}}
Code Block |
---|
|
<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: 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> |
...