menu
Is this helpful?

# Ruby

최신 버전:v2.0.0

업데이트 시간:2023-10-08

다운로드: Source Code (opens new window)

# 1. SDK 구현

  1. gem을 이용하여 SDK를 액세스해 주세요.
# install SDK
gem install thinkingdata-ruby
  1. Logbus 설치

TE 시스템을 통해 빠르고 정확한 데이터 전송을 위해, SDK와 LogBus를 함께 사용하여 서버 데이터의 데이터 리포트를 권장합니다.

# 2. 초기 설정

다음은 SDK의 초기 설정 포맷 코드입니다:

require 'thinkingdata-ruby'

consumer = ThinkingData::TDLoggerConsumer.new("LOG_DIRECTORY")
ta = ThinkingData::TDAnalytics.new(consumer)

LOG_DIRECTORY는 로컬 액세스 파일의 주소가 됩니다. LogBus의 모니터 주소를 이 주소로 설정하면 자동으로 업로드됩니다.

# 3. 주요 기능

게스트 ID와 계정 ID를 정확하게 연동하기 위해, 게임 내에서 게스트 ID와 계정 ID를 모두 사용하는 경우, 이들 ID를 동시에 업로드하는 것을 권장합니다. 동시에 업로드하지 않을 경우, 유저가 중복으로 계산될 수 있습니다.

# 3.1 이벤트 전송

track을 사용하여 이벤트 전송을 합니다. 사전에 데이터 트래킹 정책을 준비한 후, 전송해 주세요. 다음은 모델 코드입니다.

DEMO_ACCOUNT_ID = '123'
DEMO_DISTINCT_ID = 'aaa'

properties = {
  array: ["str1", "11", Time.now, "2020-02-11 17:02:52.415"],
  prop_date: Time.now,
  prop_double: 134.1,
  prop_string: 'hello world',
  prop_bool: true,
}

ta.track(event_name: 'test_event', distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: properties)
  • 이벤트 이름은 string 타입으로, 영문자와 숫자, "_"를 포함하며 최대 50자입니다.
  • Key는 해당 속성의 이름으로 string 타입이며, 영문자와 숫자, "_"를 포함하여 최대 50자입니다. TE 시스템은 일괄적으로 소문자로 통일됩니다.
  • Value는 해당 속성의 값으로, String, Number, Bloon, Time, object, array, list object를 지원합니다.

유저 속성은 이벤트 속성과 일치해야 합니다.

# 3.2 유저 속성 설정

일반적인 유저 속성에 대해서는 user_set을 사용하여 설정할 수 있으며, UserSet은 기존의 값을 덮어씁니다. 원래 해당 속성에 값이 없는 경우, 속성이 새로 생성됩니다. 다음은 코드 예시입니다.

DEMO_ACCOUNT_ID = '123'
DEMO_DISTINCT_ID = 'aaa'

user_data = {
  array: ["str1", 11, 22.22],
  prop_date: Time.now,
  prop_double: 134.12,
  prop_string: 'hello',
  prop_int: 666,
}
ta.user_set(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_data)

# 4. 코드 예시 (Example Code)

아래의 코드 예시에 모든 작업이 포함되어 있으며, 아래 순서대로 사용하는 것을 권장합니다:


ThinkingData::set_stringent(false)
ThinkingData::set_enable_log(false)

consumer = ThinkingData::TDLoggerConsumer.new( 'LOG_DIRECTORY', 'hourly')
ta = ThinkingData::TDAnalytics.new(consumer, my_error_handler, uuid: true)

DEMO_ACCOUNT_ID = '123'
DEMO_DISTINCT_ID = 'aaa'

properties = {
  array: ["str1", "11", Time.now, "2020-02-11 17:02:52.415"],
  prop_date: Time.now,
  prop_double: 134.1,
  prop_string: 'hello world',
  prop_bool: true,
}

ta.track(event_name: 'test_event', distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: properties)

user_data = {
  array: ["str1", 11, 22.22],
  prop_date: Time.now,
  prop_double: 134.12,
  prop_string: 'hello',
  prop_int: 666,
}
ta.user_set(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_data)

user_append_data = {
  array: %w[33 44]
}
ta.user_append(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_append_data)

user_uniq_append_data = {
  array: %w[44 55]
}
ta.user_uniq_append(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_uniq_append_data)

user_set_once_data = {
  prop_int_new: 888,
}
ta.user_set_once(distinct_id: DEMO_DISTINCT_ID, account_id: DEMO_ACCOUNT_ID, properties: user_set_once_data)

ta.user_add(distinct_id: DEMO_DISTINCT_ID, properties: {prop_int: 10, prop_double: 15.88})

ta.user_unset(distinct_id: DEMO_DISTINCT_ID, property: [:prop_string, :prop_int])

ta.user_del(distinct_id: DEMO_DISTINCT_ID)

ta.flush