|
↳ See all 53 articles
/ Documentation /Integrations/ How to Send SureDonation Events to Google Analytics 4 via Google Tag Manager

How to Send SureDonation Events to Google Analytics 4 via Google Tag Manager

This guide shows how to track SureDonation form views and completed donations in Google Analytics 4 (GA4) using Google Tag Manager (GTM). When it is set up, every donation form view and every completed donation reaches GA4 as an event, along with the form ID, campaign ID, donation amount, and currency.

Overview

The setup has three parts:

  1. A small script in GTM that listens for SureDonation activity on the page and pushes it to the GTM dataLayer.
  2. GTM tags and a trigger that send those dataLayer entries to GA4.
  3. Your GA4 property, where the events appear in Realtime, DebugView, and the Events report.

Prerequisites

  • A WordPress site with SureDonation installed and at least one donation form published on a page.
  • A Google Tag Manager container installed on the site (the GTM snippet in the site’s <head> and <body>, added with a plugin such as Site Kit or GTM4WP, or by your theme).
  • A GA4 property and its Measurement ID (it starts with G-). Find it in GA4 under Admin → Data streams → your web stream.

Step 1: Add the SureDonation data push script

This script is added to GTM as a Custom HTML tag. It pushes a SureDonationActivities event to the dataLayer for each form view (DonationFormView) and each completed donation (DonationCompleted).

  • In GTM, open Tags and click New (Add tag in an empty container).
  • Name the tag cHTML – SureDonation Data Push.
  • Click Tag Configuration and choose Custom → Custom HTML at the bottom of the list.
  • Paste the script below into the HTML box.
  • Under Triggering, choose DOM Ready. If it does not exist, click +, choose the trigger type DOM Ready (All DOM Ready Events), name it DOM Ready and save it.
  • Click Save.
<script>
( function () {
  window.dataLayer = window.dataLayer || [];
  function push( action, container, extra ) {
    var data = {
      event: 'SureDonationActivities',
      eventCategory: 'SureDonation',
      eventAction: action,
      SureDonationFormID: container ? container.getAttribute( 'data-form-id' ) || '' : '',
      SureDonationCampaignID: container ? container.getAttribute( 'data-campaign-id' ) || '' : ''
    };
    for ( var key in extra ) {
      data[ key ] = extra[ key ];
    }
    window.dataLayer.push( data );
  }
  function donation( container ) {
    var amount = container.querySelector( '.sd-input-donation-amount-hidden' );
    var payment = container.querySelector( '[data-currency]' );
    return {
      SureDonationAmount: amount ? parseFloat( amount.value ) || 0 : 0,
      SureDonationCurrency: ( container.getAttribute( 'data-gtm-currency' ) ||
        ( payment ? payment.getAttribute( 'data-currency' ) : '' ) ).toUpperCase()
    };
  }
  
// DonationFormView: every SureDonation form on the page.
  var forms = document.querySelectorAll( '.sd-form-container' );
  for ( var i = 0; i < forms.length; i++ ) {
    push( 'DonationFormView', forms[ i ] );
  }

// Remember the currency a donor picks in the currency switcher (SureDonation Pro).
  document.addEventListener( 'sd-currency-changed', function ( e ) {
    var container = e.target.closest && e.target.closest( '.sd-form-container' );
    if ( container && e.detail && e.detail.currency ) {
      container.setAttribute( 'data-gtm-currency', e.detail.currency );
    }
  } );

// DonationCompleted: SureDonation shows its confirmation box after a successful donation.
  new MutationObserver( function ( mutations ) {
    mutations.forEach( function ( m ) {
      var box = m.target;
      if ( box.classList && box.classList.contains( 'sd-success-box' ) &&
        box.classList.contains( 'sd-active' ) && ! box.getAttribute( 'data-gtm-sent' ) ) {
        box.setAttribute( 'data-gtm-sent', '1' );
        var container = box.closest( '.sd-form-container' );
        push( 'DonationCompleted', container, container ? donation( container ) : {} );
      }
    } );
  } ).observe( document.body, { attributes: true, attributeFilter: [ 'class' ], subtree: true } );

// DonationCompleted after a Stripe authentication redirect (for example 3D Secure).
  var params = new URLSearchParams( window.location.search );
  if ( params.get( 'suredonation_payment' ) === 'success' && params.get( 'redirect_status' ) === 'succeeded' ) {
    push( 'DonationCompleted', forms[ 0 ] || null, {} );
  }
} )();
</script>

