iOS용 Google 애널리틱스 SDK - v3로 이전

이 가이드에서는 iOS용 Google 애널리틱스 SDK의 V3로 업그레이드하는 방법을 설명합니다.

한눈에 보기: V3의 새로운 기능

V3의 API는 네이티브 플랫폼과 웹 플랫폼 전반에서 더 일관되도록 리팩터링되었습니다. 모든 V2 사용자는 다음 변경사항을 참고해야 합니다.

  • 이제 조회가 단일 send:(NSDictionary *)params 메서드를 사용하여 전송됩니다.
  • 자동 클라이언트 측 세션 관리가 삭제되었습니다. 대신 관리 인터페이스에서 세션 제한 시간을 구성할 수 있습니다. 자세히 알아보세요.
  • 디버그 모드가 Logger로 대체되었습니다.
  • 신규: 전달된 데이터가 보고서에 표시되지 않도록 dryRun 플래그가 추가되었습니다.
  • 신규: iOS용 현지 통화 지원이 추가되었습니다.

전체 변경사항 목록은 변경 로그를 참고하세요.

시작하기 전에

v3로 업그레이드를 시작하기 전에 다음이 필요합니다.

업그레이드 경로

시작하려면 현재 구현에서 v3으로의 업그레이드 경로를 선택하세요.

v1.x에서 v3으로

Google 애널리틱스 iOS SDK v1.x 사용자는 v3 시작 가이드에 따라 v3를 사용하는 것이 좋습니다.

v2.x에서 v3으로

v2.x 사용자가 v3로 업그레이드하려면 다음 단계를 따라야 합니다.

  1. 모든 send<hit-type> 편의 메서드를 새 send: 메서드로 바꿉니다.
    // v2 (Old)
    id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
    [tracker sendView:@"HomeScreen"];
    
    // v3
    id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
    // Set the screen name on the tracker so that it is used in all hits sent from this screen.
    [tracker set:kGAIScreenName value:@"Home Screen"];
    
    // Send a screenview.
    // [tracker send:[[GAIDictionaryBuilder createAppView]  build]];   // Previous V3 SDK versions.
    [tracker send:[[GAIDictionaryBuilder createScreenView]  build]];   // SDK Version 3.08 and up.
    
  2. 자동 클라이언트 측 세션 관리가 v3에서 삭제되었습니다. 세션 제한 시간은 관리 인터페이스에서 설정할 수 있으며 기본값은 30분입니다. sessionControl 매개변수를 사용하여 수동으로 세션을 시작하고 중지할 수도 있습니다. v3의 세션 관리 자세히 알아보기

  3. 자동 화면 추적 사용자는 GAITrackedViewController.trackedViewName에 대한 참조를 GAITrackedViewController.screenName로 바꿔야 합니다.
    // v2 (Old)
    #import "GAITrackedViewController.h"
    
    @implementation AboutViewController
    
    - (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      self.trackedViewName = @"About Screen";
    }
    
    // ... Rest of ViewController implementation.
    
    // v3
    #import "GAITrackedViewController.h"
    
    @implementation AboutViewController
    
    - (void)viewDidAppear:(BOOL)animated {
      [super viewDidAppear:animated];
      self.screenName = @"About Screen";
    }
    
    // ... Rest of ViewController implementation.
    
  4. 디버그 모드가 지원 중단되었습니다. 대신 Logger를 사용하세요.
    // v2 (Old)
    [GAI sharedInstance].debug = YES;
    
    // v3
    [[GAI sharedInstance].logger setLogLevel:kGAILogLevelVerbose];
    
  5. GAI.useHttp 속성이 삭제되었습니다. 기본 HTTPS 대신 HTTP를 사용하여 조회를 전송하려면 대신 각 GAITrackerkGAIUseSecure 매개변수를 설정하세요.
    // v2 (Old)
    // AppDelegate.m
    
    #import AppDelegate.h
    #import GAI.h
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        static NSString const *kGaPropertyId = @"UA-XXXX-Y";
        id tracker = [[GAI sharedInstance] trackerWithTrackingId:kGaPropertyId];
    
        // Send hits using HTTP (default=HTTPS).
        tracker.useHttps = NO;
    
    }
    
    // v3
    // AppDelegate.m
    
    #import AppDelegate.h
    #import GAI.h
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        static NSString const *kGaPropertyId = @"UA-XXXX-Y";
        id tracker = [[GAI sharedInstance] trackerWithTrackingId:kGaPropertyId];
    
        // Send hits using HTTP (default=HTTPS).
        [tracker set:kGAIUseSecure value:[@NO stringValue]];
    
    }
    
  6. v3 SDK는 앱이 열릴 때 더 이상 자동으로 새 세션을 시작하지 않습니다. v2부터 이 동작을 유지하려면 사용자가 앱을 시작할 때 자체 세션 제어 로직을 구현해야 합니다.
  7. // AppDelegate.m
    
    #import AppDelegate.h
    #import GAI.h
    
    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    
        static NSString const *kGaPropertyId = @"UA-XXXX-Y";
        id tracker = [[GAI sharedInstance] trackerWithTrackingId:kGaPropertyId];
    
        // CAUTION: Setting session control directly on the tracker persists the
        // value across all subsequent hits, until it is manually set to null.
        // This should never be done in normal operation.
        //
        // [tracker set:kGAISessionControl value:@"start"];
    
        // Instead, send a single hit with session control to start the new session.
        [tracker send:[[[GAIDictionaryBuilder createEventWithCategory:@"UX"
                                                               action:@"appstart"
                                                                label:nil
                                                                value:nil] set:@"start" forKey:kGAISessionControl] build]];
    
    
  8. 앱 수준 선택 해제 설정은 더 이상 SDK에서 유지하지 않으며 앱이 실행될 때마다 설정해야 합니다 (기본값은 NO). 애플리케이션 수준 선택 해제 설정에 대해 자세히 알아보기

