JavaScript Transformation

  • 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()
    
    See more

    Declaration

    Swift

    public class JavaScriptTransformationSettingsBuilder : TransformationSettingsBuilder