我正在尝试使用 Google Analytics 4 来跟踪 Stripe 的付款错误。
我正在使用 Drupal 8;这是相关的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);
}
该gtag()
函数取自Google 开发人员文档,用于在 GA4 中推送异常。
我在 Analytics 中打开了调试模式,转到结帐页面,然后输入了无效的到期日期。
在 Chrome 开发控制台中,我可以看到记录了异常:
Processing GTAG command: ["event", "exception", {description: "Your card has expired.", fatal: false}]
但是,该异常实际上并未登录到 Analytics。我还需要做什么才能记录异常?