전역 속성 설정
앱에서 전송되는 모든 세션과 이벤트에 자동으로 첨부되는 사용자 정의 속성을 정의하여 리포트에서 상세한 데이터 세분화를 가능하게 합니다.
전역 속성을 사용하면 필요한 모든 사용자, 앱 모드 또는 컨텍스트 정보를 트래킹할 수 있습니다. 예를 들어 게임 앱에서 "0"으로 초기화된 "Level" 속성을 생성하고 사용자가 진행함에 따라 업데이트할 수 있습니다. 모든 세션과 이벤트에 이 속성이 포함되어 사용자 레벨별로 세션, 이벤트 수, 매출을 분석할 수 있습니다.
속성 사양
한도 및 지속성
전역 속성의 제약 사항과 지속성 동작을 이해하세요.
- 최대 속성 수: 앱 설치당 최대 5개의 전역 속성을 정의할 수 있습니다
- 지속성: 속성은 명시적으로 해제되거나 앱이 제거될 때까지 가장 최근 값으로 앱 실행 간에 지속됩니다
- 문자 한도: 속성 이름과 값은 최대 200자까지 가능합니다. 더 긴 값은 자동으로 200자로 잘립니다
- 데이터 사용 가능성: 전역 속성은 사용자 수준 익스포트와 포스트백에서 액세스할 수 있습니다. 집계 리포팅 지원에 대한 업데이트는 Singular 고객 성공 매니저에게 문의하세요
초기화 시 전역 속성 설정
SingularConfig를 통한 구성
Singular.start()를 호출하기 전에
setGlobalProperty
메서드를 사용하여 SDK 초기화 중에 전역 속성을 설정합니다
Singular.start()
.
전역 속성은 앱 실행 간에 지속되므로 속성이 이미 다른 값으로 존재할 수 있습니다.
overrideExisting
파라미터를 사용하여 새 값이 기존 값을 재정의해야 하는지 여부를 제어합니다.
func getConfig() -> SingularConfig? {
// Create config with API credentials
guard let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET") else {
return nil
}
// Set global properties during initialization
config.setGlobalProperty("MyProperty", withValue: "MyValue", overrideExisting: true)
config.setGlobalProperty("AnotherProperty", withValue: "AnotherValue", overrideExisting: true)
return config
}
// Initialize SDK with config
if let config = getConfig() {
Singular.start(config)
}
- (SingularConfig *)getConfig {
// Create config with API credentials
SingularConfig *config = [[SingularConfig alloc] initWithApiKey:@"SDK_KEY"
andSecret:@"SDK_SECRET"];
// Set global properties during initialization
[config setGlobalProperty:@"MyProperty" withValue:@"MyValue" overrideExisting:YES];
[config setGlobalProperty:@"AnotherProperty" withValue:@"AnotherValue" overrideExisting:YES];
return config;
}
// Initialize SDK with config
SingularConfig *config = [self getConfig];
[Singular start:config];
메서드 시그니처:
- (void)setGlobalProperty:(NSString *)key withValue:(NSString *)value overrideExisting:(BOOL)overrideExisting;
파라미터:
- key: 속성 이름 (최대 200자)
- value: 속성 값 (최대 200자)
- overrideExisting: 동일한 키를 가진 기존 속성을 재정의할지 여부
초기화 후 속성 관리
전역 속성 설정
앱 런타임 중 어느 시점에서든 전역 속성을 추가하거나 업데이트합니다.
// Set a global property after initialization
let result = Singular.setGlobalProperty("MyProperty",
andValue: "MyValue",
overrideExisting: true)
if result {
print("Property set successfully")
} else {
print("Failed to set property")
}
// Set a global property after initialization
BOOL result = [Singular setGlobalProperty:@"MyProperty"
andValue:@"MyValue"
overrideExisting:YES];
if (result) {
NSLog(@"Property set successfully");
} else {
NSLog(@"Failed to set property");
}
메서드 시그니처:
+ (BOOL)setGlobalProperty:(NSString *)key andValue:(NSString *)value overrideExisting:(BOOL)overrideExisting;
반환값:
true
속성이 성공적으로 설정되면,
false
그렇지 않으면
중요 — 런타임
+setGlobalProperty:andValue:overrideExisting:
반환값
NO
다음의 경우:
-
key가nil이거나 비어 있는 경우 -
SDK가 아직 시작되지 않은 경우 (
+start:가 실행되지 않음) - 이미 5개의 속성이 존재하는 상태에서 새 속성을 추가하려는 경우
-
동일한 키를 가진 속성이 이미 존재하고
overrideExisting가NO인 경우 — 값이 대체되지 않습니다
속성이 저장되었다고 가정하기 전에 항상 반환값을 확인하세요.
구성 시점 vs 런타임 동작:
구성 시점의 인스턴스 메서드
-setGlobalProperty:withValue:overrideExisting:
는
SingularConfig
에서
void
를 반환합니다 — 5개 속성 한도에 도달하거나 키가 비어 있으면 조용히 no-op됩니다. 런타임 클래스 메서드는
Singular
에서
BOOL
을 반환하고 실패를 노출합니다. 가능하다면 구성 시점에 속성을 설정하는 것을 선호하고,
실패 피드백이 필요한 경우 런타임 메서드를 사용하세요.
전역 속성 가져오기
현재 설정된 모든 전역 속성과 해당 값을 Dictionary로 검색합니다.
// Retrieve all global properties
let properties = Singular.getGlobalProperties()
// Iterate through properties
if let properties = properties as? [String: String] {
for (key, value) in properties {
print("Property: \(key) = \(value)")
}
}
// Retrieve all global properties
NSDictionary *properties = [Singular getGlobalProperties];
// Iterate through properties
for (NSString *key in properties) {
NSString *value = properties[key];
NSLog(@"Property: %@ = %@", key, value);
}
메서드 시그니처:
+ (NSDictionary *)getGlobalProperties;
반환값: 모든 전역 속성 키-값 쌍을 포함하는 Dictionary
전역 속성 해제
키로 특정 전역 속성을 제거합니다.
// Remove a specific global property
Singular.unsetGlobalProperty("MyProperty")
// Remove a specific global property
[Singular unsetGlobalProperty:@"MyProperty"];
메서드 시그니처:
+ (void)unsetGlobalProperty:(NSString *)key;
파라미터:
- key: 제거할 속성의 이름
모든 전역 속성 지우기
모든 전역 속성을 한 번에 제거합니다.
// Remove all global properties
Singular.clearGlobalProperties()
// Remove all global properties
[Singular clearGlobalProperties];
메서드 시그니처:
+ (void)clearGlobalProperties;
모범 사례:
사용자가 로그아웃하거나 모든 사용자 정의 트래킹 속성을 기본 상태로 재설정해야 할 때
clearGlobalProperties()
를 사용하세요.
구현 예제
완전한 사용 패턴
애플리케이션 라이프사이클 전반에 걸쳐 앱 수준 및 사용자별 속성을 트래킹합니다.
// Initialize SDK with app-level global properties
func getConfig() -> SingularConfig? {
guard let config = SingularConfig(apiKey: "SDK_KEY", andSecret: "SDK_SECRET") else {
return nil
}
// Set app version as a global property
if let appVersion = Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String {
config.setGlobalProperty("app_version", withValue: appVersion, overrideExisting: true)
}
return config
}
// Set third-party identifier on login
func onUserLogin(thirdPartyUserId: String) {
let success = Singular.setGlobalProperty("third_party_identifier",
andValue: thirdPartyUserId,
overrideExisting: true)
if success {
print("Third-party identifier set")
}
}
// Clear third-party identifier on logout
func onUserLogout() {
Singular.unsetGlobalProperty("third_party_identifier")
print("Third-party identifier cleared")
}
// Initialize SDK with app-level global properties
- (SingularConfig *)getConfig {
SingularConfig *config = [[SingularConfig alloc] initWithApiKey:@"SDK_KEY"
andSecret:@"SDK_SECRET"];
// Set app version as a global property
NSString *appVersion = [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"];
if (appVersion) {
[config setGlobalProperty:@"app_version" withValue:appVersion overrideExisting:YES];
}
return config;
}
// Set third-party identifier on login
- (void)onUserLogin:(NSString *)thirdPartyUserId {
BOOL success = [Singular setGlobalProperty:@"third_party_identifier"
andValue:thirdPartyUserId
overrideExisting:YES];
if (success) {
NSLog(@"Third-party identifier set");
}
}
// Clear third-party identifier on logout
- (void)onUserLogout {
[Singular unsetGlobalProperty:@"third_party_identifier"];
NSLog(@"Third-party identifier cleared");
}
모범 사례:
연동 크로스 플랫폼 트래킹을 위해 타사 분석 식별자(예: Mixpanel distinct_id, Amplitude user_id)를
Singular 전역 속성에 동기화하세요. 로그인 시 사용자별 식별자를 설정하고 로그아웃 시
unsetGlobalProperty()
로 지우세요. 다음과 같은 앱 수준 속성
app_version
은 세션 간에 지속됩니다.