カスタム ディメンションやカスタム指標を使用すると、ログイン中のユーザーとログアウトしたユーザー、ページの著者、ゲーム内のレベルを分割してその違いを測定することができます。このページでは、Google アナリティクスにカスタム ディメンションとカスタム指標を送信する方法について説明します。
カスタム パラメータの値を Google アナリティクスに送信するには、次に示す Google アナリティクスのカスタム ディメンションまたはカスタム指標のパラメータにパラメータをマッピングします。
カスタム パラメータ | データ型 | 説明 |
---|---|---|
dimension<Index> |
string |
カスタム ディメンション パラメータ(例: dimension3 ) |
metric<Index> |
string |
カスタム指標パラメータ(例: metric8 ) |
カスタム ディメンションの設定と送信
カスタム パラメータの値を Google アナリティクスに送信するには、ウェブサイト上の値を Google アナリティクスのパラメータにマッピングする必要があります。これには custom_map
パラメータを使用します。
Google アナリティクスにカスタム ディメンションを送信するには、プロパティの config
を更新してディメンションの custom_map
パラメータを設定し、カスタム パラメータを使用してカスタム ディメンションの値を送信します。
// Configures custom dimension<Index> to use the custom parameter // 'dimension_name' for 'GA_MEASUREMENT_ID', where <Index> is a number // representing the index of the custom dimension. gtag('config', 'GA_MEASUREMENT_ID', { 'custom_map': {'dimension<Index>': 'dimension_name'} }); // Sends the custom dimension to Google Analytics. gtag('event', 'any_event_name', {'dimension_name': dimension_value});
'GA_MEASUREMENT_ID'
は、ご自分の Google アナリティクス ID に置き換えてください。
たとえば、次のスニペットでは、値が 55
のカスタム ディメンション dimension2
が Google アナリティクスに送信されます。
// Maps 'dimension2' to 'age'. gtag('config', 'GA_MEASUREMENT_ID', { 'custom_map': {'dimension2': 'age'} }); // Sends an event that passes 'age' as a parameter. gtag('event', 'age_dimension', {'age': 55});
カスタム指標の設定と送信
Google アナリティクスにカスタム指標を送信するには、プロパティの config
を更新して指標の custom_map
パラメータを設定し、カスタム パラメータを使用してカスタム指標の値を送信します。
// Configures custom metric<Index> to use the custom parameter // 'metric_name' for GA_MEASUREMENT_ID, where <Index> is a number // representing the index of the custom metric. gtag('config', 'GA_MEASUREMENT_ID', { 'custom_map': {'metric<Index>': 'metric_name'} }); // Sends the custom dimension to Google Analytics. gtag('event', 'any_event_name', {'metric_name': metric_value});
'GA_MEASUREMENT_ID'
は、ご自分の Google アナリティクス ID に置き換えてください。
たとえば、次のスニペットでは、値が 1
のカスタム指標 metric5
が Google アナリティクスに送信されます。
// Maps 'metric5' to 'avg_page_load_time'. gtag('config', 'GA_MEASUREMENT_ID', { 'custom_map': {'metric5': 'avg_page_load_time'} }); // Sends an event that passes 'avg_page_load_time' as a parameter. gtag('event', 'load_time_metric', {'avg_page_load_time': 1});
カスタム ディメンションとカスタム指標の設定と送信
プロパティの config
を更新して、カスタム ディメンションとカスタム指標の両方をマッピングできます。
gtag('config', 'GA_MEASUREMENT_ID', { 'custom_map': { 'dimension2': 'age', 'metric5': 'avg_page_load_time' } }); gtag('event', 'foo', {'age': 55, 'avg_page_load_time': 1});