第 1 步:實現登入體驗
簡介:衡量 iOS 廣告轉換 |
第 1 步:實現登入體驗 |
第 2 步:整合 Google Analytics |
步驟 3:使用 Google Analytics 啟動裝置上轉換衡量 |
步驟 4:檢視並處理常見問題 |
第一步是實現登入體驗,以允許使用者提供他們的電子郵件地址或電話號碼。
您使用的身份驗證系統必須提供與使用者關聯的電子郵件地址或電話號碼。以下步驟概述了使用 Firebase 驗證安全收集登入資訊的流程,但如果您已有收集使用者電子郵件或電話號碼的驗證系統,則可以跳過此步驟,然後繼續執行步驟 2:整合 Google Analytics 。
您自己的應用程式可以在 iOS 11 或更高版本上運行
您的應用程式已註冊為與 Google Analytics 和廣告關聯的 Firebase 應用程式
您首選的 IDE
建立認證系統
使用 Firebase 驗證登入方法
您可以使用 Firebase 驗證,允許使用者使用一種或多種登入方法登入您的應用程式,包括電子郵件地址、電話號碼、密碼登入和聯合身分提供者(例如 Google、Facebook 或 Twitter)。請查看Firebase 身份驗證入門。
將 Firebase 身份驗證與自訂身份驗證系統集成
或者,您可以透過修改身份驗證伺服器將Firebase 驗證與自訂身份驗證系統集成,以在使用者成功登入時生成自訂簽名令牌。您的應用程式收到此令牌並使用它透過Firebase 進行身份驗證。請查看自訂身份驗證系統入門。
取得經過驗證的使用者的電子郵件地址或電話號碼
使用 Firebase 驗證設定驗證系統後,您可以獲得目前登入的使用者。
取得目前使用者的建議方法是在Auth
物件上設定偵聽器:
迅速
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; // ... }];
統一
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; }