Forcing Collection

One of the criteria of implementations can be the need to be able to collect particular sessions that may fall outside of the standard sampling method. This can be achieved by making use of the DXA setCollectionJavaScript endpoint, which will ensure that if a users' session is not in the sample, and therefore not being collected, it will begin to be collected from the point of calling the endpoint.

The end-point that is required for forcing collection can be seen below:
<script type="text/javascript">
decibelInsight('setCollection', true);
</script>
You can use the setCollection JavaScript API to force collection on all relevant journeys on your property. For example, you may have a 20% sample rate for your property, but want to collect all journeys that reach your checkout. You can use the setCollection call on the Checkout page which would force collection from this point onward for those who were previously being sampled out, while those already in the sample will continue to be collected.
Note: Upon calling setCollection, this will proceed to collect the user for the remainder of their session and potentially future sessions, see below for further info. If you trigger the setCollection call on a particular part of a flow, for example a Checkout page onwards, or Step 3 of a Sign-Up flow, if the user goes back to a previous point, i.e. from checkout to a product page, or step 3 back to step 2, they will continue to be collected.
Meanwhile, the following example shows a session being marked for collection following a checkout button being clicked on the website:
<script type="text/javascript">
   var buttonEl = document.querySelector('#checkoutButton');
   buttonEl.addEventListener('click', function(){
      decibelInsight('setCollection', true);
   });
</script>

Arguments

  • status (boolean) — New collection status for the current session
  • remember (boolean|integer) — Whether to remember the collection status for the next session (optional). If true is provided, the status will apply for this and all future sessions. If false is provided, the status will apply for this session only. If an integer value is provided, the status will apply to this session and any future sessions within the provided number of seconds. If not provided, this will default to true.

Testing

In order to test if triggering setCollection has been successful, you can do this by using the DXA Google Chrome extension. Ensure you have Logging enabled and are logged into the DXA platform within the same browser session that you're testing.

Upon triggering the setCollection in testing, you will see a DXA log printed to the console, such as in the second line of the below image:Triggering setCollection displayed in the console

Further examples

A few more examples can be seen below:
// Enable collection for the current session and future sessions for the current visitor.
decibelInsight('setCollection', true);

// Enable collection for the current session and keep the visitor in the sample for up to three days.
decibelInsight('setCollection', true, 259200);

// Disable collection for the current session only.
decibelInsight('setCollection', false, false);