Open-Measurement-SDKJS

OM SDK for Web Video and Iframes

OM SDK Service Script

The OM SDK Service Script must be same-origin relative to ad creative’s HTML (e.g. the <video> element) in order to measure it correctly. Additionally, it must also be loaded in a non-null origin.

This means that Service Script and the creative may be <iframe>‘d from the top window, but they must share the same non-null origin. The following configurations are acceptable:

The following configurations will not work:

OM SDK JS Session Client

The OM SDK JS Session Client has no restrictions on which origin or window it is loaded in.

However, if it is loaded in a window with a different origin from the window loading the Service Script, you must call an API present on the Service Script’s window object that allows the Service Script to accept communication from the JS Session Client. This API is located at window.omidSessionInterface.setSessionClientWindow.

If this API is not called, the integration will not work with version 1.4.9 and later of the Service Script.

An example implementation is provided below in which the Service Script is loaded in the top window and the JS Session Client is loaded in a cross-origin IFrame (more complicated setups, such as loading the Service Script in an iframe, may require a slightly different approach).

https://publisher.example/index.html (top window):

<html>
  <body>
    <script src="https://mycdn.example/omweb-v1.js"></script>
    <iframe id="session-client-frame" src="https://ads.example/frame.html"></iframe>
    <script src="https://mycdn.example/my-top-integration.js"></script>
  </body>
</html>

https://mycdn.example/my-top-integration.js:

const sessionClientFrame = document.getElementById('session-client-frame');
const sessionClientWindow = sessionClientFrame.contentWindow;
window.omidSessionInterface.setSessionClientWindow(sessionClientWindow);

https://ads.example/frame.html (IFrame):

<html>
  <body>
    <script src="httsp://mycdn.example/omid-session-client-v1.js"></script>
    <script src="https://mycdn.example/my-session-client-integration.js"></script>
  </body>
</html>

https://mycdn.example/my-session-client-integration.js:

const sessionClient = window.OmidSessionClient['default'];
const {AdSession, Context} = sessionClient;

const myServiceWindow = window.parent;
const context = new Context(...); // see main guide for more details
context.setServiceWindow(myServiceWindow);
const adSession = new AdSession(context);