Amwal Tech logoDocs

Google Analytics (GA4) Integration

Track user interactions with Amwal checkout buttons, monitor payment funnel conversion, and analyze installment performance in Google Analytics 4 (GA4) and Google Tag Manager (GTM).


1. Include Google Tag Manager / GA4 Script

Include the standard GA4 tag snippet in the <head> section of your storefront:

<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'G-XXXXXXXXXX');
</script>

2. Dynamic Event Listener (MutationObserver)

Because Amwal checkout buttons and widgets may be rendered dynamically by JavaScript frameworks or e-commerce themes, use a MutationObserver to ensure event listeners are attached reliably:

<script>
document.addEventListener('DOMContentLoaded', () => {
  function addAmwalCheckoutListeners() {
    document.querySelectorAll('.amwal-checkout-button, amwal-checkout-button').forEach((button) => {
      if (!button.dataset.gaListenerAttached) {
        button.addEventListener('click', () => {
          // Send custom event to Google Analytics 4
          gtag('event', 'amwal_checkout_click', {
            event_category: 'E-commerce Checkout',
            event_label: 'Amwal Bank Installments',
            value: button.getAttribute('amount') || 1,
            currency: button.getAttribute('currency') || 'SAR',
          });
        });
        button.dataset.gaListenerAttached = 'true';
      }
    });
  }

  // Observe DOM for dynamically loaded components
  const observer = new MutationObserver(addAmwalCheckoutListeners);
  observer.observe(document.body, { childList: true, subtree: true });

  // Initial check
  addAmwalCheckoutListeners();
});
</script>

Trigger PointGA4 Event NameParameters Tracked
Widget Viewview_promotionpromotion_id: "amwal_0_percent", items: [...]
Installment Clickselect_promotionpromotion_name: "Amwal Bank Installments"
Begin Checkoutbegin_checkoutcurrency: "SAR", value: 1200.00
Successful Paymentpurchasetransaction_id, value, payment_type: "installments"

4. Google Analytics Real-Time Dashboard

Once events are fired, verify tracking in Google Analytics → Reports → Realtime → Event Count by Event Name:

Google Analytics Realtime Event Tracking Dashboard

On this page