使用者屬性描述使用者族群區隔,例如語言偏好設定 或地理位置Analytics 會自動記錄部分使用者屬性。如果 如想收集額外資源,您最多可以再設定 25 位使用者 每項專案的屬性請參閱自訂使用者屬性,瞭解如何設定和 登錄使用者屬性
使用者屬性能增強使用者區隔,但使用者屬性資料通常只會 可用的伺服器端Measurement Protocol 能讓您 使用伺服器端資料進行用戶端評估,但通常無法這麼做 只使用用戶端解決方案
保留名稱
部分使用者屬性名稱為預留名稱,無法用於評估:
- first_open_time
- first_visit_time
- last_deep_link_referrer
- user_id
- first_open_after_install
此外,使用者屬性名稱的開頭不得為:
- google_
- ga_
- firebase_
使用案例:
在以下範例中,您的客戶關係管理系統中有使用者屬性 (customer_tier)
我想加入測量資料customer_tier 可設為以下其中一個值:
premium 或 standard。如要在報表中取得這項使用者屬性,請按照下列步驟進行:
包括:
首先,請客戶傳送 add_payment_info 事件以及呼叫
具有您客戶關係管理系統存取權的伺服器 API:
用戶端代碼
FirebaseAnalytics.logEvent("add_payment_info")
ServerAPI.addCustomerTier(
  FirebaseAnalytics.getAppInstanceId(),
  "[{name: \"add_payment_info\"}"]
);
接著,您的伺服器使用 customer_tier 使用者屬性擴增測量結果
使用 Measurement Protocol:
伺服器程式碼
const firebaseAppId = "FIREBASE_APP_ID";
const apiSecret = "API_SECRET";
function addCustomerTier(appInstanceId, events) {
  // Request the customer tier from the CRM.
  const customerTier = getCustomerTier(appInstanceId);
  const queryParams = `?firebase_app_id=${firebaseAppId}&api_secret=${apiSecret}`;
  fetch(`https://www.google-analytics.com/mp/collect${queryParams}`, {
    method: "POST",
    body: JSON.stringify({
      "app_instance_id": "APP_INSTANCE_ID",
      "user_properties": {
        "customer_tier": {
          "value": "CUSTOMER_TIER"
        }
      },
      "events": JSON.parse(events)
    })
  });
}
這項使用者屬性會回報 premium 和 standard 這兩個區隔。
覆寫時間戳記
Measurement Protocol 會使用在下列時間找到的第一個時間戳記 列出每個使用者屬性的清單:
- user_properties中項目的- timestamp_micros。
- 要求的 timestamp_micros。
- Measurement Protocol 接收要求的時間。
以下範例傳送的要求層級時間戳記會套用至所有
使用者屬性。因此,Measurement Protocol 會指派
customer_tier 和 customer_group 使用者屬性的時間戳記
requestUnixEpochTimeInMicros。
{
  "timestamp_micros": requestUnixEpochTimeInMicros,
  "user_properties": {
      "customer_tier": {
        "value": customerTierValue
      },
      "customer_group": {
        "value": customerGroupValue
      }
  }
}
以下範例會同時傳送要求層級的時間戳記和
customer_tier 使用者屬性。因此,Measurement Protocol 會指派
customer_tier 是 customerTierUnixEpochTimeInMicros 的時間戳記,而
customer_group 是 requestUnixEpochTimeInMicros 的時間戳記。
"timestamp_micros": requestUnixEpochTimeInMicros,
"user_properties": {
    "customer_tier": {
      "value": customerTierValue,
      "timestamp_micros": customerTierUnixEpochTimeInMicros
    },
    "customer_group": {
      "value": customerGroupValue
    }
}