Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Chọn nền tảng của bạn:
Measurement Protocol của Google Analytics không trả về mã lỗi HTTP, ngay cả khi một sự kiện bị sai định dạng hoặc thiếu các tham số bắt buộc. Để đảm bảo các sự kiện của bạn hợp lệ, bạn nên thử nghiệm sự kiện với máy chủ xác thực Measurement Protocol trước khi đưa vào sử dụng chính thức.
Sau khi xác thực rằng các sự kiện của bạn được cấu trúc đúng cách, bạn nên xác minh việc triển khai để đảm bảo bạn đang sử dụng đúng khoá.
Bạn có thể gọi trực tiếp máy chủ xác thực hoặc sử dụng Trình tạo sự kiện Google Analytics. Trình tạo sự kiện của Google Analytics cho phép bạn tương tác để tạo sự kiện và sử dụng máy chủ xác thực Measurement Protocol để xác thực các sự kiện đó.
Hướng dẫn này mô tả cách gửi sự kiện đến Measurement Protocol cho máy chủ xác thực Google Analytics 4 và diễn giải phản hồi.
Gửi sự kiện để xác thực
Điểm khác biệt duy nhất trong yêu cầu đối với các sự kiện được gửi đến Measurement Protocol và máy chủ xác thực Measurement Protocol là URL.
Máy chủ
URL
Measurement Protocol
/mp/collect
Máy chủ xác thực Measurement Protocol
/debug/mp/collect
Tất cả các trường yêu cầu khác đều giống nhau. Hãy xem tài liệu tham khảo về giao thức để biết đầy đủ thông tin chi tiết về cách tạo một yêu cầu hợp lệ.
Đoạn mã sau đây cho thấy một sự kiện không hợp lệ đang được gửi đến máy chủ xác thực Measurement Protocol:
Phản hồi xác thực
Sau đây là phản hồi của máy chủ xác thực đối với sự kiện trước đó:
{"validationMessages":[{"fieldPath":"events","description":"Event at index: [0] has invalid name [_badEventName]. Names must start with an alphabetic character.","validationCode":"NAME_INVALID"}]}
Sau đây là phản hồi của máy chủ xác thực đối với một yêu cầu không có vấn đề xác thực:
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-26 UTC."],[[["\u003cp\u003eThe Measurement Protocol Validation Server helps ensure your Google Analytics 4 events are correctly formatted before deploying to production.\u003c/p\u003e\n"],["\u003cp\u003eThe Validation Server uses a different URL endpoint (\u003ccode\u003e/debug/mp/collect\u003c/code\u003e) than the standard Measurement Protocol (\u003ccode\u003e/mp/collect\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eValidation responses provide detailed error messages including the field path, description, and a validation code for easier debugging.\u003c/p\u003e\n"],["\u003cp\u003eEvents sent to the Validation Server are not processed and will not appear in your Google Analytics reports.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Analytics Event Builder offers an interactive way to construct and validate events before sending them to the server.\u003c/p\u003e\n"]]],["To ensure valid events, use the Measurement Protocol Validation Server by sending requests to `/debug/mp/collect` instead of `/mp/collect`. Validate events before deploying them. This server doesn't log events in reports. It returns a response with `validationMessages`, an array detailing any errors like `NAME_INVALID`, `VALUE_REQUIRED`, or `VALUE_OUT_OF_BOUNDS`, specifying the `fieldPath`, `description`, and `validationCode` of the issue. Use the Google Analytics Event Builder for interactive event construction.\n"],null,[]]