Google 애널리틱스로 측정 프로토콜 이벤트 전송

이 가이드에서는 Google 애널리틱스 측정 프로토콜 웹 및 앱 스트림 이벤트를 Google 애널리틱스 서버를 통해 Google 애널리틱스 보고서

이 가이드에서 확인할 플랫폼을 선택하세요.

요청 형식 지정하기

Google 애널리틱스 측정 프로토콜은 HTTP POST 요청만 지원합니다.

이벤트를 전송하려면 다음 형식을 사용하세요.

POST /mp/collect HTTP/1.1
HOST: www.google-analytics.com
Content-Type: application/json
<payload_data>

요청 URL에 다음을 포함해야 합니다.

  • api_secret: Google 애널리틱스 UI에서 생성된 API 비밀번호입니다.

    새 비밀번호를 만들려면 관리자 > 데이터 스트림 > 스트림 선택 > 측정 프로토콜 > 생성으로 이동합니다.

  • measurement_id: 스트림과 연결된 측정 ID로, 관리자 > 데이터 스트림 > 스트림 선택 > 측정 ID 아래의 Google 애널리틱스 UI에서 찾을 수 있습니다.

    measurement_id스트릠 ID가 아닙니다.

전체 참조를 보려면 쿼리 매개변수를 참고하세요.

요청 본문에 다음을 포함해야 합니다.

  • client_id: 클라이언트의 고유 식별자입니다. Firebase app_instance_id와는 다릅니다. gtag.js('get')를 사용하세요.
  • user_id: 선택사항입니다. 사용자의 고유 식별자입니다. UTF-8만 포함할 수 있습니다. 있습니다. 이 식별자에 관한 자세한 내용은 교차 플랫폼 분석용 User-ID를 참고하세요.

  • consent: 선택사항. 동의 설정 방법 알아보기 설정을 참조하세요.

  • timestamp_micros: 선택사항. 해당 세대의 유닉스 시간(마이크로초)은 이벤트 및 사용자 속성을 포함합니다. 지정하지 않으면 기본값은 호출 시간.

  • events: 이벤트 항목의 배열입니다. 여러 이벤트를 한 번에 포함할 수 있습니다 합니다.

    실시간 보고서와 같은 보고서에 사용자 활동을 표시하려면 event에 대한 params의 일부로 engagement_time_msecsession_id가 제공되어야 합니다. engagement_time_msec 매개변수는 이벤트의 참여 시간(밀리초)입니다.

    예를 들면 다음과 같습니다.

```json { "client_id": "123456.7654321", "events": [ { "name": "campaign_details", "params": { "campaign_id": "google_1234", "campaign": "Summer_fun", "source": "google", "medium": "cpc", "term": "summer+travel", "content": "logolink", "session_id": "123", "engagement_time_msec": "100" } } ] } ``` While `session_start` is a [reserved event name](/analytics/devguides/collection/protocol/ga4/reference#reserved_names), creating a new `session_id` creates a new session without the need to send `session_start`. Understand how [sessions are counted](//support.google.com/analytics/answer/9191807). ## Try it Here's an example you can use to send a [`tutorial_begin`] event to your Google Analytics server: ```javascript const measurement_id = `G-XXXXXXXXXX`; const api_secret = `<secret_value>`; fetch(`https://www.google-analytics.com/mp/collect?measurement_id=${measurement_id}&api_secret=${api_secret}`, { method: "POST", body: JSON.stringify({ client_id: 'XXXXXXXXXX.YYYYYYYYYY', events: [{ name: 'tutorial_begin', params: {}, }] }) }); ``` ## Override timestamp The Measurement Protocol uses the *first* timestamp it finds in the following list for each event in the request: 1. The `timestamp_micros` of the event. 1. The `timestamp_micros` of the request. 1. The time that the Measurement Protocol receives the request. The following example sends a request-level timestamp that applies to all of the events in the request. As a result, the Measurement Protocol assigns both the `tutorial_begin` and `join_group` events a timestamp of `requestUnixEpochTimeInMicros`. ```javascript { "timestamp_micros": requestUnixEpochTimeInMicros, "events": [ { "name": "tutorial_begin" }, { "name": "join_group", "params": { "group_id": "G_12345", } } ] } ``` The following example sends both a request-level timestamp and an event-level timestamp. As a result, the Measurement Protocol assigns the `tutorial_begin` event a timestamp of `tutorialBeginUnixEpochTimeInMicros`, and the `join_group` event a timestamp of `requestUnixEpochTimeInMicros`. ```javascript { "timestamp_micros": requestUnixEpochTimeInMicros, "events": [ { "name": "tutorial_begin", "timestamp_micros": tutorialBeginUnixEpochTimeInMicros }, { "name": "join_group", "params": { "group_id": "G_12345", } } ] } ``` ## Limitations The following limitations apply to sending Measurement Protocol events to Google Analytics: Note: For information on the limitations of 360 features, see [Google Analytics 360](//support.google.com/analytics/answer/11202874). * Requests can have a maximum of 25 events. * Events can have a maximum of 25 parameters. * Events can have a maximum of 25 user properties. * User property names must be 24 characters or fewer. * User property values must be 36 characters or fewer. * Event names must be 40 characters or fewer, can only contain alpha-numeric characters and underscores, and must start with an alphabetic character. * Parameter names including item parameters must be 40 characters or fewer, can only contain alpha-numeric characters and underscores, and must start with an alphabetic character. * Parameter values including item parameter values must be 100 characters or fewer for a standard Google Analytics property, and 500 characters or fewer for a Google Analytics 360 property. * Item parameters can have a maximum of 10 custom parameters. * The post body must be smaller than 130kB. * App Measurement Protocol events sent to Google Analytics 4 don't populate Search audiences in Google Ads for app users. For additional requirements of each use case, see [common use cases].