Google Analytics는 사용자가 앱과 상호작용하는 방식을 파악할 수 있는 이벤트 보고서를 제공합니다. Cloud Functions(1세대)를 사용하면 Apple 및 Android 기기에서 로깅한 전환 이벤트에 액세스하고 이러한 이벤트를 기준으로 함수를 트리거할 수 있습니다.
Google Analytics 함수 트리거
Cloud Functions는 Google AnalyticsAnalyticsEvent를 지원합니다.
이 이벤트는 사용자 활동으로 전환 이벤트가 생성될 때마다 트리거됩니다.
예를 들어 인앱 구매가 발생했음을 나타내는 in_app_purchase 이벤트가 생성되면 트리거되는 함수를 작성할 수 있습니다.
functions.analytics.event() 메서드를 사용하여 함수를 트리거할 Analytics 이벤트를 지정하고 onLog() 이벤트 핸들러 내에서 이벤트를 처리해야 합니다.
각 Analytics 이벤트로 모든 관련 파라미터와 사용자 속성에 액세스할 수 있습니다. 여기에는 이벤트의 사용자, 기기, 앱, 지리적 정보가 포함됩니다.
파라미터와 사용자 속성의 전체 목록은 functions.analytics 참조를 확인하세요.
이 샘플에 나와 있는 것처럼 구매를 통해 트리거되는 함수의 경우 사용자 언어 및 이벤트 값(valueInUSD)과 같은 사용자 속성에 액세스할 수 있습니다. 샘플 함수는 이 두 번째 속성을 사용하여 구매력 높은 고객에게 고가의 쿠폰을 전송할 만한 가치가 있는 전환 이벤트인지를 테스트합니다.
[null,null,["최종 업데이트: 2025-08-13(UTC)"],[],[],null,["\u003cbr /\u003e\n\nGoogle 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)."]]