Step 2: Google Tag Manager Configuration

Create one trigger, five variables, and two more tags. Triggers and Variables are under Show more in GTM’s left sidebar.

2.1 Trigger

Go to Triggers → New, name it SureDonationActivitiesEvent, choose the type Custom Event, enter the event name SureDonationActivities, keep All Custom Events and click Save.

2.2 Data Layer Variables

Go to Variables, click New under User-Defined Variables, choose Data Layer Variable, and create one variable for each row below.

Variable nameData Layer Variable Name
DLV – SureDonation Event ActioneventAction
DLV – SureDonation Form IDSureDonationFormID
DLV – SureDonation Campaign IDSureDonationCampaignID
DLV – SureDonation AmountSureDonationAmount
DLV – SureDonation CurrencySureDonationCurrency

2.3 Google Tag

Go to Tags → New, name it SureDonation – GA4, choose Google Tag (under Other Google) and enter your Measurement ID in the Tag ID field. Keep the trigger Initialization – All Pages and click Save.

2.4 GA4 Event tag

Go to Tags → New, name it SureDonation – GA4 Event, choose Google Analytics → Google Analytics: GA4 Event, enter the same Measurement ID, and set Event Name to {{DLV – SureDonation Event Action}}. Under Event Parameters, add the rows below. Set the trigger to SureDonationActivitiesEvent and click Save.

Event ParameterValue
event_action{{DLV – SureDonation Event Action}}
donation_form_id{{DLV – SureDonation Form ID}}
campaign_id{{DLV – SureDonation Campaign ID}}
value{{DLV – SureDonation Amount}}
currency{{DLV – SureDonation Currency}}

Summary of what you created

ItemTypeTrigger / setting
cHTML – SureDonation Data PushCustom HTML tagDOM Ready
SureDonation – GA4Google TagInitialization – All Pages
SureDonation – GA4 EventGA4 Event tagSureDonationActivitiesEvent
SureDonationActivitiesEventCustom Event triggerEvent name: SureDonationActivities

Step 3: Verifying Tags with GTM Preview

In GTM, click Preview, enter the URL of a page with a donation form, and click Connect. Your site opens in a new tab; keep the Tag Assistant tab open while testing.

When the page loads, Tag Assistant should show cHTML – SureDonation Data Push and SureDonation – GA4 fired once, and SureDonation – GA4 Event fired for DonationFormView. Make a test donation with the payment gateway in Test Mode (for Stripe, card 4242 4242 4242 4242, any future date, any CVC). When the confirmation message appears, SureDonation – GA4 Event fires again for DonationCompleted.

Open the Variables tab for that event to check the form ID, campaign ID, amount and currency.

Step 4: Viewing SureDonation Data in GA4

  1. Realtime (Reports → Realtime overview): events appear within seconds.
  1. DebugView (Admin → Data display → DebugView): a second-by-second timeline while GTM Preview is connected. Click an event to see its parameters.
  1. Engagement Reports (Reports → Engagement → Events): available after 24–48 hours.

Troubleshooting

  • No data at all, not even page views: the SureDonation – GA4 Google Tag must fire on Initialization – All Pages, not on the SureDonation trigger. If it only fires on the custom event, GA4 is never initialized on normal page loads.
  • DonationCompleted does not fire on forms that redirect: if the form’s confirmation type is Redirect, the donor leaves the page before the confirmation appears. Track the donation with a Page View trigger on your thank-you page instead.
  • Lower event counts than expected: ad blockers, consent banners, and throttling on staging or preview hosts can stop some events.
  • Events in Realtime but not in reports: Realtime and DebugView are near-instant; standard reports take up to 48 hours.

Summary

With the data push script in place, the three GTM tags configured, and the GA4 Google Tag firing on Initialization – All Pages, SureDonation form views and completed donations flow into GA4 as DonationFormView and DonationCompleted events.

Was this doc helpful?
What went wrong?

We don't respond to the article feedback, we use it to improve our support content.

Need help? Contact Support
Table of Contents
Scroll to Top