Custom Javascript Events for Ecommerce

Make sure you first added the main script loader. That is required and nothing below will work without the main script..

The article covers integrations of the following codes:

  1. Add ViewItem Event
  2. Add ViewCategory Event
  3. Add Search Event
  4. Add AddToCart Event
  5. Add AddToWishlist Event
  6. Add Checkout Event
  7. Add Confirm Order Event
  8. Add Login Event

 

Things to know:

  • These events allow us to handle all tracking/segmentation/personalization
  • Before creating site events, it’s recommended to create the product feed. Some elements are required to be indentical in both (product_id, category_id).
  • Important: Please change red text with exemplified values.
  • For product_id and category_id, make sure they are sent as lowercase and all spaces are replaced with underscore.
  • A product with id “FLV-GV 12” becomes “flv-gv_12” in our system.
  • A category with id “Photo & Video accessories-extra” becomes “photo_&_video accessories-extra”
  • All events support a generic object param:
    • Example: _vteq.push({“viewitem”:{“itemId”:”123″, “generic”:{“type”:”mobile”}}})
    • More details about generic can be found in this article.

1. Add ViewItem Event

  • Needed to tell us when a user lands on a product page
  • File to modify. Product Page (the product display page)
  • * Mandatory

Note: please change ‘unique-product-id’ with each product id on product page, the same from product feed

<script>
window._vteq = window._vteq || [];
window._vteq.push({
"viewitem": {
itemId: "unique_product-id"
}
});
</script>

2. Add ViewCategory Event

 

  • Needed to tell us when a user lands on a category page
  • File to modify: Category Page (the category listing page)
  • * Mandatory

Note: please change ‘unique-category-id’ with each category id on product page, the same from product feed

<script>
window._vteq = window._vteq || [];
window._vteq.push({
"viewcategory": {
category: "unique_category-id"
}
});
</script>

3. Add Search Event

  • Needed to tell us when a user does a search
  • File to modify: Search Page (the search listing results page)
  • * Mandatory for emailing personalization

Note: please change ‘search-query’ with the query string of user.

<script>
window._vteq = window._vteq || [];
window._vteq.push({
"search": {
query: "search-query"
}
});
</script>

4. Add AddToCart Event

  • Needed to tell us when a product is successfully added to the Cart
  • It should be called from all possible locations of the user event
  • * Mandatory for emailing personalization

Note: please change ‘unique-product-id’ with each product id

Note: please change ‘unique-cart-id’ with an unique identifier for the cart. If you have one, we can restore/recreate the cart later by passing back this param

<script>
window._vteq = window._vteq || [];
window._vteq.push({
addtocart: {
itemId: "unique-product-id",
cartId: "unique-cart-id"
}
});
</script>

5. Add AddToWishlist Event

 

  • Needed to tell us when a product is added to wishlist (optional)
  • It should be called from all possible locations of the user event, javascript or loaded pages
  • * Mandatory for emailing personalization

Note: please change ‘unique-product-id’ with each product id

<script>
window._vteq = window._vteq || [];
window._vteq.push({
addtowishlist: {
itemId: "unique-product-id"
}
});
</script>

6. Add Checkout Event

  • Needed to tell us when a user starts the checkout process, or enters another step of the checkout
  • Please fill the step parameter with a string value to define the current step name
  • * Mandatory for emailing personalization

Note: please change ‘current-checkout-step’ with name of the checkout step if you have a multi-step checkout

<script>
window._vteq = window._vteq || [];
window._vteq.push({
checkout: {
step: "current-checkout-step",
items: ["prod1", "prod2", "prod3" … ] //list of product id’s
}
});
</script>

7. Add Confirm Order Event

  • Needed to tell us when a user confirmed an order (is on the Thank You page)
  • File to modify: THANK YOU PAGE
  • * Mandatory

Note: please change ‘unique-order-id’ with order id, used to identify transactions later. Also order_total is required when items are missing or you do not use a product feed.

<script>
var items = [{id:"unique-product-id", quantity:1}, {...}, {...}];
window._vteq = window._vteq || [];
window._vteq.push({
confirmation: {
items: items,
orderId: "unique-order-id",
total: order_total
}
});
</script>

8. Add Login Event

  • Needed to tell us when a user has logged in/registered or just introduced an email address in your site
  • All emails are automatically taken from the website if option is enabled on your account
  • Use this event to also pass (any) attributes about users to our system. Make sure the attribute already exists, otherwise it will be ignored
  • File to modify: Every Page where user introduces an email address: Registration/Login/Purchase
  • * Mandatory for emailing personalization

Note: only user email is required in here.

Note: Please also put this code when “Login with Facebook”, when receiving the email from Facebook

<script>
window._vteq = window._vteq || [];
window._vteq.push({
login: {
email: "[email protected]", // required, string, user email
source: "newsletter", // optional, string, to determine where the user logged in. It will overwrite source attribute for the user
name: "alex" // optional, string, user full name
}
});
</script>

Having all these set will allow you to create some amazing marketing campaigns.

Option, for onsite campaigns you can make use of Page Variables

Related Articles