Skip to main content

Event-based integration

The event-based integration allows you to retrieve loaded placements and listen to the events that they emit.

The Rokt object exposes a method called rokt.getPlacements() that returns a promise that resolves with the placements after they have finished loading.

Each placement exposes a placement.on(EVENT_NAME) method that allows you to subscribe to events emitted by that placement.

rokt.onLoaded(function (rokt) {  rokt.getPlacements().then(function (placements) {    // Return the placement with a corresponding placementId    const placement = placements.find(function (p) {      return p.getAlias() === placementId;    });
    // Listen for when the placement becomes interactive/ready to display    placement.on("PLACEMENT_INTERACTIVE").subscribe(function () {      // Logic to run after Placement has become interactive    });
    // Listen for when the placement iframe resizes    placement.on("PLACEMENT_RESIZE").subscribe(function () {      // Logic to run after Placement resizes    });
    // Listen for when the placement encounters an unrecoverable failure before closing    placement.on("PLACEMENT_FAILURE").subscribe(function () {      // Logic to run after Placement has encountered a failure    });  });
  // Integration steps as per other examples});
Was this article helpful?