บทแนะนํา: วัด Conversion ของโฆษณา iOS
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
ขั้นตอนที่ 1: ใช้ประสบการณ์การลงชื่อเข้าใช้
ขั้นตอนแรกคือการใช้ประสบการณ์การลงชื่อเข้าใช้เพื่อให้ผู้ใช้ระบุอีเมลหรือหมายเลขโทรศัพท์
ระบบการตรวจสอบสิทธิ์ที่คุณใช้ต้องระบุอีเมลหรือหมายเลขโทรศัพท์ที่เชื่อมโยงกับผู้ใช้ ขั้นตอนต่อไปนี้จะอธิบายกระบวนการรวบรวมข้อมูลการลงชื่อเข้าใช้อย่างปลอดภัยโดยใช้ Firebase Authentication แต่คุณสามารถข้ามขั้นตอนนี้ไปได้หากมีระบบการตรวจสอบสิทธิ์ที่รวบรวมอีเมลหรือหมายเลขโทรศัพท์ของผู้ใช้อยู่แล้ว แล้วไปยังขั้นตอนที่ 2: ผสานรวม Google Analytics
ตรวจสอบว่าคุณมีคุณสมบัติตรงตามข้อกําหนดเบื้องต้นสําหรับบทแนะนํานี้
ตั้งค่าระบบการตรวจสอบสิทธิ์
ใช้วิธีการลงชื่อเข้าใช้ Firebase Authentication
คุณสามารถใช้ Firebase Authentication เพื่ออนุญาตให้ผู้ใช้ลงชื่อเข้าใช้แอปโดยใช้วิธีการลงชื่อเข้าใช้อย่างน้อย 1 วิธี ซึ่งรวมถึงอีเมล หมายเลขโทรศัพท์ การลงชื่อเข้าใช้ด้วยรหัสผ่าน และผู้ให้บริการข้อมูลประจำตัวแบบรวมศูนย์ (เช่น Google, Facebook หรือ Twitter)
โปรดอ่านเริ่มต้นใช้งาน Firebase Authentication
ผสานรวม Firebase Authentication กับระบบการตรวจสอบสิทธิ์ที่กำหนดเอง
หรือจะผสานรวม Firebase Authentication กับระบบการตรวจสอบสิทธิ์ที่กำหนดเองก็ได้โดยแก้ไขเซิร์ฟเวอร์การตรวจสอบสิทธิ์ให้สร้างโทเค็นที่ลงชื่อที่กำหนดเองเมื่อผู้ใช้ลงชื่อเข้าใช้สำเร็จ แอปของคุณจะได้รับโทเค็นนี้และใช้เพื่อตรวจสอบสิทธิ์กับ Firebase โปรดดูเริ่มต้นใช้งานระบบการตรวจสอบสิทธิ์ที่กำหนดเอง
รับอีเมลหรือหมายเลขโทรศัพท์ของผู้ใช้ที่ตรวจสอบสิทธิ์แล้ว
หลังจากตั้งค่าระบบการตรวจสอบสิทธิ์ด้วย Firebase Authentication แล้ว คุณจะรับผู้ใช้ที่ลงชื่อเข้าใช้อยู่ในปัจจุบันได้
วิธีที่เราแนะนำในการรับผู้ใช้ปัจจุบันคือการตั้งค่า Listener บนออบเจ็กต์ 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;
}
arrow_back_iosข้อมูลเบื้องต้น
ขั้นตอนที่ 2: ผสานรวม Google Analyticsarrow_forward_ios
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-07-25 UTC
[null,null,["อัปเดตล่าสุด 2025-07-25 UTC"],[],[],null,["Step 1: Implement a sign-in experience\n\n\u003cbr /\u003e\n\n|----------------------------------------------------------------------------------------------------------------------------------|\n| Introduction: [Measure iOS Ads conversions](/docs/tutorials/ads-ios-on-device-measurement/index-first-party) |\n| **Step 1: Implement a sign-in experience** \u003cbr /\u003e |\n| Step 2: [Integrate Google Analytics](/docs/tutorials/ads-ios-on-device-measurement/step-2) |\n| Step 3: [Initiate on-device conversion measurement using Google Analytics](/docs/tutorials/ads-ios-on-device-measurement/step-3) |\n| Step 4: [Troubleshoot and handle common issues](/docs/tutorials/ads-ios-on-device-measurement/step-4) |\n\n\u003cbr /\u003e\n\nThe first step is to implement a sign-in experience to allow users to provide\ntheir email addresses or phone number.\n\n**The authentication system that you use must provide an email address or\nphone number associated with the user.** The following steps outline the process\nfor securely collecting sign-in information using Firebase Authentication, but you\ncan skip this step if you already have an authentication system that collects\nuser emails or phone numbers and continue to [Step 2: Integrate Google Analytics](/docs/tutorials/ads-ios-on-device-measurement/step-2).\n\n\u003cbr /\u003e\n\n**Make sure you have the prerequisites for this tutorial**\n\n\u003cbr /\u003e\n\n- Your own app that can run on iOS 12 or higher\n\n- Your app registered as a Firebase App that's linked to Google Analytics\n and Ads\n\n- Your preferred IDE\n\n \u003cbr /\u003e\n\n\u003cbr /\u003e\n\nSet up an authentication system\n\nUse a Firebase Authentication sign-in method\n\nYou can use Firebase Authentication to allow users to sign in to your app using one or\nmore sign-in methods, including email address, phone number, password sign-in,\nand federated identity providers (like Google, Facebook or Twitter).\nPlease review [Get started with Firebase Authentication](/docs/auth/ios/start).\n\nIntegrate Firebase Authentication with a custom authentication system\n\nAlternatively, you can integrate Firebase Authentication with a custom\nauthentication system by modifying your authentication server to produce custom\nsigned tokens when a user successfully signs in. Your app receives this token\nand uses it to authenticate with Firebase. Please review [Get started with a custom\nauthentication system](/docs/auth/ios/custom-auth).\n\nGet the authenticated user's email address or phone number\n\nAfter you've set up an authentication system with Firebase Authentication, you can\nget the currently signed-in user.\n\nThe recommended way to get the current user is by setting a listener on the\n`Auth` object: \n\nSwift \n\n```swift\nhandle = Auth.auth().addStateDidChangeListener { auth, user in\n // Get the user's email address\n let email = user.email\n // or get their phone number\n let phoneNumber = user.phoneNumber\n // ...\n}\n```\n\nObjective-C \n\n```objective-c\nself.handle = [[FIRAuth auth]\n addAuthStateDidChangeListener:^(FIRAuth *_Nonnull auth, FIRUser *_Nullable user) {\n // Get the user's email address\n NSString *email = user.email;\n // or get their phone number\n NSString *phoneNumber = user.phoneNumber;\n // ...\n }];\n```\n\nUnity \n\n```c#\nFirebase.Auth.FirebaseAuth auth;\nFirebase.Auth.FirebaseUser user;\n\n// Handle initialization of the necessary firebase modules:\nvoid InitializeFirebase() {\n auth = Firebase.Auth.FirebaseAuth.DefaultInstance;\n auth.StateChanged += AuthStateChanged;\n AuthStateChanged(this, null);\n}\n\n// Track state changes of the auth object.\nvoid AuthStateChanged(object sender, System.EventArgs eventArgs) {\n if (auth.CurrentUser != user) {\n bool signedIn = user != auth.CurrentUser && auth.CurrentUser != null;\n user = auth.CurrentUser;\n if (signedIn) {\n // Get the user's email address\n string email = user.Email;\n // or get their phone number\n string phoneNumber = user.PhoneNumber;\n // ...\n }\n }\n}\n\n// Handle removing subscription and reference to the Auth instance.\n// Automatically called by a Monobehaviour after Destroy is called on it.\nvoid OnDestroy() {\n auth.StateChanged -= AuthStateChanged;\n auth = null;\n}\n```\n| **Note:** Find more code examples demonstrating Firebase Authentication in the [Firebase quickstarts](https://github.com/firebase/quickstart-ios).\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\n\u003cbr /\u003e\n\n[arrow_back_ios**Introduction**](/docs/tutorials/ads-ios-on-device-measurement/index-first-party)\n[**Step 2** : Integrate Google Analyticsarrow_forward_ios](/docs/tutorials/ads-ios-on-device-measurement/step-2)\n\n\u003cbr /\u003e\n\n*** ** * ** ***"]]