How can values of customData fields be changed?

There are two methods to either permanently or temporary change the values of customData : setCustomData and setCustomDataOnce/sendCustomDataEvent

Both methods receive a subset of the available customData fields you want to change

collector.setCustomData({
  customData1: "new-value",
  customData3: "new-value"
})

setCustomData

This methods allows you to change the value of a customData field during a session. The method can be called multiple times during a session. There are two different cases to consider here:

Case 1

If the current state is paused or played, an additional sample will be sent when using this method. This sample will contain the old values for the changed customData fields. Additionally, the sample will contain all measurements up until that point and will display the state when the method was triggered (paused or played). After that sample, the collector will continue with collecting data as new samples, however all following samples will contain the new values for the changed customData fields.

Case 2

If current state is something other than paused or played no samples will be sent. The collector will just change the customData values internally and all samples from this point on will contain the new customData values.

setCustomDataOnce / sendCustomDataEvent

This method allows you to change the value of a customData field temporarily for one sample.

When this method is called, an additional sample will be sent. That sample will trigger the state = customdatachanged and write new values for the selected customData fields. All other duration measurements will be set to 0 (e.g. played, paused, duration etc).