Explore Metaframe methods and events

window.metaframe object

Once the script is loaded, the metaframe object is available in the global window object of your application. The metaframe object contains a list of methods needed to manage the Metaframe in your web application.

window.metaframe.create method

Method signature:

Copy
Full screen
Small screen
    window.metaframe.create: (parameters: {
     loginProjectId: string,
     merchantId?: number,
     projectId?: number,
     orbsApiHostId?: string,
     isMobile?: boolean,
    
    }) => void;
    

    Initializes Metaframe in your web application. The method accepts the parameters object with the following parameters needed to run Metaframe:

    ParameterTypeDescription
    loginProjectId
    stringLogin ID. To get it, open Publisher Account, and go to the Login > Dashboard > your Login project section. Required.
    merchantId
    stringMerchant ID. You can find this parameter in your Publisher Account:
    • in the Company settings > Company section.
    • in the URL in the browser address bar on any Publisher Account page. The URL has the following format: https:​//publisher.xsolla.com/<merchant ID>/<Publisher Account section>.
    Required, if the Virtual currencies or Backpack function is enabled in the project settings in the Publisher Account.
    projectID
    stringProject ID. You can find this parameter in your Publisher Account next to the name of the project.
    Required, if the Backpack function is enabled in the project settings in the Publisher Account.
    orbsApiHostId
    stringHost ID. To get it, contact the integration team at integration@xsolla.com or your Customer Success Manager at csm@xsolla.com and pass the project ID and merchant ID.
    Required, if the Virtual currencies function is enabled in the project settings in the Publisher Account.
    isMobile
    booleanWhether Metaframe uses mobile layout by default.
    Note
    The widget location in the mobile version can be configured in the Publisher Account. Detailed information is provided in the Setting up mobile version section.

    window.metaframe.setIsMobile method

    Method signature:

    Copy
    Full screen
    Small screen
      window.metaframe.setIsMobile(isMobile: boolean)
      

      Switches Metaframe from desktop to mobile version or vice versa.

      ParameterTypeDescription
      isMobile
      booleanWhether to switch Metaframe to the mobile version. If set to true, Metaframe switches to the mobile version. If set to false, Metaframe switches to the desktop version.
      Note
      The widget location in the mobile version can be configured in the Publisher Account. Detailed information is provided in the Setting up mobile version section.

      window.metaframe.partnerActions object

      The object contains methods to trigger actions in the Metaframe.

      Before using the methods of this object, you must ensure that the Metaframe is fully loaded. To do this, subscribe to the Metaframe load event. If the event has been processed, the object’s methods are available.

      Example of setting a listener to the Metaframe load event:

      Copy
      Full screen
      Small screen
      window.addEventListener("@metaframe-partner-events:app-loaded", () => {
      
       //Here you can use partner actions
      
      });
      

      window.metaframe.partnerActions.openBackpackItemPage method

      Method signature:

      Copy
      Full screen
      Small screen
        window.metaframe.partnerActions.openBackpackItemPage(itemId: string)
        

        Opens the page for the specified item in the Backpack section.

        For the method to work correctly, the following conditions must be met:

        • The Backpack function is enabled in the Publisher Account.
        • The user is authenticated in to Metaframe.

        ParameterTypeDescription
        itemId
        stringInternal ID of the item that is passed when calling the API method to create the item.

        Tracking events

        You can subscribe to the following Metaframe events:

        ParameterType
        @metaframe-partner-events:app-loadedThe event is triggered when the Metaframe is successfully loaded after the window.metaframe.create method is called.
        @metaframe-partner-events:login-successfulThis event is triggered when the user successfully logs into the Metaframe. It contains a detail object with the user’s authorization token.
        @metaframe-partner-events:logout-successfulThe event is triggered when a user successfully logs out of the system.
        @metaframe:custom-action:<ACTION_ID>The event is triggered when a user selects a custom section of type Action in the Metaframe. For more information, see Tracking custom sections’ events.

        Tracking custom sections’ events

        You can add a custom section to the Metaframe with the Action type. This section appears as a button that, performs an action when clicked, such as opening a website.

        To track the event of clicking a custom section, you need to subscribe to the @metaframe:custom-action:<ACTION_ID> event, where <ACTION_ID> is the action ID generated in Publisher Account when setting up the custom section.

        Example of setting a listener for a custom section click event:

        Copy
        Full screen
        Small screen
        document.addEventListener("@metaframe:custom-action:00000000-0000-0000-0000-000000000000", () => {
        
         // Your code here...
        
        })
        
        Was this article helpful?
        Thank you!
        Is there anything we can improve? Message
        We’re sorry to hear that
        Please explain why this article wasn’t helpful to you. Message
        Thank you for your feedback!
        We’ll review your message and use it to help us improve your experience.
        Last updated: November 1, 2024

        Found a typo or other text error? Select the text and press Ctrl+Enter.

        Report a problem
        We always review our content. Your feedback helps us improve it.
        Provide an email so we can follow up
        Thank you for your feedback!