Setting up monitoring with custom Javascript

🎯
Setting up monitoring with custom javascript, enables you to control entirely the process but will require you to understand well Potions Events and the right occasions to send them.
This documentation will explain you how and when to send those events by
  • showing examples of Potions Analytics Events sent to gtag (GA4)
  • listing the Potions Analytics Events that need to be sent to your analytics
  • detailing how to use GTM to send the events

Examples of Potions Analytics Events sent to gtag (GA4)

Potions uses 5 different events to create its monitoring.
  • When an experience is shown to the user.
    • javascript
      window.gtag("event", "potions", { experience_id : "df9ee7d4-795b-4a5f-b11b-1a2558672811", action_id: "show", item_ids : '["66","316","321","326","126"]' });
  • When a product is clicked
    • javascript
      window.gtag("event", "potions", { experience_id : "df9ee7d4-795b-4a5f-b11b-1a2558672811", action_id: "go_to_page", item_id : "66" });
  • When a product is added to cart in a recommendation banner or an organized product list
    • javascript
      window.gtag("event", "potions", { experience_id : "df9ee7d4-795b-4a5f-b11b-1a2558672811", action_id: "add_to_cart_item", item_id : "66" });
  • when multiple products are added to cart
    • javascript
      window.gtag("event", "potions", { experience_id : "df9ee7d4-795b-4a5f-b11b-1a2558672811", action_id: "add_to_cart_items", item_ids : '["66","316"]' });
  • when an experiment audience is set
    • javascript
      window.gtag("event", "potions", { experiment_id : "df9ee7d4-795b-4a5f-b11b-1a2558672811", audience_id : "A" action_id: "set_experiment_audience" });

Potions Analytics Events

A Potions Analytics Event is named potions and contains all the relevant informations as property values.
Here is an example of a Potions Analytics Event sent to gtag (GA4) when showing an experience
A Potions Analytics Event can have the following properties :
Potions Analytics Event properties
Name
Description
Possible values
Potions Analytic Events Action Names
Potions Analytic Events Action Names 1
action_id
the action that led to sending the event
an action id
experience_id
the id of the experience concerned by the action
a Potions uuid
experiment_id
the id of the experiment (an AB Test campaign for instance)
a Potions uuid
audience_id
the id of the audience in an experiment
A or B or C
item_id
the specific item concerned by the action (like the item added to cart in an “add_to_cart_item” action)
an item_id
item_ids
a list of items concerned by the action (like the items shown in a “show” action)
an array of item_id
You can also add optional and custom properties that will help you creating your own reports in your analytics tools, they will simply not be used by Potions. For instance, it can be interesting to add the properties experience_name, experiment_name, placement_name to find more easily your indicators in your analytics.
Potions Analytics Events are sent on the following occasions
Potions Analytic Events Actions
action_id
Description
Required properties
Optional properties
Click action
show
when an experience is shown to the user.
go_to_page
when a product is clicked
add_to_cart_item
when a product is added to cart in a recommendation banner or an organized product list
add_to_cart_items
when multiple products are added to cart
set_experiment_audience
when an experiment audience is set
close
when an experience is closed
convert_XXX
when a conversion button is clicked (XXX can be anything)
The table above explains the possible values of the action_id property.
Here are the possibles values for the other properties :
  • any uuid : You can use any uuid for your placement_id, or your experiment id For placement_id : the uuid could be the id attribute of the div in which you show a Potions experience. For experiment_id : the uuid is the unique identifier of your experiment. A visitor should stay in a given audience for a given experiment_id. Therefore your code needs to send once the set_audience event and keep the audience_id of the visitor for a given experiment_id. You can generate a uuid with the following tool (uuid version 4)
  • A or B or C : Well… A, B or C
  • an item_id : a string representing the id either of the sku or the variant of the item.
  • an array of item_id : a stringified version of a javascript array of item_id

Using GTM to send Potions events

We strongly recommend using GTM to send your analytics events.
It will provide useful debugging methods and enable you to eventually switch analytics easily.
First you need to setup your GTM account to send Potions Analytics Events pushed in your datalayer to your analytics tool.
Then, instead of calling gtag, you push the event to the datalayer, this way
javascript
window.datalayer.push( { event : `potions_event_${window.crypto.randomUUID()}`, potions: { experience_id : "df9ee7d4-795b-4a5f-b11b-1a2558672811", action_id: "add_to_cart_items", item_ids : '["66","316"]' } } );