Google Analytics को मेज़रमेंट प्रोटोकॉल इवेंट भेजें

इस गाइड में बताया गया है कि Google Analytics मेज़रमेंट प्रोटोकॉल वेब और ऐप्लिकेशन स्ट्रीम इवेंट के लिए Google Analytics सर्वर का इस्तेमाल किया जा सकता है, ताकि आप इसमें मेज़रमेंट प्रोटोकॉल इवेंट देख सकें आपकी Google Analytics रिपोर्ट.

वह प्लैटफ़ॉर्म चुनें जिसे आपको इस गाइड में देखना है:

अनुरोध को फ़ॉर्मैट करना

Google Analytics मेज़रमेंट प्रोटोकॉल सिर्फ़ एचटीटीपी POST अनुरोधों के साथ काम करता है.

इवेंट भेजने के लिए, इस फ़ॉर्मैट का इस्तेमाल करें:

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

आपको अनुरोध के यूआरएल में यह जानकारी देनी होगी:

  • api_secret: Google Analytics के यूज़र इंटरफ़ेस (यूआई) में जनरेट किया गया एपीआई सीक्रेट.

    नया सीक्रेट बनाने के लिए, एडमिन पर जाएं > डेटा स्ट्रीम > चुनें स्ट्रीम > मेज़रमेंट प्रोटोकॉल > बनाएं.

  • measurement_id: किसी स्ट्रीम से जुड़ा मेज़रमेंट आईडी, जो एडमिन सेक्शन में Google Analytics का यूज़र इंटरफ़ेस (यूआई) > डेटा स्ट्रीम > अपना स्ट्रीम > मेज़रमेंट आईडी.

    measurement_id, आपका स्ट्रीम आईडी नहीं है.

पूरी जानकारी के लिए, क्वेरी पैरामीटर देखें.

आपको अनुरोध के मुख्य हिस्से में यह जानकारी देनी होगी:

  • client_id: यह क्लाइंट के लिए एक यूनीक आइडेंटिफ़ायर होता है. यह Firebase app_instance_id. gtag.js('get') का इस्तेमाल करें.
  • user_id: ज़रूरी नहीं. उपयोगकर्ता के लिए यूनीक आइडेंटिफ़ायर. इसमें सिर्फ़ UTF-8 का इस्तेमाल किया जा सकता है वर्ण ज़्यादा जानकारी के लिए क्रॉस-प्लैटफ़ॉर्म विश्लेषण के लिए User-ID देखें इस आइडेंटिफ़ायर के बारे में जानकारी.

  • consent: ज़रूरी नहीं. सहमति सेट करने का तरीका जानें सेटिंग पर टैप करें.

  • timestamp_micros: ज़रूरी नहीं. Unix epoch टाइम, माइक्रोसेकंड में, इवेंट और उपयोगकर्ता प्रॉपर्टी मौजूद होती हैं. अगर यह तय नहीं किया गया है, तो डिफ़ॉल्ट रूप से अनुरोध का समय.

  • events: इवेंट आइटम का कलेक्शन. एक इवेंट में, एक से ज़्यादा इवेंट शामिल किए जा सकते हैं अनुरोध.

    उपयोगकर्ता गतिविधि को रिपोर्ट में दिखाने के लिए, जैसे कि रीयलटाइम, engagement_time_msec और session_id, event के लिए params चुकाएं. 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 don't populate Search audiences in Google Ads for app users. For additional requirements of each use case, see [common use cases].