This guide provides information on how to use Nitro's JavaScript API to identify visitors and track various events on your website.
Use nitro.identify method to identify visitors by providing their email, phone, and name.
nitro.identify("<visitor_email>", "<visitor_phone>", "<visitor_name>");
Different events can be tracked with the help of methods enlisted below:
Use nitro.view method to track page views.
// Example view event data
view_data = {
page: "https://someurl.com"
}
// Track view event
nitro.view(view_data);
Use nitro.updatecart method to track when items are added to the cart or removed from the cart. line_items should contain all items currently in the cart.
While sending update cart event send all the line items currently in cart. Trigger this event whenever anything in cart changes so that we can capture the timeline of cart activity in order.
// Example add to cart event data
cart_data = {"line_items": line_items, "cart_value": cart_value}
cart_data = {
cart_url: "https://someurl.com",
product_id: 123456,
line_items: [{
"quantity": 1,
"title": "Black Box",
"line_price", 24.00,
"id": "987654" (Variant Id),
"product_id": "1234567",
"image_url": "variant or product image url"
},
{
"quantity": 1,
"title": "Pink Box",
"line_price", 20.00,
"id": "987654" (Variant Id),
"product_id": "1234568",
"image_url": "variant or product image url"
}],
cart_value: 44.00
}
// Track add to cart event
nitro.updatecart(cart_data);
Use nitro.checkout method to track checkout events.
// Example checkout event data
checkout_data = {
checkout: "<checkout_url>",
items: [
{
product_id: 12345,
price: 12.00,
product_url: "https://someurl.com/product_id"
},
{
product_id: 12346,
price: 18.00,
product_url: "https://someurl.com/product_id"
}
],
cart_value: <total_checkout_amount>,
}
// Track checkout event
nitro.checkout(checkout_data);
Use nitro.buy method to track purchase events.
// Example buy event data
buy_data = {
checkout_url: "https://someurl.com",
order_id: "1231312312312",
items: [
{
product_id: 12345,
price: 12.00,
product_url: "https://someurl.com/product_id"
},
{
product_id: 12346,
price: 12.00,
product_url: "https://someurl.com/product_id"
}
]
}
// Track buy event
nitro.buy(buy_data);
Use nitro.productView method to track product view events.
// Example product view event data
product_data = {
"title": "Your product title",
"image": "https://pinkcans.myshopify.com/cdn/shop/files/Main.jpg?v=1718006767",
"page": "https://pinkcans.myshopify.com/products/the-videographer-snowboard",
}
// Track product view event
nitro.productView(product_data);
Use nitro.categoryView method to track category view events.
// Example category view event data
data = {
"page" : "https://pinkcans.myshopify.com/collections/all",
"category" : "All",
}
// Track category view event
nitro.categoryView(category_data);
Use nitro.track method to track custom events.
// Example custom event
nitro.track("<EVENT_NAME>", EVENT_VALUE);
Events to enter funnel = ["addtocart", "updatecart", "checkout"]
Events to exit funnel = "buy"