How to set up Pay Station analytics in GTM
How it works
This instruction covers the basic integration of third-party web analytics into the Xsolla Pay Station payment flow and explains how to get valuable data from events and parameters.
How to get it
To integrate web analytics, perform the following Google Tag Manager (GTM) settings:
- Add script to the custom HTML tag.
- Define variables.
- Add triggers.
- Add tags.
- Publish changes.
If you change a component of the already integrated web analytics for the payment UI, you only need to publish changes to apply them. You don’t have to adjust the settings of the other components.
Example: If you add the custom HTML tag and the variables have been already defined, publish only the changes related to the tag. You don’t need to repeatedly set up other web analytics components.
Add script to the custom HTML tag
- Open your account in GTM and go to Tags.
- Click New.

- Click the Tag Configuration area.
- Choose the Custom HTML tag type from the list.

- In the HTML field, paste the following code.
event.origin
parameter to https://sandbox-secure.xsolla.com
.- js
<script>
window.onmessage = function payStationStatus(event) {
if (event.origin === "https://secure.xsolla.com") {
try {
var data = JSON.parse(event.data).data;
if (data.action === 'change-status') {
dataLayer.push({'event': 'status', 'changeStatus': true, 'status': data.value})
}
if (data.action === 'choose-method' && data.value) {
dataLayer.push({'event': 'choosePaymentMethod', 'choosePaymentMethod': true, 'paymentMethod': data.value})
}
if (data.action === 'click-btn-pay') {
dataLayer.push({'event': 'clickPayButton', 'clickPayButton': true})
}
if (data.action === 'close-widget') {
dataLayer.push({'event': 'closeWidget', 'closeWidget': true})
}
if (data.action === 'create-invoice') {
dataLayer.push({
'event': 'invoiceCreated',
'invoiceCreated': true,
'action': data.action,
'coupon_code': data.coupon_code,
'date': data.date,
'milliseconds': data.milliseconds,
'payment_country': data.payment_country,
'purchase_currency': data.purchase_currency,
'purchase_description': data.purchase_description,
'purchase_external_id': data.purchase_external_id,
'purchase_invoice_id': data.purchase_invoice_id,
'purchase_sku': data.purchase_sku,
'purchase_digital_content_sku': data.purchase_digital_content_sku,
'purchase_sum': data.purchase_sum,
'purchase_type': data.purchase_type,
'session_id': data.session_id,
'state': data.state,
'timezone': data.timezone,
'user_country': data.user_country,
'user_id': data.user_id,
'value': data.value,
'virtual_currency_amount': data.virtual_currency_amount
});
}
if (data.state) {
dataLayer.push({'event': 'changeState', 'changeState': true, 'state': data.state});
}
} catch (e) {
return;
}
}
};
</script>
- Click the Triggering area.
- Select a trigger with the Page View type firing on all pages.
- Click Save.

The saved HTML tag will be displayed in the Tags section. The script execution will be triggered by the payment UI opening.
Define variables
There are two sets of Data Layer variables you need to define, including:
- Events — used to create triggers and have predefined values.
- Parameters — used to feed information to an analytics system and can return any values.
How to add a variable:

