首页 > 解决方案 > 如何使用 PyFCM 在 Django Python 中启用 Google Firebase 通知分析?

问题描述

我们正在使用 PyFCM 模块通过 google firebase 发送通知,并且不知何故 GCP firebase 控制台的报告部分中缺少通知分析报告的数据。

有人可以知道如何在 Firebase 上启用通知分析吗?因为我们想知道正在发送、接收和打开的通知的详细信息。

标签: pythonfirebasepush-notificationfirebase-cloud-messaginggoogle-cloud-messaging

解决方案


我们需要在发送到 firebase 的每个通知中添加 analytics_label,对于使用 Django 的 PyFcm,您可以在下面给出的 fcm_options 中传递 analytics_label:-

from pyfcm import FCMNotification

push_service = FCMNotification(api_key=FCM_SERVER_KEY)
registration_ids = ['user_mobile_token_key']
data = {
    "body": "test body,
    "title": "title,
    "priority": "high"
}

extra_kwargs = {'**fcm_options**': {
    'analytics_label': 'notification-label'}}
result = push_service.multiple_devices_data_message(registration_ids=registration_ids,
                                                                                 data_message=data, extra_kwargs=extra_kwargs)
print(result)


推荐阅读