JavaScript
1. Install the SDK Run the following command to install the SDK via npm:
2. (Alternate) Install through "script tag"
3. Initialize the SDK
Call the initialization functions at the start of your application:
4. Launch an Advertisement (Optional):
If you need to launch an ad at the start, check if ads are enabled and then request one:
if (await PortalSDK.isAdEnabled()) {
try {
await PortalSDK.requestAd();
} catch (ex) {
console.error(ex);
}
}
5. Setup game time tracking
You must add the code for tracking game time as shown here:
let timer;
const trackTimeEveryS = 20 // 20 seconds
function startGameTimeTrack() {
if (timer) clearInterval(timer)
window.PortalSDK.trackGameTimeTick()
timer = setInterval(() => {
window.PortalSDK.trackGameTimeTick()
}, trackTimeEveryS * 1000)
}
6. Call game-ready event
Call this method when the game is ready and visible to the user.
Notes:
Ensure you handle exceptions gracefully, especially when requesting ads.
Initialization should occur as early as possible in your application lifecycle to prevent delays.