Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Google Analytics cung cấp báo cáo sự kiện giúp bạn hiểu rõ cách người dùng tương tác với ứng dụng của bạn. Với Cloud Functions (thế hệ đầu tiên), bạn có thể truy cập vào các sự kiện chuyển đổi mà bạn đã ghi lại từ các thiết bị Apple và Android, đồng thời kích hoạt các chức năng dựa trên những sự kiện đó.
Kích hoạt hàm Google Analytics
Cloud Functions hỗ trợ Google AnalyticsAnalyticsEvent.
Sự kiện này được kích hoạt bất cứ khi nào hoạt động của người dùng tạo ra một sự kiện chuyển đổi.
Ví dụ: bạn có thể viết một hàm kích hoạt khi sự kiện in_app_purchase được tạo, cho biết rằng một giao dịch mua hàng trong ứng dụng đã xảy ra.
Bạn phải chỉ định sự kiện Analytics mà bạn muốn kích hoạt hàm bằng phương thức functions.analytics.event() và xử lý sự kiện trong trình xử lý sự kiện onLog():
Với mỗi sự kiện Analytics, bạn có quyền truy cập vào tất cả các thông số và thuộc tính người dùng có liên quan. Những thông tin này bao gồm thông tin về người dùng, thiết bị, ứng dụng và thông tin địa lý cho sự kiện.
Để xem danh sách đầy đủ các thông số và thuộc tính người dùng, hãy xem tài liệu tham khảo về functions.analytics.
Đối với một hàm được kích hoạt khi mua hàng như minh hoạ trong mẫu này, bạn có thể muốn truy cập vào các thuộc tính người dùng như ngôn ngữ của người dùng và giá trị của sự kiện (valueInUSD). Thuộc tính thứ hai này cho phép hàm mẫu kiểm tra xem đây có phải là một sự kiện chuyển đổi có giá trị cao hay không, để gửi phiếu giảm giá có giá trị cao hơn cho những khách hàng có giá trị.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[],[],null,["Google Analytics provides event reports that help you understand\nhow users interact with your app. With Cloud Functions (1st gen), you\ncan access conversion events you have logged from Apple and Android devices\nand trigger functions based on those events.\n| Only Apple platform and Android events marked as conversion events are currently supported by Cloud Functions; Web conversion events are not currently available. You can specify which events are conversion events in the [Events](//console.firebase.google.com/project/_/analytics/events) tab of the Firebase console **Analytics** pane.\n| **Note:** Cloud Functions for Firebase (2nd gen) does not provide support for the events and triggers described in this guide. Because 1st gen and 2nd gen functions can coexist side-by-side in the same source file, you can still develop and deploy this functionality together with 2nd gen functions.\n\nTrigger a Google Analytics function\n\nCloud Functions supports the Google Analytics\n[`AnalyticsEvent`](/docs/reference/functions/firebase-functions.analytics.analyticsevent).\nThis event is triggered whenever user activity generates a conversion event.\nFor example, you could write a function that\ntriggers when the `in_app_purchase` event is generated, indicating that an\nin-app purchase has occurred.\nYou must specify the Analytics event that\nyou want to trigger your function using the\n[`functions.analytics.event()`](/docs/reference/functions/firebase-functions.analytics.analyticsevent)\nmethod, and handle the event within the\n[`onLog()`](/docs/reference/functions/firebase-functions.analytics.analyticseventbuilder#analyticsanalyticseventbuilderonlog)\nevent handler:\n\n\u003cbr /\u003e\n\n```gdscript\nexports.sendCouponOnPurchase = functions.analytics.event('in_app_purchase').onLog((event) =\u003e {\n // ...\n});\n```\n\n\u003cbr /\u003e\n\nAccess event attributes\n\nWith each Analytics event, you have access to all relevant\nparameters and user properties. These include information about the user, the\ndevice, the app, and geographical information for the event.\nFor the complete list of parameters and user properties, see the\n[`functions.analytics`](/docs/reference/functions/firebase-functions.analytics) reference.\n\nFor a purchase-triggered function as illustrated in\n[this sample](https://github.com/firebase/functions-samples/tree/main/Node-1st-gen/coupon-on-purchase),\nyou might want to access user attributes such as the user's language and the\nevent's value ([`valueInUSD`](/docs/reference/functions/firebase-functions.analytics.analyticsevent#analyticsanalyticseventvalueinusd)).\nThis second attribute allows the sample function to test whether this is a\nhigh-value conversion event, in order to send a higher-value coupon to valuable customers.\n\n\u003cbr /\u003e\n\n```gdscript\n/**\n * After a user has completed a purchase, send them a coupon via FCM valid on their next purchase.\n */\nexports.sendCouponOnPurchase = functions.analytics.event('in_app_purchase').onLog((event) =\u003e {\n const user = event.user;\n const uid = user.userId; // The user ID set via the setUserId API.\n const purchaseValue = event.valueInUSD; // Amount of the purchase in USD.\n const userLanguage = user.deviceInfo.userDefaultLanguage; // The user language in language-country format.\n\n // For purchases above 500 USD, we send a coupon of higher value.\n if (purchaseValue \u003e 500) {\n return sendHighValueCouponViaFCM(uid, userLanguage);\n }\n return sendCouponViaFCM(uid, userLanguage);\n});https://github.com/firebase/functions-samples/blob/c4fde45b65fab584715e786ce3264a6932d996ec/Node-1st-gen/coupon-on-purchase/functions/index.js#L23-L41\n```\n\n\u003cbr /\u003e\n\nNext steps\n\nTo learn more about handling Analytics events in Cloud Functions,\nsee the [Google Analytics documentation](/docs/analytics) and the\n[`functions.analytics`](/docs/reference/functions/firebase-functions.analytics) reference,\nand try running the code sample\n[coupon-on-purchase](https://github.com/firebase/functions-samples/tree/main/Node-1st-gen/coupon-on-purchase)."]]