참조

다음 섹션에서는 V3 SDK를 사용하여 데이터를 설정하고 전송하는 방법의 참조 예를 제공합니다.

v3에서 사전을 사용하여 데이터 전송

V3에서는 Google 애널리틱스 필드 및 값의 NSDictionary를 인수로 사용하는 단일 send: 메서드를 통해 데이터가 전송됩니다. 조회 빌드 프로세스를 단순화하기 위해 GAIDictionaryBuilder 유틸리티 클래스가 제공됩니다.

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];
[tracker set:kGAIScreenName value:@"Home Screen"];

// Previous V3 SDK versions.
// [tracker send:[[GAIDictionaryBuilder createAppView] setValue:@"Premium"  // Creates a Map of hit type 'AppView' (screenview) and set any additional fields.
//                                                     forKey:[customDimensionForIndex:1] build]; // Build and return the dictionary to the send method.

// SDK Version 3.08 and up.
[tracker send:[[GAIDictionaryBuilder createScreenView] setValue:@"Premium"  // Creates a Map of hit type 'ScreenView' and set any additional fields.
                                                       forKey:[customDimensionForIndex:1] build]; // Build and return the dictionary to the send method.

GAIDictionaryBuilder 클래스는 이벤트와 같은 지원되는 조회 유형을 빌드하는 데 사용할 수 있습니다.

id<GAITracker> tracker = [[GAI sharedInstance] defaultTracker];

[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"     // Event category (required)
                                                      action:@"button_press"  // Event action (required)
                                                       label:@"play"          // Event label
                                                       value:nil] build]];    // Event value

v3에서 데이터 전송에 관해 자세히 알아보기

v3에서 추적기의 데이터 설정

set:value:forKey 메서드를 사용하여 GAITracker에 직접 값을 설정할 수도 있습니다. 직접 설정된 값은 해당 GAITracker에서 발생하는 모든 후속 조회에 적용됩니다.

// Values set directly on a tracker apply to all subsequent hits.
[tracker set:kGAIScreenName value:@"Home Screen"];

// This screenview hit will include the screen name "Home Screen".
// [tracker send:[[GAIDictionaryBuilder createAppView] build]];   // Previous V3 SDK versions.
[tracker send:[[GAIDictionaryBuilder createScreenView] build]];   // SDK Version 3.08 and up.

// And so will this event hit.
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"
                                                      action:@"button_press"
                                                       label:@"play"
                                                       value:nil] build]];

GAITracker에 설정된 값을 지우려면 속성을 nil로 설정하세요.

// Clear the previously-set screen name value.
[tracker set:kGAIScreenName
       value:nil];

// Now this event hit will not include a screen name value.
[tracker send:[[GAIDictionaryBuilder createEventWithCategory:@"ui_action"
                                                      action:@"button_press"
                                                       label:@"play"
                                                       value:nil] build]];

v3의 데이터 설정 자세히 알아보기