Setup

To start using the Vanilla JS SDK, you will need to add a setup script to your body. Ensure you have completed the Installation steps first (including the x-ogp-key meta tag).

document.addEventListener('DOMContentLoaded', () => {
  const sdk = new OpenGameSDK({
    ui: {
      usePointsWidget: true, // Enable the points widget (default: true)
      useCustomUI: false, // Set true to disable widget and modals
      theme: 'system', // 'light', 'dark', or 'system' (default: 'system')
    },
    // apiKey is automatically read from the <meta name="x-ogp-key"> tag.
    // You can also pass it explicitly here:
    // apiKey: 'your-api-key',
  });

  sdk.on('OnReady', () => {
    console.log('OpenGameSDK Ready');
    // Start your game here
  });

  sdk
    .init({ gameId: 'your-game-id' })
    .then(() => console.log('OpenGameSDK Initialized'))
    .catch(console.error);
});
circle-info

Your API key (creator key) is read from the <meta name="x-ogp-key"> tag in your HTML <head>. If the meta tag is present, you do not need to pass apiKey in the constructor. The gameId is passed to init(), or can be provided via the constructor or URL query params.

Last updated