Events
Event | Description |
---|---|
show-error-page | Opening a page with an error. An error code is passed in value parameter. |
open-{state_name} | Opening a page in the payment UI. |
create-invoice | Creating an invoice on Xsolla’s side. |
widget-close | Closing the payment UI. |
click-email-submit | Sending an email from the status page. |
click-custom-package-continue | Clicking the Continue button when buying an arbitrary amount of virtual currency. |
click-comment | Clicking the button to post a comment. |
click-buy-package | Clicking the Buy Package button when buying a package of virtual currency. |
click-buy-gift-package | Clicking the button when buying a package of virtual currency as a gift. |
click-buy-gift-custom-package | Clicking the button when buying an arbitrary amount of virtual currency as a gift. |
click-btn-share | Clicking the button to share via a social network. The social network name is passed in value . |
click-btn-pay | Clicking the Pay Now button on the billing data entry form. |
click-btn-continue | Clicking the button to buy the subscription. |
click-btn-apply | Clicking the Apply button when redeeming a coupon. |
click-btn-activate | Clicking the Activate button when activating a game key. |
click-btn-accept | Clicking the button to buy digital content. |
choose-payment-widget | Clicking on the payment method widget. The widget name is passed in value . |
choose-method | Selecting the payment method. The payment method name is passed in value . |
change-status | Changing the payment status. If the user closes the payment UI or leaves the page, and then the status changes, the event message is not sent. |
external-link-open | Redirection to an external resource. The address to which the redirection occurred is passed in the url parameter. |
dimensions | When Pay Station opens in the iframe, the width and height of the iframe are passed in the width and height parameters. |
status-redeem | The coupon redemption in a payment form. |
focus-change | Changing the focus on elements of the Pay Station widget. The focus state is passed in the hasFocus parameter and can be true or false . |
status | Going to the payment status page. The following parameters can be passed:
|
external-payment-open | Redirection from the payment UI to an external payment system or 3-D Secure verification. |
order-status | Changing the order status to done . The event is sent from the payment status page if an order was created via one of the following API calls: |
add_saved_account_error | Error occuring while saving a payment account. |
cancel_save_account | Cancellation of the saving of a payment account by a user. |
add_saved_account | Successful saving of a payment account. |
Parameters
Parameter | Type | Description |
---|---|---|
action | string | Event name. |
value | string | Additional parameter. Contains specific event parameters that vary depending on the user’s choice. |
state | string | The payment UI page, on which the action was performed. |
date | string | Date and time in the GMT format. |
milliseconds | number | Date and time in the Unix time format. |
timezone | string | User time zone. |
session_id | string | Session ID. The session includes all user actions performed within 30 minutes or until the payment UI is closed. The session starts from the moment when the payment UI is opened and is saved after the page with the payment UI is refreshed. |
payment_country | string | Payment country. |
purchase_invoice_id | number | Payment invoice ID in the Xsolla system. |
purchase_external_id | string | Payment invoice ID in the partner’s system. |
purchase_type | string | Purchase type. Can be: virtual item , virtual currency , pay2play , subscription . |
purchase_sum | number | Nominal purchase amount. |
purchase_currency | string | Purchase currency. |
purchase_sku | string | SKU of the purchased item. |
purchase_digital_content_sku | string | SKU of the purchased game keys package. |
purchase_description | string | Purchase description. |
virtual_currency_amount | number | Virtual currency amount. |
coupon_code | string | Coupon code. |
subscription_package_external_id | number | Subscription ID. |
subscription_package_name | string | Subscription name. |
subscription_package_description | string | Subscription description. |
total_sum | number | Total purchase amount. All fees are included. |
total_sum_currency | string | Total purchase amount currency. |
user_id | string | User ID (v1). |
user_country | string | User country. |
payment_instance_name | string | Payment method name. |
Add triggers
To add a trigger, you need one or more Data Layer variables listed under events.
EXAMPLE: We want to send information to Facebook after a user visited the payment status page.

Add tags
This step depends on the web analytics system you use. As an example, we’ll review Google Analytics.
EXAMPLE: A user goes to the status page. We want to transfer this event information, as well as the payment amount and currency, to Google Analytics (currency is a custom metric in our Google Analytics).

clickPayButton
— as any further event requires a user to keep the browser window open; it’s not always the case that transaction confirmation gets postMessage
initiation before a user closes the tab.Publish changes
- Go to Overview and click Submit.

- In the Publish and Create Version tab, indicate a version name, its description, and a publication environment.
- Click Publish.

Was this article helpful?
Rate this page
Don’t want to answer
Thank you for your feedback!
Found a typo or other text error? Select the text and press Ctrl+Enter.