고급 가이드
1. 이벤트 전송
SDK 초기화가 완료되면 데이터 트래킹을 진행하여 유저의 행동 정보를 수집할 수 있습니다. 일반적으로 일반 이벤트로 비즈니스 시나리오의 요구 사항을 충족할 수 있으며, 실제 비즈니스 시나리오에 따라 최초 이벤트, 업데이트 가능 이벤트 등을 사용할 수도 있습니다.
1.1 일반 이벤트
track을 호출하여 이벤트를 전송할 수 있습니다. 앞서 정리한 문서에 따라 이벤트 속성과 이벤트 전송 조건을 설정하는 것을 권장합니다. 여기서는 유저가 어떤 상품을 구매하는 경우를 예로 듭니다:
TDPropertiesNode event_properties;
event_properties.SetString("name1", "XZ_debug");
event_properties.SetString("name2", "logbugs");
event_properties.SetString("name3", "name3");
event_properties.SetString("#uuid", "1234567890");
event_properties.SetNumber("test_number_int", 3);
event_properties.SetNumber("test_number_double", 3.14);
event_properties.SetBool("test_bool", true);
std::string test_string = "test_string";
event_properties.SetString("test_stl_string1", test_string);
event_properties.SetDateTime("test_time1", time(nullptr), 0);
timeb t = {};
ftime(&t);
event_properties.SetDateTime("#time", t.time, t.millitm);
std::vector<std::string> test_list;
test_list.push_back("item11");
test_list.push_back("item21");
event_properties.SetList("test_list1", test_list);
// track event
te.track("accountId", "distinctId", "eventName", event_properties);
1.2 최초 이벤트
최초 이벤트는 디바이스 또는 기타 차원의 ID를 기준으로 한 번만 기록되는 이벤트입니다. 예를 들어 특정 디바이스에서의 활성화 이벤트를 기록하려는 경우 최초 이벤트로 데이터를 전송할 수 있습니다. 최초 이벤트 검증 기능을 사용하려면 반드시 properties에 #first_check_id 필드를 설정해야 하며, 타입은 문자열입니다.
TDPropertiesNode event_properties;
// first event
event_properties.SetString("#first_check_id", "first_event");
te.track_first("accountId", "distinctId", "eventName", event_properties);
주의: 최초 여부 검증은 서버 측에서 이루어지므로 최초 이벤트는 기본적으로 1시간 지연되어 저장됩니다.
1.3 업데이트 가능 이벤트
업데이트 가능 이벤트를 사용하면 특정 시나리오에서 이벤트 데이터를 수정해야 하는 요구를 충족할 수 있습니다. 업데이트 가능 이벤트는 해당 이벤트를 식별하는 ID를 지정해야 하며, 업데이트 가능 이벤트 객체를 생성할 때 전달합니다. AE 백엔드는 이벤트 이름과 이벤트 ID를 기준으로 업데이트할 데이터를 결정합니다.
// updatable event
std::string updateEventId = "update_001";
TDPropertiesNode update_event_properties;
update_event_properties.SetString("price", "100");
update_event_properties.SetString("status", "3");
// the value of "status" is 3, the value of "price" is 100
te.track_update("accountId", "distinctId", "eventName", updateEventId, update_event_properties);
TDPropertiesNode update_event_new_properties;
update_event_new_properties.SetString("status", "5");
// the value of "status" become 5, the value of "price" is still 100
te.track_update("accountId", "distinctId", "eventName", updateEventId, update_event_new_properties);
1.4 덮어쓰기 가능 이벤트
덮어쓰기 가능 이벤트는 업데이트 가능 이벤트와 비슷하지만, 최신 데이터로 과거 데이터를 완전히 덮어쓴다는 점이 다릅니다. 효과 면에서는 이전 데이터를 삭제하고 최신 데이터를 저장하는 것과 같습니다. AE 백엔드는 이벤트 이름과 이벤트 ID를 기준으로 업데이트할 데이터를 결정합니다.
// overwrite event
std::string overWriteEventId = "overWrite_001";
TDPropertiesNode overWrite_event_properties;
overWrite_event_properties.SetString("money", "99");
overWrite_event_properties.SetString("code", "10");
// the value of "code" is 10, the value of "money" is 99
te.track_overwrite("accountId", "distinctId", "eventName", overWriteEventId, overWrite_event_properties);
TDPropertiesNode overWrite_event_new_properties;
overWrite_event_new_properties.SetString("money", "66");
// The "money" has changed to 66,The "code" will be deleted
te.track_overwrite("accountId", "distinctId", "eventName", overWriteEventId, overWrite_event_new_properties);
2. 유저 속성
AE 플랫폼에서 지원하는 유저 속성 설정 API는 다음과 같습니다: user_set, user_setOnce, user_add, user_unset, user_del, user_append, user_uniqAppend.
2.1 user_set
일반적인 유저 속성은 user_set을 호출하여 설정할 수 있습니다. 이 인터페이스로 업로드한 속성은 원래 속성 값을 덮어쓰며, 이전에 해당 유저 속성이 없었다면 새로 생성하고 타입은 전달된 속성의 타입과 같습니다. 여기서는 사용자 이름 설정을 예로 듭니다:
TDPropertiesNode userSet_properties;
userSet_properties.SetString("userName", "A");
// set user properties. the value of "userName" is "A"
te.user_set("accountId", "distinctId", userSet_properties);
userSet_properties.SetString("userName", "B");
// set user properties again,the value of "userName" will change to "B"
te.user_set("accountId", "distinctId", userSet_properties);
2.2 user_setOnce
업로드할 유저 속성을 한 번만 설정하면 되는 경우 user_setOnce를 호출하여 설정할 수 있습니다. 해당 속성에 이미 값이 있으면 이 정보는 무시됩니다. 여기서도 사용자 이름 설정을 예로 듭니다:
// user_setOnce
TDPropertiesNode userSetOnce_properties;
userSetOnce_properties.SetString("user_one_name", "A");
// create "user_one_name" property, and the value is "A"
te.user_setOnce("accountId", "distinctId", userSetOnce_properties);
userSetOnce_properties.SetString("user_one_name", "B");
// the value of "user_one_name" is still "A"
te.user_setOnce("accountId", "distinctId", userSetOnce_properties);
2.3 user_add
숫자형 속성을 업로드할 때 user_add를 호출하여 해당 속성을 누적할 수 있습니다. 해당 속성이 아직 설정되지 않았으면 0을 할당한 후 계산합니다. 음수를 전달할 수도 있으며, 이는 빼기 연산과 같습니다. 여기서는 누적 결제 금액을 예로 듭니다:
// user_add
TDPropertiesNode userAdd_properties;
userAdd_properties.SetNumber("cash", 30);
// the value of "cash" is 30
te.user_add("accountId", "distinctId", userAdd_properties);
userAdd_properties.SetNumber("cash", 60);
// set user properties again,the value of "cash" is 90 now
te.user_add("accountId", "distinctId", userAdd_properties);
설정하는 속성 key는 문자열이며, Value는 숫자만 허용됩니다.
2.4 user_append
user_append를 호출하여 배열 타입의 유저 속성에 값을 추가할 수 있습니다.
// user_append
TDPropertiesNode userAppend_properties;
std::vector<std::string> userAppendListValue;
userAppendListValue.push_back("11");
userAppendListValue.push_back("33");
userAppend_properties.SetList("arr1", userAppendListValue);
// the value of "arr1" is ["11", "33"]
te.user_append("accountId", "distinctId", userAppend_properties);
TDPropertiesNode userAppend_properties_new;
std::vector<std::string> userAppendListValueNew;
userAppendListValueNew.push_back("22");
userAppendListValueNew.push_back("33");
userAppend_properties_new.SetList("arr1", userAppendListValueNew);
// the value of "arr1" is ["11", "33", "22", "33"]
te.user_append("accountId", "distinctId", userAppend_properties_new);
2.5 user_uniqAppend
user_uniqAppend를 호출하여 배열 타입의 유저 속성에 값을 추가할 수 있습니다. user_uniqAppend 인터페이스는 추가하는 유저 속성의 중복을 제거하지만, user_append 인터페이스는 중복을 제거하지 않으므로 유저 속성에 중복이 있을 수 있습니다.
// user_uniqAppend
TDPropertiesNode userAppend_properties;
std::vector<std::string> userAppendListValue;
userAppendListValue.push_back("11");
userAppendListValue.push_back("33");
userAppend_properties.SetList("arr1", userAppendListValue);
// the value of "arr1" is ["11", "33"]
te.user_uniqAppend("accountId", "distinctId", userAppend_properties);
TDPropertiesNode userAppend_properties_new;
std::vector<std::string> userAppendListValueNew;
userAppendListValueNew.push_back("22");
userAppendListValueNew.push_back("33");
userAppend_properties_new.SetList("arr1", userAppendListValueNew);
// the value of "arr1" is ["11", "33", "22"]
te.user_uniqAppend("accountId", "distinctId", userAppend_properties_new);
2.6 user_unset
유저의 유저 속성 값을 비우려면 user_unset을 호출하여 지정한 속성을 비울 수 있습니다. 해당 속성이 아직 클러스터에 생성되지 않았다면 user_unset은 해당 속성을 생성하지 않습니다
// user_unset
TDPropertiesNode userUnset_properties;
userUnset_properties.SetNumber("userName", 0);
// the value of "userName" will be reset after executed "user_unset"
te.user_unset("accountId", "distinctId", userUnset_properties);
user_unset: 전달 값은 비울 속성의 Key 값입니다.
2.7 user_del
특정 유저를 삭제하려면 user_del을 호출하여 해당 유저를 삭제할 수 있습니다. 삭제한 후에는 해당 유저의 유저 속성을 더 이상 조회할 수 없지만, 해당 유저가 발생시킨 이벤트는 여전히 조회할 수 있습니다. 이 작업은 되돌릴 수 없는 결과를 초래할 수 있으므로 신중하게 사용하십시오.
te.user_del("accountId", "distinctId");
3. 기타 기능
3.1 BatchConsumer
데이터양이 너무 많거나 네트워크에 이상이 있으면 데이터가 유실될 위험이 있으므로 운영 환경에서는 사용하지 않는 것을 권장합니다
데이터를 AE 서버로 실시간 일괄 전송하며, 별도의 전송 도구가 필요하지 않습니다.
TDBatchConsumer batchConsumer("APPID","SERVER_URL", 10);
TDAnalytics te(batchConsumer, true);
파라미터 설명:
-
APPID: 프로젝트의 APPID로, AE 백엔드의 프로젝트 관리 페이지에서 확인할 수 있습니다 -
SERVER_URL: 데이터 전송 URL- 클라우드 서비스를 사용하는 경우 다음을 입력합니다: https://global-receiver-ta.thinkingdata.cn
- 프라이빗 배포 버전을 사용하는 경우 데이터 수집 주소에 도메인을 바인딩하고 HTTPS 인증서를 설정하십시오: https://데이터 수집 주소에 바인딩한 도메인

