ga 객체 메서드 참조

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

메소드 요약

analytics.js 라이브러리가 로드된 후 ga 객체에서 다음 메서드를 사용할 수 있습니다. 이러한 메서드는 즉시 사용할 수 없으므로 항상 ga 명령어 목록의 준비된 콜백을 사용하여 호출해야 합니다.

하지 말아야 할 일 - 메서드를 아직 사용하지 못할 수 있으므로 readyCallback 외부의 ga 객체 메서드를 사용합니다.

var trackers = ga.getAll();

권장 - readyCallback 객체 내에서 사용 가능하다고 보장되는 ga 객체 메서드를 사용합니다.

ga(function() {
  var trackers = ga.getAll();
});
메서드
create([trackingId], [cookieDomain], [name], [fieldsObject]);

반환: Tracker

지정된 필드를 사용하여 새 추적기 인스턴스를 만듭니다.

getByName(name)

반환: Tracker

지정한 이름의 추적기 인스턴스를 가져옵니다.

getAll()

반환: Array<Tracker>

모든 추적기 인스턴스를 가져옵니다.

remove(name)

반환: undefined

지정된 이름의 추적기 인스턴스를 삭제합니다.

Method Details

create

지정된 필드를 사용하여 새 추적기 인스턴스를 만듭니다.

사용

ga.create([trackingId], [cookieDomain], [name], [fieldsObject]);

매개변수

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

반환

Tracker

// Creates a default tracker for the property UA-XXXXX-Y
// and uses automatic cookie domain configuration.
ga(function() {
  var tracker = ga.create('UA-XXXXX-Y', 'auto');
})
// Creates a tracker with the name "myTracker" for the property
// UA-XXXXX-Y, sets the cookieDomain to "example.com" and specifies
// a site speed sample rate of 10%.
ga(function() {
  var myTracker = ga.create('UA-XXXXX-Y', 'example.com', 'myTracker', {
    siteSpeedSampleRate: 10
  });
});

getByName

지정한 이름의 추적기 인스턴스를 가져옵니다.

사용

ga.getByName(name);

매개변수

이름 유형 필수 여부 설명
name string 가져올 추적기의 이름입니다.

반환

Tracker

// Gets the default tracker.
ga(function() {
  ga.getByName('t0');
});
// Gets the tracker with the name "myTracker".
ga(function() {
  ga.getByName('myTracker');
});

getAll

모든 추적기 인스턴스를 가져옵니다.

ga.getAll();

반환

Array<Tracker>

// Logs a list of all tracker names to the console.
ga(function() {
  var trackers = ga.getAll();
  trackers.forEach(function(tracker) {
    console.log(tracker.get('name'));
  });
});

remove

지정된 이름의 추적기 인스턴스를 삭제합니다.

사용

ga.remove(name);

매개변수

이름 유형 필수 여부 설명
name string 삭제할 추적기의 이름입니다.

반환

undefined

// Removes the default tracker.
ga(function() {
  // Note that, unlike the ga command queue's remove method,
  // this method requires passing a tracker name, even when
  // removing the default tracker.
  ga.remove('t0');
});
// Removes the tracker with the name "myTracker".
ga(function() {
  ga.remove('myTracker');
});