추적기 객체 참조

이 참조에서는 Tracker 객체에서 사용할 수 있는 메서드를 설명합니다.

메소드 요약

메서드
get(fieldName)

반환: *

추적기에 저장된 필드의 값을 가져옵니다.

set(fieldName|fieldsObject, [fieldValue])

반환: undefined

추적기에 필드/값 쌍 또는 필드/값 쌍의 그룹을 설정합니다.

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

반환: undefined

Google 애널리틱스로 조회를 전송합니다.

Method Details

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 eventCategory, eventAction, eventLabel, eventValue
social socialNetwork, socialAction, socialTarget
timing timingCategory, timingVar, timingValue, timingLabel

개별 필드 문서는 필드 참조를 확인하세요.

반환

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
  });
});