...
To integrate through API - Events Tracking API Integration.
To integrate through Rapid UI Framework: TrackingService | @bridgeline-digital/hawksearch-handlebars-ui
...
For Hawksearch v2.0L to v4.0L
...
:
Note |
---|
This section is only applicable for Hawksearch v2.0L-4.0L implementations with JavaScript integration. Please contact your Project Manager if you are unsure of the tracking implementation or version. |
...
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> |
Info |
---|
Note: this code only takes physical items into account, if digital items or gift certificates are sold the code will need to be adjusted to take that data point into account (order api can be found here: https://developer.bigcommerce.com/api-reference/storefront/orders/order/ordersbyorderidget ). |
...