SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX -
SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX - SANDBOX -
× #message#
×

Warning

API Manual

Statistics tools

The purpose of these tools is to collect statistical data about payments, which allows merchants to identify possible bottlenecks in the flow of the payment and to optimize the payment flow so that consumers are not confused by it.

Basic data about payment progress is collected client-side using JavaScript and passed server-side through HTTP requests.

Note that all functions reside in a separate namespace to avoid possible conflicts with existing JavaScript functions. Because of this all calls should be prefixed with CryptoPaymentStats.

Installation Step 1: Including JS

To start collecting statistical data about payments, a JavaScript file needs to be loaded by including this line on the payment site HTML:

<script type="text/javascript" src="https://sandbox.forumpay.com/api/events/payment.js"></script>

Installation Step 2: Setting authentication token

To make sure that the statistical data is correctly tied to each payment, a token must be set using setToken().

<script type="text/javascript">
CryptoPaymentStats.setToken(stats_token);
</script>

The token should be taken from the StartPayment API call response (stats_token).

Token must be set ideally before the first on...() call is made. If the token is not set within 10 seconds of the first communication attempt, an error will be logged to console. However, the events will still be sent if the token is set later.

Function reference

Function Explanation
setToken(token) Sets the authentication token which allows other function calls to send information to server. The token must be taken from StartPayment API call response field stats_token.
onAddressCopy() Should be called whenever payment target crypto address is copied to the clipboard by the consumer.
onAmountCopy() Should be called whenever payment amount is copied to the clipboard by the consumer.
onQRCodeInit() Should be called when consumer requests the QR code to be displayed to them (on click,...).
onQRCodeLoad(success) Should be called when the QR code image is loaded (on load, on error).
onQRAltCodeInit() Should be called when consumer requests the alternative QR code to be displayed to them (on click,...).
onQRAltCodeLoad(success) Should be called when the alternative QR code image is loaded (on load, on error).
beforeClose() Should be called before widget is closed by the consumer. If it is not possible to detect the closing event, call this function periodically (every few seconds) while the widget is still opened.

onAddressCopy

This function should be called whenever JS detects that the crypto address was copied to clipboard.

Example:

<div oncopy="CryptoPaymentStats.onAddressCopy();">38wGZr2xLgbHWsYrsNCER1C9mZkNHwyd69</div>

onAmountCopy

This function should be called whenever JS detects that the amount of crypto was copied to clipboard.

Example:

<div oncopy="CryptoPaymentStats.onAmountCopy();">0.00701648 BTC</div>

onQRCodeInit / onQRCodeLoad / onQRAltCodeInit / onQRAltCodeLoad

These functions collect information about which QR code was displayed, how long the loading took and if it was successful. Note that onQRCodeInit() / onQRAltCodeInit() function calls signal the intent of the user to see the appropriate QR code. In other words, it is possible to call onQRCodeLoad() before onQRCodeInit()

Example:

<script>
CryptoPaymentStats.onQRCodeInit();
</script>

<img id="qr" src="https://api.forumpay.com/pay/qr/?d=bitcoin%3A38wGZr2xLgbHWsYrsNCER1C9mZkNHwyd69%3Famount%3D0.00001"
onload="CryptoPaymentStats.onQRCodeLoad(true);" onerror="CryptoPaymentStats.onQRCodeLoad(false);">
<img id="qralt" src="https://api.forumpay.com/pay/qr/?d=bitcoin%3A38wGZr2xLgbHWsYrsNCER1C9mZkNHwyd69"
onload="CryptoPaymentStats.onQRAltCodeLoad(true);" onerror="CryptoPaymentStats.onQRAltCodeLoad(false);" style="display: hidden;">

<button onclick="CryptoPaymentStats.onQRAltCodeInit(); $('#qr').hide(); $('#qralt').show(); ">show alternative QR code</button>

×