ユーザー プロパティは、言語設定や地理的位置などのユーザーベースのセグメントを表現します。アナリティクスでは、一部のユーザー プロパティが自動的にログに記録されます。他のプロパティを収集したい場合は、プロジェクトごとに最大 25 個のユーザー プロパティを追加設定することができます。ユーザー プロパティの設定と登録の方法について詳しくは、カスタム ユーザー プロパティをご覧ください。
ユーザー プロパティを使用するとユーザー セグメントを拡張できますが、ユーザー プロパティのデータは、多くの場合、サーバーサイドでのみ利用できます。Measurement Protocol を使用すると、 サーバーサイド データを使用したクライアントサイド測定(通常は実現不可能) クライアントサイドソリューションのみを使用します
予約済みの名前
一部のユーザー プロパティ名は予約済みのため、測定では使用できません。
first_open_timefirst_visit_timelast_deep_link_referreruser_idfirst_open_after_install
また、ユーザー プロパティ名の先頭を以下にすることはできません。
google_ga_firebase_
使用例
以下の例では、測定に追加するユーザー プロパティ(customer_tier)が CRM に含まれています。customer_tier は premium または standard に設定できます。レポートでこのユーザー プロパティを取得するための手順は、以下のとおりです。
まず、クライアントに呼び出しと一緒に add_payment_info イベントを送信してもらいます。
CRM システムにアクセスできるサーバー 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 の 2 種類のセグメントがレポートされます。
イベントの送信について詳しくは、イベントの送信をご覧ください。 Measurement Protocol。
タイムスタンプをオーバーライド
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
}
}