Prerequisites
- You have a working Magic Checkout integration using the Razorpay JS SDK.
- Your analytics tool (GA4, Mixpanel and so on) is already initialised on the page before the checkout is opened.
How It Works
Magic Checkout communicates analytics events to your page via the Razorpay SDK instance:1
Step 1
You create a Razorpay instance with your checkout options.
2
Step 2
You register a listener on the
mx-analytics event before opening the checkout.3
Step 3
As the customer progresses through checkout, events fire through the
mx-analytics listener.4
Step 4
When payment succeeds, the
handler callback fires (not mx-analytics).Integration Steps
Follow these steps to integrate Magic Checkout analytics into your website.Step 1: Create the Razorpay Instance
Create a new Razorpay instance with your checkout options. Thehandler callback is where you capture successful payment events for your analytics.
New Razorpay Instance
Step 2: Register the Analytics Listener
Register themx-analytics listener on your Razorpay instance before you call rzpInstance.open(). This listener receives all checkout analytics events except payment success.
Register mx-analytics Listener
Payment Success (Purchase Event)
Payment success is not delivered via themx-analytics listener. It is delivered through the handler callback defined in your checkoutOptions.
The handler is called immediately after a successful payment with the following payload:
razorpay_payment_id
: string Unique identifier of the successful payment (for example, "pay_XXXXXXXXXXXXXXXXX").
razorpay_order_id
: string The order id associated with this payment. Always present for Magic Checkout since an order is required.
razorpay_signature
: string HMAC-SHA256 signature for server-side payment verification. Always present for Magic Checkout.
Handler
Full Integration Example
Example
Forward Events to Your Analytics Platform
Themx-analytics listener delivers raw event data to your page. It is your responsibility to forward this data to your analytics platform of choice, using whatever event names and payload structure that platform expects.
Below is an example of how you might forward Magic Checkout events to Google Analytics 4 (GA4). This is illustrative only; the event names and parameters shown are one possible mapping. Adapt them to match your own platform and tracking requirements.
Example GA4 Integration
Handy TipsThe event names (
begin_checkout, add_payment_info and so on) above are GA4’s recommended e-commerce event names. Your platform may use different conventions; refer to your analytics provider’s documentation for the correct event taxonomy. This example covers only a subset of events; refer to the Event Reference for the complete list.