playgen.io

Documentation

Access control

Gating Features

Implementing Gated Features with playgen.io

playgen.io offers a robust access control mechanism for features like leaderboards, archives, and stats. When a feature is set as gated, players attempting to access it will trigger a request event instead of directly opening the screen. This allows you to manage access by requiring authentication, subscription, or other conditions before the feature is unlocked.

How Access Control Works

  1. Gating a Feature:

    • In your playgen.io dashboard, you can configure features like Leaderboard, Archive, or Stats to be gated. Once enabled, access to these features will be restricted.
  2. Request Event Triggered:

    • When a player tries to access a gated feature, a request event is sent from the game. For example, if the leaderboard is gated, the game will send a PLAYGEN_REQUEST_LEADERBOARD event instead of opening the leaderboard screen.
  3. Listening for Request Events:

    • Your app needs to listen for these request events to handle the access control logic. You can capture these events using an event listener. Here’s an example:
    window.addEventListener("message", (event) => {
      const { type } = event.data;
     
      if (
        type === "PLAYGEN_REQUEST_LEADERBOARD" ||
        type === "PLAYGEN_REQUEST_ARCHIVE"
      ) {
        // Custom logic to handle gated access
        handleAccessRequest(type);
      }
    });
  4. Responding with PLAYGEN_RESOLVER Event:

    • After detecting a request event, you must send a PLAYGEN_RESOLVER event back to the game iframe to grant or deny access. This event includes parameters indicating whether the feature is unlocked. Here’s an example of sending the PLAYGEN_RESOLVER event:
    function sendAccessResponse(eventName, grantAccess) {
      const event = {
        event_name: "PLAYGEN_RESOLVER",
        resolver_type: eventName,
        resolved: grantAccess,
      };
     
      iframeRef.current?.contentWindow?.postMessage(event, "*");
    }
     
    // Example usage
    sendAccessResponse("leaderboard", true); // Grant access to leaderboard
  5. Debugging in the Playground:

    • The Playground in the game editor is an excellent tool to test and visualize these events. You can use it to monitor request and resolver events in real-time, ensuring your access control logic works correctly.

Use Cases for Access Control

Access control can be utilized to implement various features that enhance user engagement and revenue generation:

  • Loginwall Integration: Require users to log in before accessing certain features, enhancing data collection and user retention.
  • Paywall Integration: Implement a subscription model where users need to pay to access premium features like archives or detailed stats.
  • Lead Generation: Prompt users to fill out a form or provide contact information before accessing restricted features, allowing you to capture leads.
  • Ad-Supported Access: Offer access to premium features in exchange for watching an ad, providing an alternative revenue stream.

By leveraging playgen.io’s access control features, you can customize the player experience, drive engagement, and generate additional revenue streams based on user interactions.

On this page