iOS SDK - 전역 속성 설정

문서

전역 속성 설정

앱에서 전송되는 모든 세션과 이벤트에 자동으로 첨부되는 사용자 지정 속성을 정의하여 보고서에서 세부적인 데이터 세분화를 가능하게 합니다.

전역 속성을 사용하면 필요한 모든 사용자, 앱 모드 또는 컨텍스트 정보를 추적할 수 있습니다. 예를 들어, 게임 앱에서 사용자가 게임을 진행함에 따라 업데이트되는 '0'으로 초기화된 '레벨' 속성을 만듭니다. 모든 세션과 이벤트에 이 속성이 포함되므로 사용자 수준별로 세션, 이벤트 수, 구매을 분석할 수 있습니다.

속성 사양

제한 및 지속성

글로벌 프로퍼티의 제약 조건과 지속성 동작을 이해합니다.

  • 최대 속성: 앱 설치당 최대 5개의 글로벌 속성을 정의할 수 있습니다.
  • 지속성: 명시적으로 설정이 해제되거나 앱이 제거될 때까지 앱 실행 간에 속성이 가장 최근 값으로 유지됩니다.
  • 글자 수 제한: 속성 이름과 값은 최대 200자까지 입력할 수 있습니다. 더 긴 값은 자동으로 200자로 잘립니다.
  • 데이터 가용성: 글로벌 속성은 사용자 수준 내보내기 및 포스트백에서 액세스할 수 있습니다. 집계 보고 지원에 대한 업데이트는 Singular 고객 성공 매니저에게 문의하세요.

초기화 시 글로벌 속성 설정

SingularConfig를 통해 구성

Singular.start() 을 호출하기 전에 setGlobalProperty 메서드를 사용하여 SDK 초기화 중에 글로벌 프로퍼티를 설정하세요.

글로벌 프로퍼티는 앱 실행 간에 유지되므로 이미 다른 값으로 프로퍼티가 존재할 수 있습니다. overrideExisting 파라미터를 사용하여 새 값이 기존 값을 재정의할지 여부를 제어하세요.

SwiftObjective-C
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)
}

메서드 서명:

- (void)setGlobalProperty:(NSString *)key withValue:(NSString *)value overrideExisting:(BOOL)overrideExisting;

매개변수:

  • key: 속성 이름(최대 200자)
  • 값: 속성 값(최대 200자)
  • overrideExisting: 동일한 키로 기존 프로퍼티를 재정의할지 여부입니다.

초기화 후 프로퍼티 관리

글로벌 프로퍼티 설정

앱 런타임 중 언제든지 글로벌 프로퍼티를 추가하거나 업데이트할 수 있습니다.

SwiftObjective-C
// 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")
}

메서드 서명:

+ (BOOL)setGlobalProperty:(NSString *)key andValue:(NSString *)value overrideExisting:(BOOL)overrideExisting;

반환: true 프로퍼티가 성공적으로 설정된 경우, 그렇지 않은 경우 false

중요:

  • 5개의 프로퍼티가 이미 존재하고 새 프로퍼티를 추가하려고 하면 메서드는 false을 반환합니다.
  • overrideExisting 매개 변수는 기존 속성 값을 대체할지 여부를 결정합니다.
  • 반환 값을 확인하여 프로퍼티가 성공적으로 설정되었는지 확인합니다.

전역 프로퍼티 가져오기

현재 설정된 모든 글로벌 프로퍼티와 해당 값을 딕셔너리로 가져옵니다.

SwiftObjective-C
// 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)")
    }
}

메서드 서명:

+ (NSDictionary *)getGlobalProperties;

반환합니다: 모든 글로벌 프로퍼티 키-값 쌍이 포함된 딕셔너리입니다.


글로벌 프로퍼티 설정 해제

특정 전역 속성을 해당 키로 제거합니다.

SwiftObjective-C
// Remove a specific global property
Singular.unsetGlobalProperty("MyProperty")

메서드 서명:

+ (void)unsetGlobalProperty:(NSString *)key;

파라미터:

  • key: 제거할 프로퍼티의 이름

모든 전역 속성 지우기

모든 전역 속성을 한 번에 제거합니다.

SwiftObjective-C
// Remove all global properties
Singular.clearGlobalProperties()

메서드 서명:

+ (void)clearGlobalProperties;

모범 사례: 사용자가 로그아웃하거나 모든 사용자 지정 추적 속성을 기본 상태로 재설정해야 할 때 clearGlobalProperties()을 사용하세요.


구현 예시

전체 사용 패턴

애플리케이션 라이프사이클 전반에 걸쳐 앱 수준 및 사용자별 속성을 추적합니다.

SwiftObjective-C
// 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")
}

모범 사례: 연동 크로스 플랫폼 추적을 위해 타사 애널리틱스 식별자(예: Mixpanel distinct_id, Amplitude user_id)를 Singular 글로벌 프로퍼티에 동기화합니다. 로그인 시에는 사용자별 식별자를 설정하고 로그아웃 시에는 unsetGlobalProperty() 으로 지웁니다. app_version 같은 앱 수준 속성은 여러 세션에 걸쳐 유지됩니다.