Bigcommerce
Last updated
<script type='application/javascript'>
;(function () {
window.Zigpoll = {
accountId: 'YOUR_ACCOUNT_ID'
};
var script = document.createElement("script");
script.type = "text/javascript";
script.charset = "utf-8";
script.src = "//cdn.zigpoll.com/static/js/main.js";
script.async = true;
document.head.appendChild(script);
}());
</script><script>
// Fetch API to get product, order and customer details
var orderId = '{{ checkout.order.id }}';
var api = '/api/storefront/orders/'+ orderId;
fetch(api)
.then((res) => res.json())
.then((order)=>{
var orderValue = order.orderAmount;
var email = order.billingAddress.email;
var phone = order.billingAddress.phone;
var firstName = order.billingAddress.firstName;
var lastName = order.billingAddress.lastName;
var city = order.billingAddress.city;
var region = order.billingAddress.stateOrProvince;
var country = order.billingAddress.country;
var countryCode = order.billingAddress.countryCode;
var address = order.billingAddress.address1+' '+order.billingAddress.address2;
var postalCode = order.billingAddress.postalCode;
var lineItems = [];
if (order.lineItems) {
Object.keys(lineItems).forEach(function (key) {
lineItems[key].forEach(function (items) {
items.forEach(function (item) {
lineItems.push(item.name);
})
})
})
if (lineItems.length) {
lineItems = lineItems.join(', ');
}
}
// Prepare Zigpoll Variables
var accountId = 'YOUR_ACCOUNT_ID';
window.Zigpoll = {
accountId: accountId
};
window.Zigpoll.user = {
id: email,
metadata: {
email: email,
phone: phone,
name: [firstName, lastName].join(' ').trim(),
city: city,
region: region,
country: country,
countryCode: countryCode,
address: address,
postalCode: postalCode
}
}
window.Zigpoll.metadata = {
orderValue: orderValue,
orderId: orderId,
lineItems: lineItems
}
var precursorEvent = window.Zigpoll.precursorEvent || {};
precursorEvent.type = 'bigcommerce-order-placed';
precursorEvent.uniqueId = ''+orderId;
// Load Zigpoll Script
var script = document.createElement("script");
script.type = "text/javascript";
script.charset = "utf-8";
script.src = '//cdn.zigpoll.com/static/js/main.js';
document.head.appendChild(script);
});
</script>