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,
isCollapsed?: boolean,
layoutSettings?: {
desktop: {
widgetMarginTop?: number,
},
mobile: {
widgetMarginTop?: number,
},
},
}) => void;
Initializes Metaframe in your web application.
Parameter | Type | Description |
---|---|---|
parameters | object | Object with parameters for launching Metaframe. |
parameters.loginProjectId | string | Login ID. To get it, open Publisher Account, and go to the Login > Dashboard > your Login project section. Required. |
parameters.merchantId | string | Merchant ID. You can find this parameter in your Publisher Account:
|
parameters.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. |
parameters.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. |
parameters.isMobile | boolean | Whether Metaframe uses mobile layout by default. |
parameters.isCollapsed | boolean | Whether the widget is displayed collapsed (minimized) by default. The default value is true . |
parameters.layoutSettings | object | Object with parameters for customizing the widget layout. |
parameters.layoutSettings.desktop | object | Object with parameters for customizing the layout of the desktop version of the widget. Required. |
parameters.layoutSettings.desktop.widgetMarginTop | number | Top margin for the Metaframe widget relative to the viewport (in px). The default value is 16 . |
parameters.parameters.layoutSettings.mobile | object | Object with parameters for customizing the layout of the mobile version of the widget. Required. |
parameters.layoutSettings.mobile.widgetMarginTop | number | Top margin for the Metaframe widget relative to the viewport (in px). The default value is 72 . |
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:
openBackpackItemPage: (itemId: string) => void;
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. |
window.metaframe.partnerActions.openLogin method
Method signature:
openLogin: () => void;
Opens the user authorization form. If the user is already authorized, an error is displayed in the browser console.
window.metaframe.partnerActions.openProfile method
Method signature:
openProfile: () => void;
Opens the
window.metaframe.partnerActions.openWallet methods
Method signature:
openWallet: () => void;
Opens the
window.metaframe.partnerActions.openBackpack method
Method signature:
openBackpack: () => void;
Opens the
- The Backpack function is enabled in the Publisher Account.
- The user is authenticated in to Metaframe.
window.metaframe.partnerActions.openCustomMiniApp method
Method signature:
openCustomMiniApp: (params: {miniAppName: string}) => void;
Opens the specified custom section with the Iframe type if one of the following conditions is met:
- If the Show this app before user login toggle in the settings of the specified custom section is active, and the current user is not authorized.
- If the Show this app after user login toggle in the settings of the specified user section is active, and the current user is authorized.
If the conditions are not met, an error is displayed in the browser console.
Parameter | Type | Description |
---|---|---|
params | object | Object with parameters. |
params.miniAppName | string | App name specified in the settings of the custom section with the Iframe type. Required. |
window.metaframe.partnerActions.pushNotification methods
Method signature:
pushNotification: (params: {
type: string; // use “success”, “warning”, “error” or “info”
text: string;
button?: {
text: string;
onClick: () => void;
};
durationInMs?: number;
}) => void;
Pushes a new notification to the notification stack.
Parameter | Type | Description |
---|---|---|
params | object | Object with parameters. |
paramps.type | string | Notification type. Possible values: “success” , “warning” , “error” , “info” . Required. |
paramps.text | string | Notification text. Required. |
params.button.text | string | Button copy. Required. |
params.button.onClick | () => void | Function that is called when the button is clicked. Required. |
params.durationInMs | number | Duration of the notification display on the screen in milliseconds. |
window.metaframe.partnerActions.setIsCustomMiniAppVisible method
Method signature:
setIsCustomMiniAppVisible: (params: {
miniAppName: string;
isVisible: boolean;
}) => void;
Shows or hides the specified custom section.
Parameter | Type | Description |
---|---|---|
params | object | Object with parameters. |
params.miniAppName | string | App name specified in the settings of the custom section. Required. |
params.isVisible | boolean | Whether to display the specified custom section in the widget. Required. |
Widget 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:not-authorized-mini-apps-loaded | The event is triggered when the Metaframe successfully loads custom sections in the settings of which the Show this app before user login toggle is active. |
@metaframe-partner-events:authorized-mini-apps-loaded | The event is triggered when the Metaframe successfully loads all configured widget sections, including custom sections in the settings of which the Show this app after user login toggle is active. |
@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-partner-events:mini-app-menu-button-clicked:<YOUR_MINI_APP_NAME> | The event is triggered when a user clicks on Metaframe custom section. |
@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 to Metaframe a custom section 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.