Skip to content

FCMOptions

chad63e edited this page Jan 29, 2024 · 1 revision

FCMOptions

Class Description

FCMOptions is an Anvil portable class specifically designed to manage options for Firebase Cloud Messaging (FCM). This class allows the specification of additional settings related to FCM, such as analytics labels.

Attributes

  • analytics_label (str, optional): A label associated with the message's analytics data. This label helps in categorizing and filtering messages in Firebase analytics.

Constructor

__init__(self, analytics_label=None)

Initializes a new instance of the FCMOptions class, setting the optional analytics label for FCM messages.

Parameters:

  • analytics_label (str, optional): The label for analytics. If provided, it helps in tracking the message in Firebase analytics.

Methods

to_dict()

Converts the FCMOptions object into a dictionary. This is particularly useful when passing the options to Firebase SDKs that require dictionary formats.

Usage Notes

  • The FCMOptions class is a convenient way to add extra configurations to your FCM messages, specifically in the context of analytics.
  • Being an Anvil portable class, it can be passed between client and server code within Anvil applications.
  • The use of analytics_label helps in gaining insights and tracking message effectiveness in Firebase analytics.

Example

from Firebase.messages import FCMOptions

# Creating FCMOptions with an analytics label
fcm_options = FCMOptions(analytics_label="campaign_123")

# Converting the FCMOptions to a dictionary
fcm_options_dict = fcm_options.to_dict()
print(fcm_options_dict)

In this example, FCMOptions is instantiated with an analytics label. The to_dict method converts it into a dictionary format, making it ready to be integrated with Firebase SDKs or other parts of a Firebase application where such options are required. This approach is particularly useful for tracking and analyzing the performance of FCM messages through Firebase analytics.