Skip to content

Latest commit

 

History

History
60 lines (42 loc) · 5.86 KB

File metadata and controls

60 lines (42 loc) · 5.86 KB
title Google Analytics / Measurement Protocol

Google Analytics / Measurement Protocol

  • Google Analytics For Mobile Apps Getting Shut Down | Simo Ahava's blog (2018-12-03) 提到 This means sending hits with the JavaScript SDK, or building a Measurement Protocol request that includes web dimensions. 原來 client 跟 GA server 間是走 Measurement API。
  • Set up Google Analytics - Analytics Tracking  |  Google Developers 第一步要 Choose a platform,粗分為 website and web apps、mobile app 與 Internet connected devices,前面兩項有自己的 SDK (JavaScript、Android、iOS),但 Internet connected devices 就直接指向 Measurement Protocol,大概是因為定位在 track user interaction in ANY ENVIRONMENT 的關係。
  • Measurement Protocol Overview  |  Analytics Measurement Protocol  |  Google Developers #ril
    • The Google Analytics Measurement Protocol allows developers to make HTTP requests to send RAW USER INTERACTION DATA directly to Google Analytics servers. This allows developers to measure how users interact with their business from almost any environment.
    • Measure user activity in new environments. Tie online to offline behavior. ?? Send data from both the client and SERVER. 感覺像 Slack slash command 拿 GA 來做 tracking 並不奇怪?? 屬於 server-side 的應用。

新手上路 ?? {: #getting-started }

  • Working with the Measurement Protocol  |  Analytics Measurement Protocol  |  Google Developers #ril

    • This document demonstrates how to format HTTP requests to send COMMON HIT TYPES to the Google Analytics Measurement Protocol. 所謂 common 是指不給 t parameter 嗎??

    • To send user interaction data, make an HTTP POST request to this endpoint.

      POST /collect HTTP/1.1
      Host: www.google-analytics.com
      
      payload_data
      
    • The following parameters are required for each payload: Each payload must contain a valid hit type and each hit type has its own set of required fields.

      v=1              // Version.
      &tid=UA-XXXXX-Y  // Tracking ID / Property ID.
      &cid=555         // Anonymous Client ID. (嚴格來說,沒有 `uid` 時,`cid` 才會是必要的)
      &t=              // Hit Type.
      

      所有的 hit type 都要有 vtidcid/uid (二擇一) 跟 t (hit type),而 hit type 會決定還有哪些 parameter 是必要的。以 /home page 的 pageview 為例,dp (document path) 是必要的:

      v=1&tid=UA-XXXXX-Y&cid=555&t=pageview&dp=%2Fhome
      
  • Hit type - Measurement Protocol Parameter Reference  |  Analytics Measurement Protocol  |  Google Developers Required for all hit types. The type of hit. Must be one of 'pageview', 'screenview', 'event', 'transaction', 'item', 'social', 'exception', 'timing'.

  • Client ID - Measurement Protocol Parameter Reference  |  Analytics Measurement Protocol  |  Google Developers

    • Optional. This field is required if User ID (uid) is not specified in the request. 有條件的 optional,也就是 ciduid 至少要有一個。
    • This ANONYMOUSLY identifies a particular user, device, or browser instance. For the web, this is generally stored as a first-party cookie with a two-year expiration. For mobile apps, this is randomly generated for each particular instance of an APPLICATION INSTALL. The value of this field should be a random UUID (version 4) as described in http://www.ietf.org/rfc/rfc4122.txt. 識別個別的用戶,所謂 anonymous 指的是相對辨識度較高的 User ID?
  • Hit Builder — Google Analytics Demos & Tools #ril

  • Measurement Protocol Reference  |  Analytics Measurement Protocol  |  Google Developers #ril

    • For environments where you CAN NOT SEND POST DATA, you can also send HTTP GET requests to the same end point: Where the payload data is sent as URI escaped query parameters. The length of the entire encoded URL must be no longer than 8000 Bytes. 什麼情況不能用 POST? 為什麼要強調 User-Agent 這個 header?

      GET /collect?payload_data HTTP/1.1
      Host: https://www.google-analytics.com
      User-Agent: user_agent_string
      

Event Tracking ??

Custom Dimensions / Metrics ??

參考資料

手冊: