RUM powered by Grail JavaScript API - 1.327.2
    Preparing search index...

    Function addEventModifier

    • Modifies future events with the provided modifier function. Returning a non-object or null discards this event and prevents future mutator functions to be executed.

      Certain reserved fields and namespaces can’t be modified in any way (added, removed or overridden), while others are open for modification. See the public documentation for a detailed list of reserved/open fields (link will be added in the future).

      The context differs based on the processed event and availability of data. For events sent with dynatrace.sendEvent, the optionally provided context will be provided as custom context. The context object contains a "type" and optionally a "sub_type" parameter, which can be used to distinguish them.

      Parameters

      • eventModifier: (jsonEvent: Readonly<JSONEvent>, eventContext?: EventContext) => JSONEvent

        The modifier function to modify a given (readonly) JSONEvent. It receives an optional context depending on the type of event, if available. The returned event must be a new object, otherwise modification will be ignored. Modification is only allowed for fields declared in AllowedModificationFields.

      Returns () => void

      The unsubscriber function to turn off event modification.

      dynatrace.addEventModifier(function (event) {
      if (event["event.type"] !== "click") {
      return event;
      }
      return {
      ...event,
      "event_properties.prop": "value",
      "url.full": "www.dynatrace.com",
      "view.detected_name": "123456789",
      }
      });

      // Using context:
      dynatrace.addEventModifier(function (event, context) {
      if (event["event.type"] !== "click") {
      return event;
      }
      if (context?.additionalData) {
      return {
      ...event,
      "event_properties.extra_data": `received extra data: ${context.additionalData}`
      };
      }
      return event;
      });

      // Discarding an event:
      dynatrace.addEventModifier(function (event) {
      if (event["event.type"] === "click") {
      return null;
      }
      return event;
      });