Zadbaj o dobrą organizację dzięki kolekcji
Zapisuj i kategoryzuj treści zgodnie ze swoimi preferencjami.
Wybierz platformę:
Protokół pomiarowy Google Analytics nie zwraca kodów błędów, nawet jeśli zdarzenie jest zniekształcone lub brakuje w nim wymaganych parametrów.HTTP Aby się upewnić, że zdarzenie jest prawidłowe, przetestuj je za pomocą serwera weryfikacyjnego Measurement Protocol, zanim je wdrożysz w środowisku produkcyjnym.
Po sprawdzeniu, czy zdarzenia są prawidłowo skonstruowane, zweryfikuj implementację, aby upewnić się, że używasz prawidłowych kluczy.
Możesz wywołać serwer weryfikacji bezpośrednio lub użyć kreatora zdarzeń Google Analytics. Kreator zdarzeń Google Analytics umożliwia interaktywne tworzenie zdarzeń i korzysta z serwera weryfikacji platformy Measurement Protocol do ich weryfikowania.
Z tego przewodnika dowiesz się, jak wysyłać zdarzenia do serwera weryfikacji Measurement Protocol w Google Analytics 4 i interpretować odpowiedź.
Wysyłanie zdarzeń do weryfikacji
Jedyna różnica między żądaniem zdarzeń wysyłanych do Measurement Protocol a żądaniem wysyłanym do serwera weryfikacyjnego Measurement Protocol to adres URL.
Serwer
URL
Measurement Protocol
/mp/collect
Serwer weryfikacyjny Measurement Protocol
/debug/mp/collect
Wszystkie pozostałe pola żądania są takie same. Pełne informacje o tworzeniu prawidłowego żądania znajdziesz w dokumentacji protokołu.
Poniższy kod pokazuje, jak wysłać nieprawidłowe zdarzenie do serwera weryfikacji Measurement Protocol:
Odpowiedź na weryfikację
Oto odpowiedź serwera weryfikacyjnego na poprzednie zdarzenie:
{"validationMessages":[{"fieldPath":"events","description":"Event at index: [0] has invalid name [_badEventName]. Names must start with an alphabetic character.","validationCode":"NAME_INVALID"}]}
Oto odpowiedź serwera weryfikacyjnego na żądanie, w którym nie wykryto problemów z weryfikacją:
[[["Łatwo zrozumieć","easyToUnderstand","thumb-up"],["Rozwiązało to mój problem","solvedMyProblem","thumb-up"],["Inne","otherUp","thumb-up"]],[["Brak potrzebnych mi informacji","missingTheInformationINeed","thumb-down"],["Zbyt skomplikowane / zbyt wiele czynności do wykonania","tooComplicatedTooManySteps","thumb-down"],["Nieaktualne treści","outOfDate","thumb-down"],["Problem z tłumaczeniem","translationIssue","thumb-down"],["Problem z przykładami/kodem","samplesCodeIssue","thumb-down"],["Inne","otherDown","thumb-down"]],["Ostatnia aktualizacja: 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,[]]