Tracker オブジェクト リファレンス

このリファレンスでは、Tracker オブジェクトで利用できるメソッドについて説明します。

メソッドの概要

メソッド
get(fieldName)

戻り値: *

トラッカーに保存されたフィールドの値を取得します。

set(fieldName|fieldsObject, [fieldValue])

戻り値: undefined

トラッカーに、フィールドと値のペアまたはフィールドと値のペアのグループを設定します。

send([hitType], [...fields], [fieldsObject])

戻り値: undefined

ヒットを Google アナリティクスに送信します。

メソッドの詳細

get

トラッカーに保存されたフィールドの値を取得します。

用途

tracker.get(fieldName);

パラメータ

名前 タイプ 必須 / 省略可 説明
fieldName string 必須 値を取得するフィールドの名前。

戻り値

*

// Creates a default tracker.
ga('create', 'UA-XXXXX-Y', auto);

// Gets the client ID of the default tracker and logs it.
ga(function(tracker) {
  var clientId = tracker.get('clientId');
  console.log(clientId);
});

set

トラッカーに、フィールドと値のペアまたはフィールドと値のペアのグループを設定します。

用途

// Sets a single field/value pair.
tracker.set(fieldName, fieldValue);
// Sets a group of field/value pairs.
tracker.set(fieldsObject);

パラメータ

個別のフィールドについては、フィールド リファレンスをご覧ください。

戻り値

undefined

// Creates a default tracker.
ga('create', 'UA-XXXXX-Y', auto);

ga(function(tracker) {
  // Sets the page field to "/about.html".
  tracker.set('page', '/about.html');
});
// Creates a default tracker.
ga('create', 'UA-XXXXX-Y', auto);

ga(function(tracker) {
  // Sets both the page and title fields.
  tracker.set({
    page: '/about.html',
    title: 'About'
  });
});

send

ヒットを Google アナリティクスに送信します。

用途

tracker.send([hitType], [...fields], [fieldsObject]);

...fields パラメータと fieldsObject に値として指定したフィールドが送信され、現在トラッカーに保存されているフィールドと統合されます。

パラメータ

...fields パラメータで指定できるフィールドは、ヒットタイプによって異なります。次の表に、各ヒットタイプと対応するフィールドの一覧を示します。ここに含まれないヒットタイプは、...fields パラメータを使用できないため、fieldsObject を使用してください。

ヒットタイプ ...fields
pageview page
event eventCategoryeventActioneventLabeleventValue
social socialNetworksocialActionsocialTarget
timing timingCategorytimingVartimingValuetimingLabel

個別のフィールドについては、フィールド リファレンスをご覧ください。

戻り値

undefined

// Creates a default tracker.
ga('create', 'UA-XXXXX-Y', auto);

ga(function(tracker) {
  // Sends a pageview hit.
  tracker.send('pageview');
});
// Creates a default tracker.
ga('create', 'UA-XXXXX-Y', auto);

ga(function(tracker) {
  // Sends an event hit for the tracker named "myTracker" with the
  // following category, action, and label, and sets the nonInteraction
  // field value to true.
  tracker.send('event', 'link', 'click', 'http://example.com', {
    nonInteraction: true
  });
});