Pushing events

Push you own custom goals and key/values pairs using GetQuanty installed script

The script you installed on your web pages loads a library allowing you to transmit your own data to GetQuanty if you need to and recover them in exports, webhooks or using our API.

Three functions are available once the script is loaded (be aware that the library is asynchronously loaded so it is recommended to test the existence of these functions before using them if you need to use them without waiting for user interaction, then you have to subscribe to "scoring_done" event)

  • GQGoal(goal: string) : allows you to transmit a tag as a goal, which will be added to other goals triggered in the visit.
  • addCustom(key: string, value: string) : allows you to transmit key/value pairs that will be added as custom field in our API.
  • addCustomQS(querystring: string) : allows you to transmit multiple key/value pairs as query string format (ex: "key_1=value_1&key_2=value_2&key_3=value_3...")

Using these functions is useful in the following cases :

  • When it isn't possible to rely on the URL pattern to detect an event. This is the case, for exemple, if you want to detect clicks on buttons, videos or when foirms are loaded without reloading the page.
  • When you want to associate a visit with a key in your database (ex: a customer ID, a visited offer ID, ...)

Let's suppose that you want to push an event whenever an article is added to your customer cart with it price. Here is an exemple of how you can do so using GQGoal and addCustom functions :

document.querySelector(".add-to-cart").addEventListener("click", (e) => { 
  var price = document.querySelector("[data-price-amount]").innerText;
  // due to asynchronous load of the library is it recommanded to check existance before calling
  if (typeof(GQGoal) == "function" && typeof(addCustom) == "function") {
    GQGoal("ajout au panier");  
    addCustom("montant", price);
  }
});