教學課程:評估 iOS 廣告轉換

步驟 1:實作登入體驗


簡介: 評估 iOS 廣告轉換

步驟 1: 導入登入體驗

步驟 2: 整合 Google Analytics
步驟 3: 使用 Google Analytics 啟動裝置端轉換評估
步驟 4: 排解及處理常見問題


首先,請實作登入服務,讓使用者提供電子郵件地址或電話號碼。

您使用的驗證系統必須提供與使用者相關聯的電子郵件地址或電話號碼。下列步驟說明如何使用 Firebase Authentication 安全地收集登入資訊,但如果您已有可收集使用者電子郵件地址或電話號碼的驗證系統,可以略過這個步驟,直接前往步驟 2:整合 Google Analytics

設定驗證系統

使用 Firebase Authentication 登入方式

您可以使用 Firebase Authentication 讓使用者透過一或多種登入方式登入應用程式,包括電子郵件地址、電話號碼、密碼登入,以及聯合身分識別供應商 (例如 Google、Facebook 或 Twitter)。請參閱「開始使用 Firebase Authentication」。

Firebase Authentication 與自訂驗證系統整合

或者,您也可以修改驗證伺服器,在使用者成功登入時產生自訂簽署權杖,將 Firebase Authentication 與自訂驗證系統整合。應用程式會收到這個權杖,並用來向 Firebase 進行驗證。請參閱「開始使用自訂驗證系統」。

取得已驗證使用者的電子郵件地址或電話號碼

使用 Firebase Authentication 設定驗證系統後,即可取得目前登入的使用者。

建議您在 Auth 物件上設定監聽器,藉此取得目前使用者:

Swift

handle = Auth.auth().addStateDidChangeListener { auth, user in
  // Get the user's email address
  let email = user.email
  // or get their phone number
  let phoneNumber = user.phoneNumber
  // ...
}

Objective-C

self.handle = [[FIRAuth auth]
  addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) {
    // Get the user's email address
    NSString *email = user.email;
    // or get their phone number
    NSString *phoneNumber = user.phoneNumber;
    // ...
  }];

Unity

Firebase.Auth.FirebaseAuth auth;
Firebase.Auth.FirebaseUser user;

// Handle initialization of the necessary firebase modules:
void InitializeFirebase() {
  auth = Firebase.Auth.FirebaseAuth.DefaultInstance;
  auth.StateChanged += AuthStateChanged;
  AuthStateChanged(this, null);
}

// Track state changes of the auth object.
void AuthStateChanged(object sender, System.EventArgs eventArgs) {
  if (auth.CurrentUser != user) {
    bool signedIn = user != auth.CurrentUser && auth.CurrentUser != null;
    user = auth.CurrentUser;
    if (signedIn) {
      // Get the user's email address
      string email = user.Email;
      // or get their phone number
      string phoneNumber = user.PhoneNumber;
      // ...
    }
  }
}

// Handle removing subscription and reference to the Auth instance.
// Automatically called by a Monobehaviour after Destroy is called on it.
void OnDestroy() {
  auth.StateChanged -= AuthStateChanged;
  auth = null;
}




簡介 步驟 2:整合 Google Analytics