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:
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:
Parameter | Type | Description |
---|---|---|
loginProjectId | string | Login ID. To get it, open Publisher Account, and go to the Login > Dashboard > your Login project section. Required. |
merchantId | string | Merchant ID. You can find this parameter in your Publisher Account:
|
projectID | string | Project 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 | string | Host 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 | boolean | Whether Metaframe uses mobile layout by default. |
window.metaframe.setIsMobile method
Method signature:
window.metaframe.setIsMobile(isMobile: boolean)
Switches Metaframe from desktop to mobile version or vice versa.
Parameter | Type | Description |
---|---|---|
isMobile | boolean | Whether 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. |
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:
- javascript
window.addEventListener("@metaframe-partner-events:app-loaded", () => {
//Here you can use partner actions
});
window.metaframe.partnerActions.openBackpackItemPage method
Method signature:
window.metaframe.partnerActions.openBackpackItemPage(itemId: string)
Opens the page for the specified item in the
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.
Parameter | Type | Description |
---|---|---|
itemId | string | Internal 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:
Parameter | Type |
---|---|
@metaframe-partner-events:app-loaded | The event is triggered when the Metaframe is successfully loaded after the window.metaframe.create method is called. |
@metaframe-partner-events:login-successful | This 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-successful | The 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:
- javascript
document.addEventListener("@metaframe:custom-action:00000000-0000-0000-0000-000000000000", () => {
// Your code here...
})
Found a typo or other text error? Select the text and press Ctrl+Enter.