Skip to main content

Rokt

Rokt's Universal Module Definition (UMD) bundle is exposed in the window object and becomes available after loading Rokt's solution into the page.

Overview

After loading Rokt's script into the page, the Rokt UMD bundle will be available on the window object as window.Rokt. The Rokt property can be interacted with once the script finishes loading which may require additional handling if the script is loaded asynchronously.

Synchronous Loading Example

<script
crossorigin="anonymous"
src="https://apps.rokt.com/wsdk/integrations/launcher.js"
></script>
const launcher = await window.Rokt.createLauncher({
accountId: "roktAccountId",
});

Please note the following important parameters in the arguments list above:

  • https://apps.rokt.com/wsdk/integrations/launcher.js — is the URL pointing to the latest version of the Rokt Launcher.
  • roktAccountId — is your unique Rokt Account ID and should be replaced with the correct value. See Where can I find my Rokt Account ID? if you do not know your account id.

Asynchronous Loading Example

<script
async
crossorigin="anonymous"
id="rokt-launcher"
fetchpriority="high"
src="https://apps.rokt.com/wsdk/integrations/launcher.js"
type="module"
></script>
await new Promise((resolve) =>
window.Rokt
? resolve()
: (document.getElementById("rokt-launcher").onload = resolve)
);

const launcher = await window.Rokt.createLauncher({
accountId: "roktAccountId",
});

Please note the additional attributes present on the script tag:

  • async - enables asynchronous loading of the script
  • id="rokt-launcher" - id of the script element. It must match id passed to document.getElementById('rokt-launcher').
  • type="module" - increases priority of the loaded resource. See Best Practices for more details.

Furthermore, obtaining the Rokt UMD bundle needs to be wrapped in a Promise (as in example) to ensure the code executes only after the asynchronously loaded Rokt script is available.

Methods

createLauncher

createLauncher: (options: IntegrationLauncherOptions): Promise<IntegrationLauncher>

Creates an instance of the IntegrationLauncher which is an entry point for the integrating with Rokt. It is up to the integrator to keep the reference to the created object.

At the same time only a single instance can exist. Trying to create another one will result in an error unless the previous one is terminated.

Parameters:

NameTypeDescription
optionsIntegrationLauncherOptionsOptions to customize the integration

Returns: IntegrationLauncher

Was this article helpful?