importFirebaseAnalytics// ...// If you're using an email address....Analytics.initiateOnDeviceConversionMeasurement(emailAddress:"example@gmail.com")// If you're using a phone number....Analytics.initiateOnDeviceConversionMeasurement(phoneNumber:"+15555555555")
@importFirebaseAnalytics;// ...// If you're using an email address....[FIRAnalyticsinitiateOnDeviceConversionMeasurementWithEmailAddress:@"example@gmail.com"];// If you're using a phone number....[FIRAnalyticsinitiateOnDeviceConversionMeasurementWithPhoneNumber:@"+15555555555"];
usingFirebase.Analytics;// ...// If you're using an email address....FirebaseAnalytics.InitiateOnDeviceConversionMeasurementWithEmailAddress("example@gmail.com");// If you're using a phone number....FirebaseAnalytics.InitiateOnDeviceConversionMeasurementWithPhoneNumber("+15555555555");
使用经过哈希处理的电子邮件地址或电话号码
该 API 接受使用 SHA256 算法对电子邮件地址和电话号码进行哈希处理。您可以在调用 SDK 之前在代码中执行哈希处理,以便保持对用户数据的控制。
importFirebaseAnalytics// ...// If you're using an email address....Analytics.initiateOnDeviceConversionMeasurement(hashedEmailAddress:hashedEmailAddress)// If you're using a phone number....Analytics.initiateOnDeviceConversionMeasurement(hashedPhoneNumber:hashedPhoneNumber)
@importFirebaseAnalytics;// ...// If you're using an email address....[FIRAnalyticsinitiateOnDeviceConversionMeasurementWithHashedEmailAddress:hashedEmailAddress];// If you're using a phone number....[FIRAnalyticsinitiateOnDeviceConversionMeasurementWithHashedPhoneNumber:hashedPhoneNumber];
usingFirebase.Analytics;// ...// If you're using an email address....FirebaseAnalytics.InitiateOnDeviceConversionMeasurementWithHashedEmailAddress(hashedEmailAddress);// If you're using a phone number....FirebaseAnalytics.InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber(hashedPhoneNumber);
使用 Xcode 调试日志进行验证(可选)
如果您启用了调试模式,请确保在调用 initiateMeasurement API 后,Xcode 调试控制台中显示如下日志消息:
[null,null,["最后更新时间 (UTC):2025-07-25。"],[],[],null,["Step 3: Initiate on-device conversion measurement using Google Analytics\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](/docs/tutorials/ads-ios-on-device-measurement/step-1) \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** \u003cbr /\u003e |\n| Step 4: [Troubleshoot and handle common issues](/docs/tutorials/ads-ios-on-device-measurement/step-4) |\n\n\u003cbr /\u003e\n\nNow that you can collect users' email addresses and phone numbers and your app has the\nGoogle Analytics for Firebase SDK, you can use the two to start\nmeasuring conversions.\n\nCall the API\n\nCall the conversion measurement API with the consented email address or phone\nnumber from Step 1, which is used for ads conversion measurement, without\nallowing any personally identifiable information to leave the user device.\n\nThere are two ways to initiate measurement:\n\n- [Using credentials](#use-plain-text-credentials)\n- [Using hashed credentials](#use-hashed-credentials)\n\nUse email address or phone number \n\nSwift\n\nImport the `FirebaseAnalytics` module and pass in the email address or phone\nnumber to the `initiateOnDeviceConversionMeasurement()` API.\n**Note:** The `initiateOnDeviceConversionMeasurement(emailAddress:)` and `initiateOnDeviceConversionMeasurement(phoneNumber:)` methods may be called sequentially, but only one match can be reported per user. If a match is found with either API, then subsequent API call are effectively ignored. \n\n```swift\nimport FirebaseAnalytics\n\n// ...\n// If you're using an email address....\nAnalytics.initiateOnDeviceConversionMeasurement(emailAddress: \"example@gmail.com\")\n// If you're using a phone number....\nAnalytics.initiateOnDeviceConversionMeasurement(phoneNumber: \"+15555555555\")\n```\n\nObjective-C\n\nImport the `FirebaseAnalytics` module and pass in the email address to the\n`initiateOnDeviceConversionMeasurementWithEmailAddress:` API or the phone\nnumber to the `initiateOnDeviceConversionMeasurementWithPhoneNumber:` API.\n**Note:** The `initiateOnDeviceConversionMeasurementWithEmailAddress:` and `initiateOnDeviceConversionMeasurementWithPhoneNumber:` methods may be called sequentially, but only one match can be reported per user. If a match is found with either API, then subsequent API call are effectively ignored. \n\n```objective-c\n@import FirebaseAnalytics;\n\n// ...\n// If you're using an email address....\n[FIRAnalytics initiateOnDeviceConversionMeasurementWithEmailAddress:@\"example@gmail.com\"];\n// If you're using a phone number....\n[FIRAnalytics initiateOnDeviceConversionMeasurementWithPhoneNumber:@\"+15555555555\"];\n```\n\nUnity\n\nImport the `Firebase.Analytics` namespace and pass in the email address to the\n`InitiateOnDeviceConversionMeasurementWithEmailAddress()` API or the phone\nnumber to the `InitiateOnDeviceConversionMeasurementWithPhoneNumber()` API:\n**Note:** The `InitiateOnDeviceConversionMeasurementWithEmailAddress()` and `InitiateOnDeviceConversionMeasurementWithPhoneNumber()` methods may be called sequentially, but only one match can be reported per user. If a match is found with either API, then subsequent API call are effectively ignored. \n\n```c#\nusing Firebase.Analytics;\n\n// ...\n// If you're using an email address....\nFirebaseAnalytics.InitiateOnDeviceConversionMeasurementWithEmailAddress(\"example@gmail.com\");\n// If you're using a phone number....\nFirebaseAnalytics.InitiateOnDeviceConversionMeasurementWithPhoneNumber(\"+15555555555\");\n```\n| **Note:** The best practice is to call the API once per install and as close as possible to the login.\n| **Important:** Be aware that if an intended in-app action or event happens *immediately* after a user email or phone registration, consider implementing a small time delay between initiating on-device conversion measurement and logging the event.\n\nUse a hashed email address or phone number\n\nThe API will accept email addresses and phone numbers hashed with SHA256. You\ncan maintain control of your user's data by performing the hashing in your code\nbefore making calls to the SDK.\n\nTo use hashed credentials, normalize addresses and numbers, hash them with\nSHA256, then call the API.\n\nNormalize email addresses and phone numbers\n\nFor **email addresses** , the Google Analytics API assumes that a\nparticular normalization is performed before SHA256 is applied, so follow these\nsteps to normalize your data:\n\n1. Convert the entire email address to lowercase.\n\n2. If the email address ends in domain *@googlemail.com* , replace the\n *@googlemail.com* domain with *@gmail.com*.\n\n3. For addresses ending in domain *@gmail.com* (including those modified in\n the previous step):\n\n 1. Remove all periods from the username portion.\n\n 2. Make the following substitutions in the username portion:\n\n - For letters I or i, or digit 1, substitute letter l\n - For digit 0, substitute letter o\n - For digit 2, substitute letter z\n - For digit 5, substitute letter s\n\nFor example, after normalization:\n\n- `an.email.user0125@googlemail.com` becomes `anemalluserolzs@gmail.com`\n- `CAPSUSER0125@provider.net` becomes `capsuser0125@provider.net`\n\nFor **phone numbers**, numbers must already be in E.164 format (that is,\nprefix with +, 1-3 digits for country code, max 12 digits for subscriber number)\nprior to hashing with SHA256.\n\nNote that the hashed SHA256 email or phone numbers must be 32 bytes long\nand not a hexadecimal string.\n\nCall the API with hashed credentials \n\nSwift\n\nImport the `FirebaseAnalytics` module and pass in the email address or phone\nnumber to the `initiateOnDeviceConversionMeasurement()` API.\n**Note:** The `initiateOnDeviceConversionMeasurement(hashedEmailAddress:)` and `initiateOnDeviceConversionMeasurement(hashedPhoneNumber:)` methods may be called sequentially, but only one match can be reported per user. If a match is found with either API, then subsequent API call are effectively ignored. \n\n```swift\nimport FirebaseAnalytics\n\n// ...\n// If you're using an email address....\nAnalytics.initiateOnDeviceConversionMeasurement(hashedEmailAddress: hashedEmailAddress)\n// If you're using a phone number....\nAnalytics.initiateOnDeviceConversionMeasurement(hashedPhoneNumber: hashedPhoneNumber)\n```\n\nObjective-C\n\nImport the `FirebaseAnalytics` module and pass in the email address to the\n`initiateOnDeviceConversionMeasurementWithHashedEmailAddress:` API or the phone\nnumber to the `initiateOnDeviceConversionMeasurementWithHashedPhoneNumber:`\nAPI.\n**Note:** The `initiateOnDeviceConversionMeasurementWithHashedEmailAddress:` and `initiateOnDeviceConversionMeasurementWithHashedPhoneNumber:` methods may be called sequentially, but only one match can be reported per user. If a match is found with either API, then subsequent API call are effectively ignored. \n\n```objective-c\n@import FirebaseAnalytics;\n\n// ...\n// If you're using an email address....\n[FIRAnalytics initiateOnDeviceConversionMeasurementWithHashedEmailAddress:hashedEmailAddress];\n// If you're using a phone number....\n[FIRAnalytics initiateOnDeviceConversionMeasurementWithHashedPhoneNumber:hashedPhoneNumber];\n```\n\nUnity\n\nImport the `Firebase.Analytics` namespace and pass in the email address to the\n`InitiateOnDeviceConversionMeasurementWithHashedEmailAddress()` API or the\nphone number to the `InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber()` API:\n**Note:** The `InitiateOnDeviceConversionMeasurementWithHashedEmailAddress()` and `InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber()` methods may be called sequentially, but only one match can be reported per user. If a match is found with either API, then subsequent API call are effectively ignored. \n\n```c#\nusing Firebase.Analytics;\n\n// ...\n// If you're using an email address....\nFirebaseAnalytics.InitiateOnDeviceConversionMeasurementWithHashedEmailAddress(hashedEmailAddress);\n// If you're using a phone number....\nFirebaseAnalytics.InitiateOnDeviceConversionMeasurementWithHashedPhoneNumber(hashedPhoneNumber);\n```\n| **Note:** The best practice is to call the API once per install and as close as possible to the login.\n| **Important:** Be aware that if an intended in-app action or event happens *immediately* after a user email or phone registration, consider implementing a small time delay between initiating on-device conversion measurement and logging the event.\n\nVerify with Xcode debug logs (optional)\n\nIf you enabled debug mode, after calling the initiate measurement API, ensure\nthat a message like the following log message appears in the Xcode debug\nconsole: \n\n [FirebaseAnalytics][I-ACS023225] Initiated on-device conversion measurement\n\nIf you enabled debug mode and included the `-DebugOnDeviceConversionMeasurement`\nlaunch argument, then calling the `initiateOnDeviceConversionMeasurement()` API\nwill simulate a match. \n\n [FirebaseAnalytics][I-ACS023229] On-device conversion measurement found a match\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\n\u003cbr /\u003e\n\n[arrow_back_ios**Step 2** : Integrate Google Analytics](/docs/tutorials/ads-ios-on-device-measurement/step-2)\n[**Step 4** : Troubleshoot and handle common issuesarrow_forward_ios](/docs/tutorials/ads-ios-on-device-measurement/step-4)\n\n\u003cbr /\u003e\n\n*** ** * ** ***"]]