教學課程:評估 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