I'm trying to use Google Analytics 4 to track payment errors with Stripe.
I'm using Drupal 8; here is the relevant JS:
// Helper to handle the Stripe responses with errors.
var stripeErrorHandler = function (result) {
if (result.error) {
// Inform the user if there was an error.
// Display the message error in the payment form.
Drupal.commerceStripe.displayError(result.error.message);
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('event', 'exception', {
'description': result.error.message,
'fatal': false
});
// Allow the customer to re-submit the form.
$form.find(':input.button--primary').prop('disabled', false);
}
The gtag() function is taken from the Google developer documentation for pushing exceptions in GA4.
I turned on debug mode in Analytics, went to the checkout page, and input an invalid expiration date.
In the Chrome dev console, I can see that the exception is logged:
Processing GTAG command: ["event", "exception", {description: "Your card has expired.", fatal: false}]
However, the exception does not actually get logged in Analytics. What more do I need to do to get the exception logged?