Consuming events

Allows you to listen for events raised by Fresh Relevance when capturing information from your website.

registerEvent call

$TB.hooks.registerEvent allows for callback methods to be registered against events raised by Fresh Relevance when capturing information from your website.

Expected Parameters

eventName

Type: string

The name of the event that you wish to attach your callback method to, for a list of events raised by Fresh Relevance see $TB.hooks.validReturnEvents()

callback

Type: function pointer

A callback function you wish to run whenever the event has been raised.

Example usage

$TB.hooks.registerEvent('pageChangeCaptured', function(meta){ // Callback code });


Events to listen for

The following events are raised by Fresh Relevance, each event will pass return data long to the callback method you assign to listen to these events:


pageChangeCaptured

The pageChangeCaptured event is raised when Fresh Relevance has completed an evaluation of the webpage. This event is often fired as the result of a pageChange event call.

Event data

An object containing all data on this page captured by Fresh Relevance.

{
  "sbc": 1,
  "skip_heartbeat": false,
  "skip_initial_slots_load": false,
  "is_single_page_app": false,
  "c": "12ab3cd4ef",
  "w": "websiteID",
  "ip": "127.0.0.1",
  "v": "1234567890123",
  "doc": {
    "r": "https://www.website.co.uk/about/",
    "t": "Products for You - Shop Products Online | Website Name",
    "u": "https://www.website.co.uk/"
  },
  "tmsd": {},
  "extend": {},
  "typ": 1,
  "ptyp": 0,
  "curr": "GBP",
  "sbr": "website",
  "ua": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
  "bo": "runInitial",
  "validate": true,
  "trace": true,
  "ignore_filters": true
}



productCaptured

Raised when a product has been captured by Fresh Relevance. This event will be raised as a result of a productBrowse or productVariantSelected event being called.

Event data

An object containing the product data captured on this page.

{
  "u": "https://website.co.uk/product/short_sleeve_shirt",
  "n": "Short Sleeved Shirt",
  "img": "https://cdn.website.co.uk/upload/siteimages/product0_img.jpg",
  "desc": "The iconic short sleeved shirt.",
  "prid": "product0",
  "sku": "product0",
  "cat": [
    {
      "g": "brand",
      "n": "Brand Name"
    }
  ],
  "curr": "GBP",
  "sbr": "website",
  "uv": 38,
  "ruv": 50,
  "up": "£38.00",
  "rup": "£50.00"
}



listCaptured

Raised when a product list page has been captured by Fresh Relevance. This event will be raised as a result of a productList event call.

Event data

An array containing objects of each product captured on the page.

[
  {
    "u": "https://www.website.co.uk/product/handbag",
    "n": "Handbag",
    "prid": "product3",
    "sku": "product3",
    "cat": [
      {
        "g": "brand",
        "n": "Brand Name"
      }
    ],
    "curr": "GBP",
    "sbr": "website",
    "uv": 40,
    "up": "£40.00",
    "ruv": 60,
    "rup": "£60.00"
  },
  {
    "u": "https://www.website.co.uk/product/trousers",
    "n": "Trousers",
    "prid": "product40",
    "sku": "product40",
    "cat": [
      {
        "g": "brand",
        "n": "Brand Name"
      }
    ],
    "curr": "GBP",
    "sbr": "website",
    "uv": 40,
    "up": "£40.00",
    "ruv": 60,
    "rup": "£60.00"
  },
  {
    "u": "https://www.website.co.uk/product/headphones",
    "n": "Headphones",
    "prid": "product79",
    "sku": "product79",
    "cat": [
      {
        "g": "brand",
        "n": "Brand Name"
      }
    ],
    "curr": "GBP",
    "sbr": "website",
    "uv": 40,
    "up": "£40.00",
    "ruv": 60,
    "rup": "£60.00"
  }
]



cartUpdated

Raised when a cart has been captured on this page by Fresh Relevance. This event will be raised as a result of either a cartUpdate, addCartProduct or removeCartProduct event call.

Event data

An object containing cart meta data such as cart total and a list of products in the cart.

{
  "p": [
    {
      "u": "https://www.website.co.uk/product/short_sleeve_shirt",
      "img_tn": "https://cdn.website.co.uk/upload/siteimages/product0_img.jpg",
      "n": "Short Sleeved Shirt",
      "prid": "product0",
      "sku": "product0",
      "curr": "GBP",
      "sbr": "website",
      "qty": 1,
      "uv": 38,
      "up": "£38.00",
      "ruv": 50,
      "rup": "£50.00",
      "opt": {
        "size": " Med"
      }
    },
    {
      "u": "https://www.website.co.uk/product/3_pack_of_socks",
      "img_tn": "https://cdn.website.co.uk/upload/siteimages/product_img.jpg",
      "n": "3 Pack of Socks",
      "prid": "product1",
      "sku": "product1",
      "curr": "GBP",
      "sbr": "website",
      "qty": 1,
      "uv": 14,
      "up": "£14.00",
      "ruv": 24,
      "rup": "£24.00",
      "opt": {
        "size": " 7-11"
      }
    }
  ],
  "qty": 2,
  "curr": "GBP",
  "ex": {
    "delivery": 4.95
  },
  "cv": 52,
  "cp": "£52.00"
}



cartProductAdded

Raised when a cart has been captured on this page by Fresh Relevance. This event will be raised as a result of either a cartUpdate, addCartProduct event call.

Event data

An object containing cart meta data such as cart total and a list of products in the cart.

{
  "p": [
    {
      "u": "https://www.website.co.uk/product/short_sleeve_shirt",
      "img_tn": "https://cdn.website.co.uk/upload/siteimages/product0_img.jpg",
      "n": "Short Sleeved Shirt",
      "prid": "product0",
      "sku": "product0",
      "curr": "GBP",
      "sbr": "website",
      "qty": 1,
      "uv": 38,
      "up": "£38.00",
      "ruv": 50,
      "rup": "£50.00",
      "opt": {
        "size": " Med"
      }
    },
    {
      "u": "https://www.website.co.uk/product/3_pack_of_socks",
      "img_tn": "https://cdn.website.co.uk/upload/siteimages/product_img.jpg",
      "n": "3 Pack of Socks",
      "prid": "product1",
      "sku": "product1",
      "curr": "GBP",
      "sbr": "website",
      "qty": 1,
      "uv": 14,
      "up": "£14.00",
      "ruv": 24,
      "rup": "£24.00",
      "opt": {
        "size": " 7-11"
      }
    }
  ],
  "qty": 2,
  "curr": "GBP",
  "ex": {
    "delivery": 4.95
  },
  "cv": 52,
  "cp": "£52.00"
}



cartProductRemoved

Raised when a cart has been captured on this page by Fresh Relevance. This event will be raised as a result of either a cartUpdate, removeCartProduct event call.

Event data

An object containing cart meta data such as cart total and a list of products in the cart.

{
  "p": [
    {
      "u": "https://www.website.co.uk/product/short_sleeve_shirt",
      "img_tn": "https://cdn.website.co.uk/upload/siteimages/product0_img.jpg",
      "n": "Short Sleeved Shirt",
      "prid": "product0",
      "sku": "product0",
      "curr": "GBP",
      "sbr": "website",
      "qty": 1,
      "uv": 38,
      "up": "£38.00",
      "ruv": 50,
      "rup": "£50.00",
      "opt": {
        "size": " Med"
      }
    }
  ],
  "qty": 1,
  "curr": "GBP",
  "ex": {
    "delivery": 4.95
  },
  "cv": 52,
  "cp": "£52.00"
}



checkoutCaptured

Raised when a checkout page has been captured by Fresh Relevance. This event will be raised as a result of a checkout event call.

Event data

An object containing cart meta data such as cart total and a list of products in the cart.

{
  "p": [
    {
      "u": "https://www.website.co.uk/product/short_sleeve_shirt",
      "img_tn": "https://cdn.website.co.uk/upload/siteimages/product0_img.jpg",
      "n": "Short Sleeved Shirt",
      "prid": "product0",
      "sku": "product0",
      "curr": "GBP",
      "sbr": "website",
      "qty": 1,
      "uv": 38,
      "up": "£38.00",
      "ruv": 50,
      "rup": "£50.00",
      "opt": {
        "size": " Med"
      }
    },
    {
      "u": "https://www.website.co.uk/product/3_pack_of_socks",
      "img_tn": "https://cdn.website.co.uk/upload/siteimages/product_img.jpg",
      "n": "3 Pack of Socks",
      "prid": "product1",
      "sku": "product1",
      "curr": "GBP",
      "sbr": "website",
      "qty": 1,
      "uv": 14,
      "up": "£14.00",
      "ruv": 24,
      "rup": "£24.00",
      "opt": {
        "size": " 7-11"
      }
    }
  ],
  "qty": 2,
  "curr": "GBP",
  "ex": {
    "delivery": 4.95
  },
  "cv": 52,
  "cp": "£52.00"
}



purchaseCompleteCaptured

Raised when a purchase complete page view has been captured by Fresh Relevance. This event will be raised as a result of a purchaseComplete event call.

Event data

An object containing all data on this page captured by Fresh Relevance. This may or may not include an order number, which will be located in co.o_num.

{
  "sbc": 1,
  "skip_heartbeat": false,
  "skip_initial_slots_load": false,
  "is_single_page_app": false,
  "c": "12ab3cd4ef",
  "w": "websiteID",
  "ip": "000.0.0.1",
  "v": "1234567890123",
  "doc": {
    "r": "https://www.website.co.uk/about/",
    "t": "Products for You - Shop Products Online | Website Name",
    "u": "https://www.website.co.uk/"
  },
  "tmsd": {},
  "extend": {},
  "typ": 1,
  "ptyp": 8,
  "curr": "GBP",
  "sbr": "websitename",
  "co": {
    "o_num": "AB123C"
  },
  "ua": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.88 Safari/537.36",
  "bo": "runInitial",
  "validate": true,
  "trace": true,
  "ignore_filters": true
}



userCaptured

Raised when a user has been captured by Fresh Relevance. This event will be raised as a result of a userLoggedIn event call.

Event data

An object containing user meta data such as name and email.

{
  "fn": "John",
  "ln": "Doe",
  "e": "[email protected]"
}