JavaScriptTransformationSettingsBuilder

public class JavaScriptTransformationSettingsBuilder : TransformationSettingsBuilder

Builder for creating TransformationSettings that configure a JavaScript transformation.

The JavaScript Transformer executes user-provided JavaScript code against each dispatch payload using Apple’s JavaScriptCore engine. The following globals are available inside the JS code:

  • payload – mutable object representing the dispatch data; modifications are reflected in the result.
  • scope – string indicating the current DispatchScope (e.g. "aftercollectors").
  • track(...) – triggers a new SDK track call from within JS. Supported signatures:
    • track(event) – tracks an event with the given name.
    • track(event, payload) – tracks an event with additional data (2nd arg must be an object).
    • track(event, type) – tracks an event with a specific type string (e.g. "view").
    • track(event, type, payload) – tracks an event with type and additional data.
  • drop() – sets payload to undefined, causing the dispatch to be dropped.
  • dataLayer – read/write access to the persistent data layer (get, getAll, put, remove, clear).
  • console – logging bridge (debug, log, info, warn, error).
  • Expiry – constants for data expiry (forever, session, untilRestart).

Usage:

let settings = JavaScriptTransformationSettingsBuilder(id: "my-transform")
    .setJsCode("payload.custom_key = 'value'")
    .setScope(.afterCollectors)
    .build()
  • Creates a new builder for a JavaScript transformation.

    Declaration

    Swift

    public init(id: String)

    Parameters

    id

    Unique identifier for this transformation.

  • Sets the JavaScript code to execute against each dispatch payload.

    See the class-level documentation for the full list of available globals.

    Declaration

    Swift

    public func setJsCode(_ code: String) -> Self

    Parameters

    code

    A JavaScript code string.

    Return Value

    self for chaining.

  • Declaration

    Swift

    override public func build() -> DataObject