Introduction
In this article, you will learn how to calculate the time spent in a node.
Step-by-Step Instructions:
Step 1: Create a custom field named time_enter.
- Make sure to use a number type for it.
Step 2: Create a custom field named time_exit.
- Make sure to use a number type for it.
Step 3: Create a calculated custom field for the time spent. Please do not forget to include the formula as shown in the image below.
Step 4: In a node, click the “Add Scripts” button as shown below.
Add the script below and set to fire on “Enter”.
<script>
let timeenter = {_c_eventtime}
DT.setField('time_enter', timeenter);
</script>
Add the script below on the same node and fire on “Exit”.
<script>
let timeexit = {_c_eventtime};
DT.setField('time_exit', timeexit);
</script>
The Custom Field time_spent will automatically calculate the time difference between the time you entered the node to the time you exit the node. The result will be in seconds.